Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : */
9 :
10 : #include <swmodeltestbase.hxx>
11 : #include <com/sun/star/awt/Gradient.hpp>
12 : #include <com/sun/star/drawing/FillStyle.hpp>
13 :
14 3 : class Test : public SwModelTestBase
15 : {
16 : public:
17 : void testFdo38244();
18 : void testFirstHeaderFooter();
19 : void testTextframeGradient();
20 : void testFdo60769();
21 : void testFdo58949();
22 :
23 2 : CPPUNIT_TEST_SUITE(Test);
24 : #if !defined(MACOSX) && !defined(WNT)
25 1 : CPPUNIT_TEST(run);
26 : #endif
27 2 : CPPUNIT_TEST_SUITE_END();
28 :
29 : private:
30 : void run();
31 : };
32 :
33 1 : void Test::run()
34 : {
35 : MethodEntry<Test> aMethods[] = {
36 : {"fdo38244.odt", &Test::testFdo38244},
37 : {"first-header-footer.odt", &Test::testFirstHeaderFooter},
38 : {"textframe-gradient.odt", &Test::testTextframeGradient},
39 : {"fdo60769.odt", &Test::testFdo60769},
40 : {"fdo58949.docx", &Test::testFdo58949},
41 1 : };
42 1 : header();
43 6 : for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
44 : {
45 5 : MethodEntry<Test>& rEntry = aMethods[i];
46 5 : load("/sw/qa/extras/odfexport/data/", rEntry.pName);
47 : // If the testcase is stored in some other format, it's pointless to test.
48 5 : if (OString(rEntry.pName).endsWith(".odt"))
49 4 : (this->*rEntry.pMethod)();
50 5 : reload("writer8");
51 5 : (this->*rEntry.pMethod)();
52 5 : finish();
53 : }
54 1 : }
55 :
56 2 : void Test::testFdo38244()
57 : {
58 : // See ooxmlexport's testFdo38244().
59 :
60 : // Test comment range feature.
61 2 : uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
62 4 : uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY);
63 4 : uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
64 4 : uno::Reference<container::XEnumerationAccess> xRunEnumAccess(xParaEnum->nextElement(), uno::UNO_QUERY);
65 4 : uno::Reference<container::XEnumeration> xRunEnum = xRunEnumAccess->createEnumeration();
66 2 : xRunEnum->nextElement();
67 4 : uno::Reference<beans::XPropertySet> xPropertySet(xRunEnum->nextElement(), uno::UNO_QUERY);
68 2 : CPPUNIT_ASSERT_EQUAL(OUString("TextFieldStart"), getProperty<OUString>(xPropertySet, "TextPortionType"));
69 2 : xRunEnum->nextElement();
70 2 : xPropertySet.set(xRunEnum->nextElement(), uno::UNO_QUERY);
71 2 : CPPUNIT_ASSERT_EQUAL(OUString("TextFieldEnd"), getProperty<OUString>(xPropertySet, "TextPortionType"));
72 :
73 : // Test properties
74 4 : uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
75 4 : uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
76 4 : uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
77 2 : xPropertySet.set(xFields->nextElement(), uno::UNO_QUERY);
78 2 : CPPUNIT_ASSERT_EQUAL(OUString("__Fieldmark__4_1833023242"), getProperty<OUString>(xPropertySet, "Name"));
79 4 : CPPUNIT_ASSERT_EQUAL(OUString("M"), getProperty<OUString>(xPropertySet, "Initials"));
80 2 : }
81 :
82 2 : void Test::testFirstHeaderFooter()
83 : {
84 : // Test import and export of the header-first token.
85 :
86 : // The document has 6 pages, two page styles for the first and second half of pages.
87 2 : CPPUNIT_ASSERT_EQUAL(OUString("First header"), parseDump("/root/page[1]/header/txt/text()"));
88 2 : CPPUNIT_ASSERT_EQUAL(OUString("First footer"), parseDump("/root/page[1]/footer/txt/text()"));
89 2 : CPPUNIT_ASSERT_EQUAL(OUString("Left header"), parseDump("/root/page[2]/header/txt/text()"));
90 2 : CPPUNIT_ASSERT_EQUAL(OUString("Left footer"), parseDump("/root/page[2]/footer/txt/text()"));
91 2 : CPPUNIT_ASSERT_EQUAL(OUString("Right header"), parseDump("/root/page[3]/header/txt/text()"));
92 2 : CPPUNIT_ASSERT_EQUAL(OUString("Right footer"), parseDump("/root/page[3]/footer/txt/text()"));
93 2 : CPPUNIT_ASSERT_EQUAL(OUString("First header2"), parseDump("/root/page[4]/header/txt/text()"));
94 2 : CPPUNIT_ASSERT_EQUAL(OUString("First footer2"), parseDump("/root/page[4]/footer/txt/text()"));
95 2 : CPPUNIT_ASSERT_EQUAL(OUString("Right header2"), parseDump("/root/page[5]/header/txt/text()"));
96 2 : CPPUNIT_ASSERT_EQUAL(OUString("Right footer2"), parseDump("/root/page[5]/footer/txt/text()"));
97 2 : CPPUNIT_ASSERT_EQUAL(OUString("Left header2"), parseDump("/root/page[6]/header/txt/text()"));
98 2 : CPPUNIT_ASSERT_EQUAL(OUString("Left footer2"), parseDump("/root/page[6]/footer/txt/text()"));
99 2 : }
100 :
101 2 : void Test::testTextframeGradient()
102 : {
103 2 : uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY);
104 4 : uno::Reference<container::XIndexAccess> xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY);
105 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount());
106 :
107 4 : uno::Reference<beans::XPropertySet> xFrame(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
108 2 : CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_GRADIENT, getProperty<drawing::FillStyle>(xFrame, "FillStyle"));
109 2 : awt::Gradient aGradient = getProperty<awt::Gradient>(xFrame, "FillGradient");
110 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0xC0504D), aGradient.StartColor);
111 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0xD99594), aGradient.EndColor);
112 2 : CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_AXIAL, aGradient.Style);
113 :
114 2 : xFrame.set(xIndexAccess->getByIndex(1), uno::UNO_QUERY);
115 2 : CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_GRADIENT, getProperty<drawing::FillStyle>(xFrame, "FillStyle"));
116 2 : aGradient = getProperty<awt::Gradient>(xFrame, "FillGradient");
117 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0x000000), aGradient.StartColor);
118 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0x666666), aGradient.EndColor);
119 4 : CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_AXIAL, aGradient.Style);
120 2 : }
121 :
122 2 : void Test::testFdo60769()
123 : {
124 : // Test multi-paragraph comment range feature.
125 2 : uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
126 4 : uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY);
127 4 : uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
128 4 : uno::Reference<container::XEnumerationAccess> xRunEnumAccess(xParaEnum->nextElement(), uno::UNO_QUERY);
129 4 : uno::Reference<container::XEnumeration> xRunEnum = xRunEnumAccess->createEnumeration();
130 16 : while (xRunEnum->hasMoreElements())
131 : {
132 12 : uno::Reference<beans::XPropertySet> xPropertySet(xRunEnum->nextElement(), uno::UNO_QUERY);
133 24 : OUString aType = getProperty<OUString>(xPropertySet, "TextPortionType");
134 : // First paragraph: no field end, no anchor
135 12 : CPPUNIT_ASSERT(aType == "Text" || aType == "TextFieldStart");
136 12 : }
137 :
138 2 : xRunEnumAccess.set(xParaEnum->nextElement(), uno::UNO_QUERY);
139 4 : while (xRunEnum->hasMoreElements())
140 : {
141 0 : uno::Reference<beans::XPropertySet> xPropertySet(xRunEnum->nextElement(), uno::UNO_QUERY);
142 0 : OUString aType = getProperty<OUString>(xPropertySet, "TextPortionType");
143 : // Second paragraph: no field start
144 0 : CPPUNIT_ASSERT(aType == "Text" || aType == "TextFieldEnd");
145 2 : }
146 2 : }
147 :
148 1 : void Test::testFdo58949()
149 : {
150 : /*
151 : * The problem was that the exporter didn't insert "Obj102" to the
152 : * resulting zip file. No idea how to check for "broken" (missing OLE data
153 : * and replacement image) OLE objects using UNO, so we'll check the zip file directly.
154 : */
155 :
156 1 : utl::TempFile aTempFile;
157 1 : save("writer8", aTempFile);
158 :
159 2 : uno::Sequence<uno::Any> aArgs(1);
160 1 : aArgs[0] <<= OUString(aTempFile.GetURL());
161 2 : uno::Reference<container::XNameAccess> xNameAccess(m_xSFactory->createInstanceWithArguments("com.sun.star.packages.zip.ZipFileAccess", aArgs), uno::UNO_QUERY);
162 2 : CPPUNIT_ASSERT_EQUAL(true, bool(xNameAccess->hasByName("Obj102")));
163 1 : }
164 :
165 1 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
166 :
167 4 : CPPUNIT_PLUGIN_IMPLEMENT();
168 :
169 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|