2 * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Initial Developer of the Original Code is
15 * Miklos Vajna <vmiklos@suse.cz> (SUSE, Inc.)
16 * Portions created by the Initial Developer are Copyright (C) 2012 the
17 * Initial Developer. All Rights Reserved.
21 * Alternatively, the contents of this file may be used under the terms of
22 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
23 * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
24 * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
25 * instead of those above.
28 #include <unotools/tempfile.hxx>
29 #include <swmodeltestbase.hxx>
31 class Test
: public SwModelTestBase
35 void testFirstHeaderFooter();
37 CPPUNIT_TEST_SUITE(Test
);
38 #if !defined(MACOSX) && !defined(WNT)
41 CPPUNIT_TEST_SUITE_END();
49 MethodEntry
<Test
> aMethods
[] = {
50 {"fdo38244.odt", &Test::testFdo38244
},
51 {"first-header-footer.odt", &Test::testFirstHeaderFooter
},
53 for (unsigned int i
= 0; i
< SAL_N_ELEMENTS(aMethods
); ++i
)
55 MethodEntry
<Test
>& rEntry
= aMethods
[i
];
56 mxComponent
= loadFromDesktop(getURLFromSrc("/sw/qa/extras/odfexport/data/") + OUString::createFromAscii(rEntry
.pName
));
57 // If the testcase is stored in some other format, it's pointless to test.
58 if (OString(rEntry
.pName
).endsWith(".odt"))
59 (this->*rEntry
.pMethod
)();
60 uno::Reference
<frame::XStorable
> xStorable(mxComponent
, uno::UNO_QUERY
);
61 uno::Sequence
<beans::PropertyValue
> aArgs(1);
62 aArgs
[0].Name
= "FilterName";
63 aArgs
[0].Value
<<= OUString("writer8");
64 utl::TempFile aTempFile
;
65 aTempFile
.EnableKillingFile();
66 xStorable
->storeToURL(aTempFile
.GetURL(), aArgs
);
67 uno::Reference
<lang::XComponent
> xComponent(xStorable
, uno::UNO_QUERY
);
68 xComponent
->dispose();
69 mxComponent
= loadFromDesktop(aTempFile
.GetURL());
70 (this->*rEntry
.pMethod
)();
74 void Test::testFdo38244()
76 // See ooxmlexport's testFdo38244().
78 // Test comment range feature.
79 uno::Reference
<text::XTextDocument
> xTextDocument(mxComponent
, uno::UNO_QUERY
);
80 uno::Reference
<container::XEnumerationAccess
> xParaEnumAccess(xTextDocument
->getText(), uno::UNO_QUERY
);
81 uno::Reference
<container::XEnumeration
> xParaEnum
= xParaEnumAccess
->createEnumeration();
82 uno::Reference
<container::XEnumerationAccess
> xRunEnumAccess(xParaEnum
->nextElement(), uno::UNO_QUERY
);
83 uno::Reference
<container::XEnumeration
> xRunEnum
= xRunEnumAccess
->createEnumeration();
84 xRunEnum
->nextElement();
85 uno::Reference
<beans::XPropertySet
> xPropertySet(xRunEnum
->nextElement(), uno::UNO_QUERY
);
86 CPPUNIT_ASSERT_EQUAL(OUString("TextFieldStart"), getProperty
<OUString
>(xPropertySet
, "TextPortionType"));
87 xRunEnum
->nextElement();
88 xPropertySet
.set(xRunEnum
->nextElement(), uno::UNO_QUERY
);
89 CPPUNIT_ASSERT_EQUAL(OUString("TextFieldEnd"), getProperty
<OUString
>(xPropertySet
, "TextPortionType"));
92 uno::Reference
<text::XTextFieldsSupplier
> xTextFieldsSupplier(mxComponent
, uno::UNO_QUERY
);
93 uno::Reference
<container::XEnumerationAccess
> xFieldsAccess(xTextFieldsSupplier
->getTextFields());
94 uno::Reference
<container::XEnumeration
> xFields(xFieldsAccess
->createEnumeration());
95 xPropertySet
.set(xFields
->nextElement(), uno::UNO_QUERY
);
96 CPPUNIT_ASSERT_EQUAL(OUString("__Fieldmark__4_1833023242"), getProperty
<OUString
>(xPropertySet
, "Name"));
97 CPPUNIT_ASSERT_EQUAL(OUString("M"), getProperty
<OUString
>(xPropertySet
, "Initials"));
100 void Test::testFirstHeaderFooter()
102 // Test import and export of the header-first token.
104 // The document has 6 pages, two page styles for the first and second half of pages.
105 CPPUNIT_ASSERT_EQUAL(OUString("First header"), parseDump("/root/page[1]/header/txt/text()"));
106 CPPUNIT_ASSERT_EQUAL(OUString("First footer"), parseDump("/root/page[1]/footer/txt/text()"));
107 CPPUNIT_ASSERT_EQUAL(OUString("Left header"), parseDump("/root/page[2]/header/txt/text()"));
108 CPPUNIT_ASSERT_EQUAL(OUString("Left footer"), parseDump("/root/page[2]/footer/txt/text()"));
109 CPPUNIT_ASSERT_EQUAL(OUString("Right header"), parseDump("/root/page[3]/header/txt/text()"));
110 CPPUNIT_ASSERT_EQUAL(OUString("Right footer"), parseDump("/root/page[3]/footer/txt/text()"));
111 CPPUNIT_ASSERT_EQUAL(OUString("First header2"), parseDump("/root/page[4]/header/txt/text()"));
112 CPPUNIT_ASSERT_EQUAL(OUString("First footer2"), parseDump("/root/page[4]/footer/txt/text()"));
113 CPPUNIT_ASSERT_EQUAL(OUString("Right header2"), parseDump("/root/page[5]/header/txt/text()"));
114 CPPUNIT_ASSERT_EQUAL(OUString("Right footer2"), parseDump("/root/page[5]/footer/txt/text()"));
115 CPPUNIT_ASSERT_EQUAL(OUString("Left header2"), parseDump("/root/page[6]/header/txt/text()"));
116 CPPUNIT_ASSERT_EQUAL(OUString("Left footer2"), parseDump("/root/page[6]/footer/txt/text()"));
119 CPPUNIT_TEST_SUITE_REGISTRATION(Test
);
121 CPPUNIT_PLUGIN_IMPLEMENT();
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */