Line data Source code
1 : /*
2 : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
3 : *
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/
8 : *
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
12 : * License.
13 : *
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.
18 : *
19 : * Contributor(s):
20 : *
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.
26 : */
27 :
28 : #include <swmodeltestbase.hxx>
29 :
30 3 : class Test : public SwModelTestBase
31 : {
32 : public:
33 : void testFdo38244();
34 : void testFirstHeaderFooter();
35 :
36 2 : CPPUNIT_TEST_SUITE(Test);
37 : #if !defined(MACOSX) && !defined(WNT)
38 1 : CPPUNIT_TEST(run);
39 : #endif
40 2 : CPPUNIT_TEST_SUITE_END();
41 :
42 : private:
43 : void run();
44 : };
45 :
46 1 : void Test::run()
47 : {
48 : MethodEntry<Test> aMethods[] = {
49 : {"fdo38244.odt", &Test::testFdo38244},
50 : {"first-header-footer.odt", &Test::testFirstHeaderFooter},
51 1 : };
52 1 : header();
53 3 : for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
54 : {
55 2 : MethodEntry<Test>& rEntry = aMethods[i];
56 2 : load("/sw/qa/extras/odfexport/data/", rEntry.pName);
57 : // If the testcase is stored in some other format, it's pointless to test.
58 2 : if (OString(rEntry.pName).endsWith(".odt"))
59 2 : (this->*rEntry.pMethod)();
60 2 : reload("writer8");
61 2 : (this->*rEntry.pMethod)();
62 2 : finish();
63 : }
64 1 : }
65 :
66 2 : void Test::testFdo38244()
67 : {
68 : // See ooxmlexport's testFdo38244().
69 :
70 : // Test comment range feature.
71 2 : uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
72 2 : uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY);
73 2 : uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
74 2 : uno::Reference<container::XEnumerationAccess> xRunEnumAccess(xParaEnum->nextElement(), uno::UNO_QUERY);
75 2 : uno::Reference<container::XEnumeration> xRunEnum = xRunEnumAccess->createEnumeration();
76 2 : xRunEnum->nextElement();
77 2 : uno::Reference<beans::XPropertySet> xPropertySet(xRunEnum->nextElement(), uno::UNO_QUERY);
78 2 : CPPUNIT_ASSERT_EQUAL(OUString("TextFieldStart"), getProperty<OUString>(xPropertySet, "TextPortionType"));
79 2 : xRunEnum->nextElement();
80 2 : xPropertySet.set(xRunEnum->nextElement(), uno::UNO_QUERY);
81 2 : CPPUNIT_ASSERT_EQUAL(OUString("TextFieldEnd"), getProperty<OUString>(xPropertySet, "TextPortionType"));
82 :
83 : // Test properties
84 2 : uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
85 2 : uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
86 2 : uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
87 2 : xPropertySet.set(xFields->nextElement(), uno::UNO_QUERY);
88 2 : CPPUNIT_ASSERT_EQUAL(OUString("__Fieldmark__4_1833023242"), getProperty<OUString>(xPropertySet, "Name"));
89 2 : CPPUNIT_ASSERT_EQUAL(OUString("M"), getProperty<OUString>(xPropertySet, "Initials"));
90 2 : }
91 :
92 2 : void Test::testFirstHeaderFooter()
93 : {
94 : // Test import and export of the header-first token.
95 :
96 : // The document has 6 pages, two page styles for the first and second half of pages.
97 2 : CPPUNIT_ASSERT_EQUAL(OUString("First header"), parseDump("/root/page[1]/header/txt/text()"));
98 2 : CPPUNIT_ASSERT_EQUAL(OUString("First footer"), parseDump("/root/page[1]/footer/txt/text()"));
99 2 : CPPUNIT_ASSERT_EQUAL(OUString("Left header"), parseDump("/root/page[2]/header/txt/text()"));
100 2 : CPPUNIT_ASSERT_EQUAL(OUString("Left footer"), parseDump("/root/page[2]/footer/txt/text()"));
101 2 : CPPUNIT_ASSERT_EQUAL(OUString("Right header"), parseDump("/root/page[3]/header/txt/text()"));
102 2 : CPPUNIT_ASSERT_EQUAL(OUString("Right footer"), parseDump("/root/page[3]/footer/txt/text()"));
103 2 : CPPUNIT_ASSERT_EQUAL(OUString("First header2"), parseDump("/root/page[4]/header/txt/text()"));
104 2 : CPPUNIT_ASSERT_EQUAL(OUString("First footer2"), parseDump("/root/page[4]/footer/txt/text()"));
105 2 : CPPUNIT_ASSERT_EQUAL(OUString("Right header2"), parseDump("/root/page[5]/header/txt/text()"));
106 2 : CPPUNIT_ASSERT_EQUAL(OUString("Right footer2"), parseDump("/root/page[5]/footer/txt/text()"));
107 2 : CPPUNIT_ASSERT_EQUAL(OUString("Left header2"), parseDump("/root/page[6]/header/txt/text()"));
108 2 : CPPUNIT_ASSERT_EQUAL(OUString("Left footer2"), parseDump("/root/page[6]/footer/txt/text()"));
109 2 : }
110 :
111 1 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
112 :
113 4 : CPPUNIT_PLUGIN_IMPLEMENT();
114 :
115 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|