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 <unotools/tempfile.hxx>
29 : #include <swmodeltestbase.hxx>
30 :
31 6 : class Test : public SwModelTestBase
32 : {
33 : public:
34 : void testFdo38244();
35 : void testFirstHeaderFooter();
36 :
37 4 : CPPUNIT_TEST_SUITE(Test);
38 : #if !defined(MACOSX) && !defined(WNT)
39 2 : CPPUNIT_TEST(run);
40 : #endif
41 4 : CPPUNIT_TEST_SUITE_END();
42 :
43 : private:
44 : void run();
45 : };
46 :
47 2 : void Test::run()
48 : {
49 : MethodEntry<Test> aMethods[] = {
50 : {"fdo38244.odt", &Test::testFdo38244},
51 : {"first-header-footer.odt", &Test::testFirstHeaderFooter},
52 2 : };
53 6 : for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
54 : {
55 4 : MethodEntry<Test>& rEntry = aMethods[i];
56 4 : 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 4 : if (OString(rEntry.pName).endsWith(".odt"))
59 4 : (this->*rEntry.pMethod)();
60 4 : uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
61 4 : uno::Sequence<beans::PropertyValue> aArgs(1);
62 4 : aArgs[0].Name = "FilterName";
63 4 : aArgs[0].Value <<= OUString("writer8");
64 4 : utl::TempFile aTempFile;
65 4 : aTempFile.EnableKillingFile();
66 4 : xStorable->storeToURL(aTempFile.GetURL(), aArgs);
67 4 : uno::Reference<lang::XComponent> xComponent(xStorable, uno::UNO_QUERY);
68 4 : xComponent->dispose();
69 4 : mxComponent = loadFromDesktop(aTempFile.GetURL());
70 4 : (this->*rEntry.pMethod)();
71 4 : }
72 2 : }
73 :
74 4 : void Test::testFdo38244()
75 : {
76 : // See ooxmlexport's testFdo38244().
77 :
78 : // Test comment range feature.
79 4 : uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
80 4 : uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY);
81 4 : uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
82 4 : uno::Reference<container::XEnumerationAccess> xRunEnumAccess(xParaEnum->nextElement(), uno::UNO_QUERY);
83 4 : uno::Reference<container::XEnumeration> xRunEnum = xRunEnumAccess->createEnumeration();
84 4 : xRunEnum->nextElement();
85 4 : uno::Reference<beans::XPropertySet> xPropertySet(xRunEnum->nextElement(), uno::UNO_QUERY);
86 4 : CPPUNIT_ASSERT_EQUAL(OUString("TextFieldStart"), getProperty<OUString>(xPropertySet, "TextPortionType"));
87 4 : xRunEnum->nextElement();
88 4 : xPropertySet.set(xRunEnum->nextElement(), uno::UNO_QUERY);
89 4 : CPPUNIT_ASSERT_EQUAL(OUString("TextFieldEnd"), getProperty<OUString>(xPropertySet, "TextPortionType"));
90 :
91 : // Test properties
92 4 : uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
93 4 : uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
94 4 : uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
95 4 : xPropertySet.set(xFields->nextElement(), uno::UNO_QUERY);
96 4 : CPPUNIT_ASSERT_EQUAL(OUString("__Fieldmark__4_1833023242"), getProperty<OUString>(xPropertySet, "Name"));
97 4 : CPPUNIT_ASSERT_EQUAL(OUString("M"), getProperty<OUString>(xPropertySet, "Initials"));
98 4 : }
99 :
100 4 : void Test::testFirstHeaderFooter()
101 : {
102 : // Test import and export of the header-first token.
103 :
104 : // The document has 6 pages, two page styles for the first and second half of pages.
105 4 : CPPUNIT_ASSERT_EQUAL(OUString("First header"), parseDump("/root/page[1]/header/txt/text()"));
106 4 : CPPUNIT_ASSERT_EQUAL(OUString("First footer"), parseDump("/root/page[1]/footer/txt/text()"));
107 4 : CPPUNIT_ASSERT_EQUAL(OUString("Left header"), parseDump("/root/page[2]/header/txt/text()"));
108 4 : CPPUNIT_ASSERT_EQUAL(OUString("Left footer"), parseDump("/root/page[2]/footer/txt/text()"));
109 4 : CPPUNIT_ASSERT_EQUAL(OUString("Right header"), parseDump("/root/page[3]/header/txt/text()"));
110 4 : CPPUNIT_ASSERT_EQUAL(OUString("Right footer"), parseDump("/root/page[3]/footer/txt/text()"));
111 4 : CPPUNIT_ASSERT_EQUAL(OUString("First header2"), parseDump("/root/page[4]/header/txt/text()"));
112 4 : CPPUNIT_ASSERT_EQUAL(OUString("First footer2"), parseDump("/root/page[4]/footer/txt/text()"));
113 4 : CPPUNIT_ASSERT_EQUAL(OUString("Right header2"), parseDump("/root/page[5]/header/txt/text()"));
114 4 : CPPUNIT_ASSERT_EQUAL(OUString("Right footer2"), parseDump("/root/page[5]/footer/txt/text()"));
115 4 : CPPUNIT_ASSERT_EQUAL(OUString("Left header2"), parseDump("/root/page[6]/header/txt/text()"));
116 4 : CPPUNIT_ASSERT_EQUAL(OUString("Left footer2"), parseDump("/root/page[6]/footer/txt/text()"));
117 4 : }
118 :
119 2 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
120 :
121 8 : CPPUNIT_PLUGIN_IMPLEMENT();
122 :
123 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|