bump product version to 4.1.6.2
[LibreOffice.git] / sw / qa / extras / odfexport / odfexport.cxx
blob09c342a65bac4bf36ade3ee155f5ffef5754d8e5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include <swmodeltestbase.hxx>
11 #include <com/sun/star/awt/Gradient.hpp>
12 #include <com/sun/star/drawing/FillStyle.hpp>
14 class Test : public SwModelTestBase
16 public:
17 void testFdo38244();
18 void testFirstHeaderFooter();
19 void testTextframeGradient();
20 void testFdo60769();
21 void testFdo58949();
23 CPPUNIT_TEST_SUITE(Test);
24 #if !defined(MACOSX) && !defined(WNT)
25 CPPUNIT_TEST(run);
26 #endif
27 CPPUNIT_TEST_SUITE_END();
29 private:
30 void run();
33 void Test::run()
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},
42 header();
43 for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
45 MethodEntry<Test>& rEntry = aMethods[i];
46 load("/sw/qa/extras/odfexport/data/", rEntry.pName);
47 // If the testcase is stored in some other format, it's pointless to test.
48 if (OString(rEntry.pName).endsWith(".odt"))
49 (this->*rEntry.pMethod)();
50 reload("writer8");
51 (this->*rEntry.pMethod)();
52 finish();
56 void Test::testFdo38244()
58 // See ooxmlexport's testFdo38244().
60 // Test comment range feature.
61 uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
62 uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY);
63 uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
64 uno::Reference<container::XEnumerationAccess> xRunEnumAccess(xParaEnum->nextElement(), uno::UNO_QUERY);
65 uno::Reference<container::XEnumeration> xRunEnum = xRunEnumAccess->createEnumeration();
66 xRunEnum->nextElement();
67 uno::Reference<beans::XPropertySet> xPropertySet(xRunEnum->nextElement(), uno::UNO_QUERY);
68 CPPUNIT_ASSERT_EQUAL(OUString("TextFieldStart"), getProperty<OUString>(xPropertySet, "TextPortionType"));
69 xRunEnum->nextElement();
70 xPropertySet.set(xRunEnum->nextElement(), uno::UNO_QUERY);
71 CPPUNIT_ASSERT_EQUAL(OUString("TextFieldEnd"), getProperty<OUString>(xPropertySet, "TextPortionType"));
73 // Test properties
74 uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
75 uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
76 uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
77 xPropertySet.set(xFields->nextElement(), uno::UNO_QUERY);
78 CPPUNIT_ASSERT_EQUAL(OUString("__Fieldmark__4_1833023242"), getProperty<OUString>(xPropertySet, "Name"));
79 CPPUNIT_ASSERT_EQUAL(OUString("M"), getProperty<OUString>(xPropertySet, "Initials"));
82 void Test::testFirstHeaderFooter()
84 // Test import and export of the header-first token.
86 // The document has 6 pages, two page styles for the first and second half of pages.
87 CPPUNIT_ASSERT_EQUAL(OUString("First header"), parseDump("/root/page[1]/header/txt/text()"));
88 CPPUNIT_ASSERT_EQUAL(OUString("First footer"), parseDump("/root/page[1]/footer/txt/text()"));
89 CPPUNIT_ASSERT_EQUAL(OUString("Left header"), parseDump("/root/page[2]/header/txt/text()"));
90 CPPUNIT_ASSERT_EQUAL(OUString("Left footer"), parseDump("/root/page[2]/footer/txt/text()"));
91 CPPUNIT_ASSERT_EQUAL(OUString("Right header"), parseDump("/root/page[3]/header/txt/text()"));
92 CPPUNIT_ASSERT_EQUAL(OUString("Right footer"), parseDump("/root/page[3]/footer/txt/text()"));
93 CPPUNIT_ASSERT_EQUAL(OUString("First header2"), parseDump("/root/page[4]/header/txt/text()"));
94 CPPUNIT_ASSERT_EQUAL(OUString("First footer2"), parseDump("/root/page[4]/footer/txt/text()"));
95 CPPUNIT_ASSERT_EQUAL(OUString("Right header2"), parseDump("/root/page[5]/header/txt/text()"));
96 CPPUNIT_ASSERT_EQUAL(OUString("Right footer2"), parseDump("/root/page[5]/footer/txt/text()"));
97 CPPUNIT_ASSERT_EQUAL(OUString("Left header2"), parseDump("/root/page[6]/header/txt/text()"));
98 CPPUNIT_ASSERT_EQUAL(OUString("Left footer2"), parseDump("/root/page[6]/footer/txt/text()"));
101 void Test::testTextframeGradient()
103 uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY);
104 uno::Reference<container::XIndexAccess> xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY);
105 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount());
107 uno::Reference<beans::XPropertySet> xFrame(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
108 CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_GRADIENT, getProperty<drawing::FillStyle>(xFrame, "FillStyle"));
109 awt::Gradient aGradient = getProperty<awt::Gradient>(xFrame, "FillGradient");
110 CPPUNIT_ASSERT_EQUAL(sal_Int32(0xC0504D), aGradient.StartColor);
111 CPPUNIT_ASSERT_EQUAL(sal_Int32(0xD99594), aGradient.EndColor);
112 CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_AXIAL, aGradient.Style);
114 xFrame.set(xIndexAccess->getByIndex(1), uno::UNO_QUERY);
115 CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_GRADIENT, getProperty<drawing::FillStyle>(xFrame, "FillStyle"));
116 aGradient = getProperty<awt::Gradient>(xFrame, "FillGradient");
117 CPPUNIT_ASSERT_EQUAL(sal_Int32(0x000000), aGradient.StartColor);
118 CPPUNIT_ASSERT_EQUAL(sal_Int32(0x666666), aGradient.EndColor);
119 CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_AXIAL, aGradient.Style);
122 void Test::testFdo60769()
124 // Test multi-paragraph comment range feature.
125 uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
126 uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY);
127 uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
128 uno::Reference<container::XEnumerationAccess> xRunEnumAccess(xParaEnum->nextElement(), uno::UNO_QUERY);
129 uno::Reference<container::XEnumeration> xRunEnum = xRunEnumAccess->createEnumeration();
130 while (xRunEnum->hasMoreElements())
132 uno::Reference<beans::XPropertySet> xPropertySet(xRunEnum->nextElement(), uno::UNO_QUERY);
133 OUString aType = getProperty<OUString>(xPropertySet, "TextPortionType");
134 // First paragraph: no field end, no anchor
135 CPPUNIT_ASSERT(aType == "Text" || aType == "TextFieldStart");
138 xRunEnumAccess.set(xParaEnum->nextElement(), uno::UNO_QUERY);
139 while (xRunEnum->hasMoreElements())
141 uno::Reference<beans::XPropertySet> xPropertySet(xRunEnum->nextElement(), uno::UNO_QUERY);
142 OUString aType = getProperty<OUString>(xPropertySet, "TextPortionType");
143 // Second paragraph: no field start
144 CPPUNIT_ASSERT(aType == "Text" || aType == "TextFieldEnd" || aType == "TextFieldEnd");
148 void Test::testFdo58949()
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.
156 utl::TempFile aTempFile;
157 save("writer8", aTempFile);
159 uno::Sequence<uno::Any> aArgs(1);
160 aArgs[0] <<= OUString(aTempFile.GetURL());
161 uno::Reference<container::XNameAccess> xNameAccess(m_xSFactory->createInstanceWithArguments("com.sun.star.packages.zip.ZipFileAccess", aArgs), uno::UNO_QUERY);
162 CPPUNIT_ASSERT_EQUAL(true, bool(xNameAccess->hasByName("Obj102")));
165 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
167 CPPUNIT_PLUGIN_IMPLEMENT();
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */