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 <com/sun/star/form/validation/XValidatableFormComponent.hpp>
29 : #include <com/sun/star/frame/XStorable.hpp>
30 : #include <com/sun/star/drawing/XControlShape.hpp>
31 : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
32 : #include <com/sun/star/beans/XPropertySet.hpp>
33 :
34 : #include <unotools/tempfile.hxx>
35 :
36 : #include <swmodeltestbase.hxx>
37 :
38 6 : class Test : public SwModelTestBase
39 : {
40 : public:
41 : void testN325936();
42 : void testFdo45724();
43 : void testFdo46020();
44 : void testFirstHeaderFooter();
45 :
46 4 : CPPUNIT_TEST_SUITE(Test);
47 : #if !defined(MACOSX) && !defined(WNT)
48 2 : CPPUNIT_TEST(run);
49 : #endif
50 4 : CPPUNIT_TEST_SUITE_END();
51 :
52 : private:
53 : void run();
54 : };
55 :
56 2 : void Test::run()
57 : {
58 : MethodEntry<Test> aMethods[] = {
59 : {"n325936.doc", &Test::testN325936},
60 : {"fdo45724.odt", &Test::testFdo45724},
61 : {"fdo46020.odt", &Test::testFdo46020},
62 : {"first-header-footer.doc", &Test::testFirstHeaderFooter},
63 2 : };
64 10 : for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
65 : {
66 8 : MethodEntry<Test>& rEntry = aMethods[i];
67 8 : mxComponent = loadFromDesktop(getURLFromSrc("/sw/qa/extras/ww8export/data/") + OUString::createFromAscii(rEntry.pName));
68 : // If the testcase is stored in some other format, it's pointless to test.
69 8 : if (OString(rEntry.pName).endsWith(".doc"))
70 4 : (this->*rEntry.pMethod)();
71 8 : uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
72 8 : uno::Sequence<beans::PropertyValue> aArgs(1);
73 8 : aArgs[0].Name = "FilterName";
74 8 : aArgs[0].Value <<= OUString("MS Word 97");
75 8 : utl::TempFile aTempFile;
76 8 : aTempFile.EnableKillingFile();
77 8 : xStorable->storeToURL(aTempFile.GetURL(), aArgs);
78 8 : mxComponent = loadFromDesktop(aTempFile.GetURL());
79 8 : (this->*rEntry.pMethod)();
80 8 : }
81 2 : }
82 :
83 4 : void Test::testN325936()
84 : {
85 : /*
86 : * The problem was that the transparent background of the drawing in the
87 : * header was exported as non-transparent.
88 : *
89 : * xray ThisComponent.DrawPage(0).BackColorTransparency
90 : */
91 :
92 4 : uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
93 4 : uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
94 4 : uno::Reference<beans::XPropertySet> xPropertySet(xDraws->getByIndex(0), uno::UNO_QUERY);
95 4 : sal_Int32 nValue = getProperty< sal_Int32 >(xDraws->getByIndex(0), "BackColorTransparency");
96 4 : CPPUNIT_ASSERT_EQUAL(sal_Int32(100), nValue);
97 4 : }
98 :
99 2 : void Test::testFdo45724()
100 : {
101 : // The text and background color of the control shape was not correct.
102 2 : uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
103 2 : uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
104 2 : uno::Reference<drawing::XControlShape> xControlShape(xDraws->getByIndex(0), uno::UNO_QUERY);
105 : // This should not happen (the shape was there before the fix as well), but let's avoid a segfault in some random cases...
106 2 : if (xControlShape.is())
107 : {
108 2 : uno::Reference<form::validation::XValidatableFormComponent> xComponent(xControlShape->getControl(), uno::UNO_QUERY);
109 2 : CPPUNIT_ASSERT_EQUAL(COL_WHITE, getProperty<sal_uInt32>(xComponent, "BackgroundColor"));
110 2 : CPPUNIT_ASSERT_EQUAL(OUString("xxx"), xComponent->getCurrentValue().get<OUString>());
111 2 : }
112 2 : }
113 :
114 2 : void Test::testFdo46020()
115 : {
116 : // The footnote in that document wasn't exported, check that it is actually exported
117 2 : uno::Reference<text::XFootnotesSupplier> xFootnotesSupplier(mxComponent, uno::UNO_QUERY);
118 2 : uno::Reference<container::XIndexAccess> xFootnotes(xFootnotesSupplier->getFootnotes(), uno::UNO_QUERY);
119 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xFootnotes->getCount());
120 2 : }
121 :
122 4 : void Test::testFirstHeaderFooter()
123 : {
124 : // Test import and export of a section's headerf/footerf properties.
125 :
126 : // The document has 6 pages. Note that we don't test if 4 or just 2 page
127 : // styles are created, the point is that layout should be correct.
128 4 : CPPUNIT_ASSERT_EQUAL(OUString("First page header"), parseDump("/root/page[1]/header/txt/text()"));
129 4 : CPPUNIT_ASSERT_EQUAL(OUString("First page footer"), parseDump("/root/page[1]/footer/txt/text()"));
130 4 : CPPUNIT_ASSERT_EQUAL(OUString("Even page header"), parseDump("/root/page[2]/header/txt/text()"));
131 4 : CPPUNIT_ASSERT_EQUAL(OUString("Even page footer"), parseDump("/root/page[2]/footer/txt/text()"));
132 4 : CPPUNIT_ASSERT_EQUAL(OUString("Odd page header"), parseDump("/root/page[3]/header/txt/text()"));
133 4 : CPPUNIT_ASSERT_EQUAL(OUString("Odd page footer"), parseDump("/root/page[3]/footer/txt/text()"));
134 4 : CPPUNIT_ASSERT_EQUAL(OUString("First page header2"), parseDump("/root/page[4]/header/txt/text()"));
135 4 : CPPUNIT_ASSERT_EQUAL(OUString("First page footer 2"), parseDump("/root/page[4]/footer/txt/text()"));
136 4 : CPPUNIT_ASSERT_EQUAL(OUString("Odd page header 2"), parseDump("/root/page[5]/header/txt/text()"));
137 4 : CPPUNIT_ASSERT_EQUAL(OUString("Odd page footer 2"), parseDump("/root/page[5]/footer/txt/text()"));
138 4 : CPPUNIT_ASSERT_EQUAL(OUString("Even page header 2"), parseDump("/root/page[6]/header/txt/text()"));
139 4 : CPPUNIT_ASSERT_EQUAL(OUString("Even page footer 2"), parseDump("/root/page[6]/footer/txt/text()"));
140 4 : }
141 :
142 2 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
143 :
144 8 : CPPUNIT_PLUGIN_IMPLEMENT();
145 :
146 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|