Line data Source code
1 : /*
2 : * This file is part of the LibreOffice project.
3 : *
4 : * This Source Code Form is subject to the terms of the Mozilla Public
5 : * License, v. 2.0. If a copy of the MPL was not distributed with this
6 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 : */
8 :
9 : #include <sal/config.h>
10 :
11 : #include <set>
12 :
13 : #include <swmodeltestbase.hxx>
14 :
15 : #if !defined(WNT)
16 :
17 : #include <com/sun/star/awt/FontWeight.hpp>
18 : #include <com/sun/star/style/PageStyleLayout.hpp>
19 : #include <com/sun/star/table/XCell.hpp>
20 : #include <com/sun/star/table/BorderLine.hpp>
21 : #include <com/sun/star/text/XTextTable.hpp>
22 : #include <com/sun/star/text/MailMergeType.hpp>
23 : #include <com/sun/star/sdb/XDocumentDataSource.hpp>
24 : #include <com/sun/star/text/TextContentAnchorType.hpp>
25 :
26 : #include <wrtsh.hxx>
27 : #include <ndtxt.hxx>
28 : #include <swdtflvr.hxx>
29 : #include <view.hxx>
30 : #include <edtwin.hxx>
31 : #include <olmenu.hxx>
32 : #include <cmdid.h>
33 :
34 4 : class MMTest : public SwModelTestBase
35 : {
36 : public:
37 4 : MMTest() : SwModelTestBase("/sw/qa/extras/mailmerge/data/", "writer8") {}
38 : };
39 :
40 : #define DECLARE_DFLT_MAILMERGE_TEST(TestName, filename, datasource, tablename) \
41 : DECLARE_MAILMERGE_TEST(TestName, filename, datasource, tablename, MMTest)
42 :
43 18 : DECLARE_DFLT_MAILMERGE_TEST(testMultiPageAnchoredDraws, "multiple-page-anchored-draws.odt", "4_v01.ods", "Tabelle1")
44 : {
45 2 : executeMailMerge();
46 :
47 2 : SwXTextDocument* pTxtDoc = dynamic_cast<SwXTextDocument *>(mxMMComponent.get());
48 2 : CPPUNIT_ASSERT(pTxtDoc);
49 2 : sal_uInt16 nPhysPages = pTxtDoc->GetDocShell()->GetWrtShell()->GetPhyPageNum();
50 2 : CPPUNIT_ASSERT_EQUAL(sal_uInt16(8), nPhysPages);
51 :
52 2 : uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxMMComponent, uno::UNO_QUERY);
53 4 : uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
54 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(8), xDraws->getCount());
55 :
56 4 : std::set<sal_uInt16> pages;
57 4 : uno::Reference<beans::XPropertySet> xPropertySet;
58 :
59 18 : for (sal_Int32 i = 0; i < xDraws->getCount(); i++)
60 : {
61 : text::TextContentAnchorType nAnchorType;
62 : sal_uInt16 nAnchorPageNo;
63 16 : xPropertySet.set(xDraws->getByIndex(i), uno::UNO_QUERY);
64 :
65 16 : xPropertySet->getPropertyValue( UNO_NAME_ANCHOR_TYPE ) >>= nAnchorType;
66 16 : CPPUNIT_ASSERT_EQUAL( text::TextContentAnchorType_AT_PAGE, nAnchorType );
67 :
68 16 : xPropertySet->getPropertyValue( UNO_NAME_ANCHOR_PAGE_NO ) >>= nAnchorPageNo;
69 : // are all shapes are on different page numbers?
70 16 : CPPUNIT_ASSERT(pages.insert(nAnchorPageNo).second);
71 2 : }
72 2 : }
73 :
74 18 : DECLARE_DFLT_MAILMERGE_TEST(testMissingDefaultLineColor, "missing-default-line-color.ott", "one-empty-address.ods", "one-empty-address")
75 : {
76 2 : executeMailMerge();
77 : // The document was created by LO version which didn't write out the default value for line color
78 : // (see XMLGraphicsDefaultStyle::SetDefaults()).
79 2 : uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxMMComponent, uno::UNO_QUERY);
80 4 : uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
81 4 : uno::Reference<beans::XPropertySet> xPropertySet(xDraws->getByIndex(0), uno::UNO_QUERY);
82 : // Lines do not have a line color.
83 2 : CPPUNIT_ASSERT( !xPropertySet->getPropertySetInfo()->hasPropertyByName( "LineColor" ));
84 2 : SwXTextDocument* pTxtDoc = dynamic_cast<SwXTextDocument *>(mxMMComponent.get());
85 2 : CPPUNIT_ASSERT(pTxtDoc);
86 4 : uno::Reference< lang::XMultiServiceFactory > xFact( mxMMComponent, uno::UNO_QUERY );
87 4 : uno::Reference< beans::XPropertySet > xDefaults( xFact->createInstance( "com.sun.star.drawing.Defaults" ), uno::UNO_QUERY );
88 2 : CPPUNIT_ASSERT( xDefaults.is());
89 4 : uno::Reference< beans::XPropertySetInfo > xInfo( xDefaults->getPropertySetInfo());
90 2 : CPPUNIT_ASSERT( xInfo->hasPropertyByName( "LineColor" ));
91 : sal_uInt32 lineColor;
92 2 : xDefaults->getPropertyValue( "LineColor" ) >>= lineColor;
93 : // And the default value is black (wasn't copied properly by mailmerge).
94 4 : CPPUNIT_ASSERT_EQUAL( COL_BLACK, lineColor );
95 2 : }
96 :
97 : #endif
98 :
99 8 : CPPUNIT_PLUGIN_IMPLEMENT();
100 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|