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 :
12 : #include <initializer_list>
13 :
14 : #if !defined(MACOSX)
15 : #include <com/sun/star/awt/Gradient.hpp>
16 : #include <com/sun/star/container/XIndexReplace.hpp>
17 : #include <com/sun/star/drawing/FillStyle.hpp>
18 : #include <com/sun/star/table/ShadowFormat.hpp>
19 : #include <com/sun/star/text/RelOrientation.hpp>
20 : #include <com/sun/star/text/XDocumentIndex.hpp>
21 : #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
22 : #include <com/sun/star/awt/XBitmap.hpp>
23 : #include <com/sun/star/graphic/XGraphic.hpp>
24 : #include <officecfg/Office/Common.hxx>
25 :
26 34 : class Test : public SwModelTestBase
27 : {
28 : public:
29 34 : Test() : SwModelTestBase("/sw/qa/extras/odfexport/data/", "writer8") {}
30 :
31 : /**
32 : * Blacklist handling
33 : */
34 17 : bool mustTestImportOf(const char* filename) const SAL_OVERRIDE {
35 : // Only test import of .odt document
36 17 : return OString(filename).endsWith(".odt");
37 : }
38 :
39 17 : bool mustValidate(const char* filename) const SAL_OVERRIDE
40 : {
41 : std::vector<const char*> aBlacklist = {
42 : // These are known problems, they should be fixed one by one.
43 : "fdo86963.odt",
44 : "shape-relsize.odt",
45 : "fdo60769.odt",
46 : "first-header-footer.odt",
47 : "fdo38244.odt"
48 17 : };
49 :
50 17 : return std::find(aBlacklist.begin(), aBlacklist.end(), filename) == aBlacklist.end();
51 : }
52 :
53 33 : virtual void preTest(const char* pFilename) SAL_OVERRIDE
54 : {
55 33 : if (OString(pFilename) == "fdo58949.docx")
56 : {
57 1 : std::shared_ptr<comphelper::ConfigurationChanges> pBatch(comphelper::ConfigurationChanges::create());
58 1 : officecfg::Office::Common::Filter::Microsoft::Import::MathTypeToMath::set(false, pBatch);
59 1 : pBatch->commit();
60 : }
61 33 : }
62 :
63 33 : virtual void postTest(const char* pFilename) SAL_OVERRIDE
64 : {
65 33 : if (OString(pFilename) == "fdo58949.docx")
66 : {
67 1 : std::shared_ptr<comphelper::ConfigurationChanges> pBatch(comphelper::ConfigurationChanges::create());
68 1 : officecfg::Office::Common::Filter::Microsoft::Import::MathTypeToMath::set(true, pBatch);
69 1 : pBatch->commit();
70 : }
71 33 : }
72 : };
73 :
74 17 : DECLARE_ODFEXPORT_TEST(testFramebackgrounds, "framebackgrounds.odt")
75 : {
76 : //Counting the Number of Frames and checking with the expected count
77 2 : uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY);
78 4 : uno::Reference<container::XIndexAccess> xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY);
79 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(16), xIndexAccess->getCount());
80 4 : uno::Reference<drawing::XShape> xTextFrame;
81 2 : awt::Gradient aGradientxTextFrame;
82 : //Frame 1
83 2 : xTextFrame = getShape(1);
84 2 : CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_NONE, getProperty<drawing::FillStyle>(xTextFrame, "FillStyle"));
85 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xTextFrame, "FillTransparence"));
86 : //Frame 2
87 2 : xTextFrame = getShape(2);
88 2 : CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_SOLID, getProperty<drawing::FillStyle>(xTextFrame, "FillStyle"));
89 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0x006600), getProperty<util::Color>(xTextFrame, "FillColor"));
90 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xTextFrame, "FillTransparence"));
91 : //Frame 3
92 2 : xTextFrame = getShape(3);
93 2 : CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_SOLID, getProperty<drawing::FillStyle>(xTextFrame, "FillStyle"));
94 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0x006600), getProperty<util::Color>(xTextFrame, "FillColor"));
95 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(45), getProperty<sal_Int32>(xTextFrame, "FillTransparence"));
96 : //Frame 4
97 2 : xTextFrame = getShape(4);
98 2 : CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_SOLID, getProperty<drawing::FillStyle>(xTextFrame, "FillStyle"));
99 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0x579D1C), getProperty<util::Color>(xTextFrame, "FillColor"));
100 2 : aGradientxTextFrame = getProperty<awt::Gradient>(xTextFrame, "FillTransparenceGradient");
101 2 : CPPUNIT_ASSERT_EQUAL(css::awt::GradientStyle_LINEAR, aGradientxTextFrame.Style);
102 : //Frame 5
103 2 : xTextFrame = getShape(5);
104 2 : CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_GRADIENT, getProperty<drawing::FillStyle>(xTextFrame, "FillStyle"));
105 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xTextFrame, "FillTransparence"));
106 2 : CPPUNIT_ASSERT_EQUAL(OUString("Subtle Tango Green"), getProperty<OUString>(xTextFrame, "FillGradientName"));
107 : //Frame 6
108 2 : xTextFrame = getShape(6);
109 2 : CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_GRADIENT, getProperty<drawing::FillStyle>(xTextFrame, "FillStyle"));
110 2 : CPPUNIT_ASSERT_EQUAL(OUString("Subtle Tango Green"), getProperty<OUString>(xTextFrame, "FillGradientName"));
111 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(45), getProperty<sal_Int32>(xTextFrame, "FillTransparence"));
112 : //Frame 7
113 2 : xTextFrame = getShape(7);
114 2 : CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_GRADIENT, getProperty<drawing::FillStyle>(xTextFrame, "FillStyle"));
115 2 : CPPUNIT_ASSERT_EQUAL(OUString("Subtle Tango Green"), getProperty<OUString>(xTextFrame, "FillGradientName"));
116 2 : aGradientxTextFrame = getProperty<awt::Gradient>(xTextFrame, "FillTransparenceGradient");
117 2 : CPPUNIT_ASSERT_EQUAL(css::awt::GradientStyle_LINEAR, aGradientxTextFrame.Style);
118 : //Frame 8
119 2 : xTextFrame = getShape(8);
120 2 : CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_HATCH, getProperty<drawing::FillStyle>(xTextFrame, "FillStyle"));
121 2 : CPPUNIT_ASSERT_EQUAL(OUString("Black 0 Degrees"), getProperty<OUString>(xTextFrame, "FillHatchName"));
122 2 : CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(xTextFrame, "FillBackground"));
123 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xTextFrame, "FillTransparence"));
124 : //Frame 9
125 2 : xTextFrame = getShape(9);
126 2 : CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_HATCH, getProperty<drawing::FillStyle>(xTextFrame, "FillStyle"));
127 2 : CPPUNIT_ASSERT_EQUAL(OUString("Black 0 Degrees"), getProperty<OUString>(xTextFrame, "FillHatchName"));
128 2 : CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xTextFrame, "FillBackground"));
129 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xTextFrame, "FillTransparence"));
130 : //Frame 10
131 2 : xTextFrame = getShape(10);
132 2 : CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_HATCH, getProperty<drawing::FillStyle>(xTextFrame, "FillStyle"));
133 2 : CPPUNIT_ASSERT_EQUAL(OUString("Black 0 Degrees"), getProperty<OUString>(xTextFrame, "FillHatchName"));
134 2 : CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(xTextFrame, "FillBackground"));
135 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(45), getProperty<sal_Int32>(xTextFrame, "FillTransparence"));
136 : //Frame 11
137 2 : xTextFrame = getShape(11);
138 2 : CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_HATCH, getProperty<drawing::FillStyle>(xTextFrame, "FillStyle"));
139 2 : CPPUNIT_ASSERT_EQUAL(OUString("Black 0 Degrees"), getProperty<OUString>(xTextFrame, "FillHatchName"));
140 2 : CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xTextFrame, "FillBackground"));
141 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(45), getProperty<sal_Int32>(xTextFrame, "FillTransparence"));
142 : //Frame 12
143 2 : xTextFrame = getShape(12);
144 2 : CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_HATCH, getProperty<drawing::FillStyle>(xTextFrame, "FillStyle"));
145 2 : CPPUNIT_ASSERT_EQUAL(OUString("Black 0 Degrees"), getProperty<OUString>(xTextFrame, "FillHatchName"));
146 2 : CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(xTextFrame, "FillBackground"));
147 2 : aGradientxTextFrame = getProperty<awt::Gradient>(xTextFrame, "FillTransparenceGradient");
148 2 : CPPUNIT_ASSERT_EQUAL(css::awt::GradientStyle_LINEAR, aGradientxTextFrame.Style);
149 : //Frame 13
150 2 : xTextFrame = getShape(13);
151 2 : CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_HATCH, getProperty<drawing::FillStyle>(xTextFrame, "FillStyle"));
152 2 : CPPUNIT_ASSERT_EQUAL(OUString("Black 0 Degrees"), getProperty<OUString>(xTextFrame, "FillHatchName"));
153 2 : CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xTextFrame, "FillBackground"));
154 2 : aGradientxTextFrame = getProperty<awt::Gradient>(xTextFrame, "FillTransparenceGradient");
155 2 : CPPUNIT_ASSERT_EQUAL(css::awt::GradientStyle_LINEAR, aGradientxTextFrame.Style);
156 : //Frame 14
157 2 : xTextFrame = getShape(14);
158 2 : CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_BITMAP, getProperty<drawing::FillStyle>(xTextFrame, "FillStyle"));
159 2 : CPPUNIT_ASSERT_EQUAL(OUString("Sky"), getProperty<OUString>(xTextFrame, "FillBitmapName"));
160 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xTextFrame, "FillTransparence"));
161 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xTextFrame, "FillBitmapPositionOffsetX"));
162 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xTextFrame, "FillBitmapPositionOffsetY"));
163 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xTextFrame, "FillBitmapOffsetX"));
164 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xTextFrame, "FillBitmapOffsetY"));
165 2 : CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xTextFrame, "FillBitmapTile"));
166 : //Frame 15
167 2 : xTextFrame = getShape(15);
168 2 : CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_BITMAP, getProperty<drawing::FillStyle>(xTextFrame, "FillStyle"));
169 2 : CPPUNIT_ASSERT_EQUAL(OUString("Sky"), getProperty<OUString>(xTextFrame, "FillBitmapName"));
170 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(45), getProperty<sal_Int32>(xTextFrame, "FillTransparence"));
171 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xTextFrame, "FillBitmapPositionOffsetX"));
172 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xTextFrame, "FillBitmapPositionOffsetY"));
173 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xTextFrame, "FillBitmapOffsetX"));
174 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xTextFrame, "FillBitmapOffsetY"));
175 2 : CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xTextFrame, "FillBitmapTile"));
176 : //Frame 16
177 2 : xTextFrame = getShape(16);
178 2 : CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_BITMAP, getProperty<drawing::FillStyle>(xTextFrame, "FillStyle"));
179 2 : CPPUNIT_ASSERT_EQUAL(OUString("Sky"), getProperty<OUString>(xTextFrame, "FillBitmapName"));
180 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xTextFrame, "FillBitmapPositionOffsetX"));
181 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xTextFrame, "FillBitmapPositionOffsetY"));
182 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xTextFrame, "FillBitmapOffsetX"));
183 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xTextFrame, "FillBitmapOffsetY"));
184 2 : CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xTextFrame, "FillBitmapTile"));
185 2 : aGradientxTextFrame = getProperty<awt::Gradient>(xTextFrame, "FillTransparenceGradient");
186 2 : CPPUNIT_ASSERT_EQUAL(css::awt::GradientStyle_LINEAR, aGradientxTextFrame.Style);
187 :
188 2 : if (xmlDocPtr pXmlDoc = parseExport("content.xml"))
189 : {
190 : // check that there are 3 background-image elements
191 1 : assertXPath(pXmlDoc, "//style:style[@style:parent-style-name='Frame' and @style:family='graphic']/style:graphic-properties[@draw:fill='bitmap']/style:background-image[@style:repeat='stretch']", 3);
192 : // tdf#90640: check that one of them is 55% opaque
193 1 : assertXPath(pXmlDoc, "//style:style[@style:parent-style-name='Frame' and @style:family='graphic']/style:graphic-properties[@draw:fill='bitmap' and @fo:background-color='transparent' and @draw:opacity='55%']/style:background-image[@style:repeat='stretch' and @draw:opacity='55%']", 1);
194 : // tdf#90640: check that one of them is 43% opaque
195 : // (emulated - hopefully not with rounding errors)
196 1 : assertXPath(pXmlDoc, "//style:style[@style:parent-style-name='Frame' and @style:family='graphic']/style:graphic-properties[@draw:fill='bitmap' and @fo:background-color='transparent' and @draw:opacity-name='Transparency_20_1']/style:background-image[@style:repeat='stretch' and @draw:opacity='43%']", 1);
197 2 : }
198 2 : }
199 :
200 17 : DECLARE_ODFEXPORT_TEST(testFdo38244, "fdo38244.odt")
201 : {
202 : // See ooxmlexport's testFdo38244().
203 :
204 : // Test comment range feature.
205 2 : uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
206 4 : uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY);
207 4 : uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
208 4 : uno::Reference<container::XEnumerationAccess> xRunEnumAccess(xParaEnum->nextElement(), uno::UNO_QUERY);
209 4 : uno::Reference<container::XEnumeration> xRunEnum = xRunEnumAccess->createEnumeration();
210 2 : xRunEnum->nextElement();
211 4 : uno::Reference<beans::XPropertySet> xPropertySet(xRunEnum->nextElement(), uno::UNO_QUERY);
212 2 : CPPUNIT_ASSERT_EQUAL(OUString("Annotation"), getProperty<OUString>(xPropertySet, "TextPortionType"));
213 2 : xRunEnum->nextElement();
214 2 : xPropertySet.set(xRunEnum->nextElement(), uno::UNO_QUERY);
215 2 : CPPUNIT_ASSERT_EQUAL(OUString("AnnotationEnd"), getProperty<OUString>(xPropertySet, "TextPortionType"));
216 :
217 : // Test properties
218 4 : uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
219 4 : uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
220 4 : uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
221 2 : xPropertySet.set(xFields->nextElement(), uno::UNO_QUERY);
222 2 : CPPUNIT_ASSERT_EQUAL(OUString("__Fieldmark__4_1833023242"), getProperty<OUString>(xPropertySet, "Name"));
223 4 : CPPUNIT_ASSERT_EQUAL(OUString("M"), getProperty<OUString>(xPropertySet, "Initials"));
224 2 : }
225 :
226 17 : DECLARE_ODFEXPORT_TEST(testFdo79358, "fdo79358.odt")
227 : {
228 : // the boolean properties of the index were not exported properly
229 2 : uno::Reference<text::XDocumentIndexesSupplier> xIndexSupplier(mxComponent, uno::UNO_QUERY);
230 4 : uno::Reference<container::XIndexAccess> xIndexes(xIndexSupplier->getDocumentIndexes(), uno::UNO_QUERY);
231 4 : uno::Reference<text::XDocumentIndex> xTOCIndex(xIndexes->getByIndex(0), uno::UNO_QUERY);
232 4 : uno::Reference<beans::XPropertySet> xTOCProps(xTOCIndex, uno::UNO_QUERY);
233 2 : CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(xTOCProps, "CreateFromOutline"));
234 2 : CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(xTOCProps, "CreateFromMarks"));
235 2 : CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xTOCProps, "CreateFromLevelParagraphStyles"));
236 : // check that the source styles are preserved too while at it
237 : uno::Reference<container::XIndexReplace> xLevels(
238 : getProperty< uno::Reference<container::XIndexReplace> >(xTOCProps,
239 4 : "LevelParagraphStyles"));
240 4 : uno::Sequence<OUString> seq(1);
241 2 : seq[0] = "Heading";
242 2 : CPPUNIT_ASSERT_EQUAL(uno::makeAny(seq), xLevels->getByIndex(1));
243 4 : CPPUNIT_ASSERT_EQUAL(uno::makeAny(uno::Sequence<OUString>()), xLevels->getByIndex(2));
244 2 : }
245 :
246 17 : DECLARE_ODFEXPORT_TEST(testFirstHeaderFooter, "first-header-footer.odt")
247 : {
248 : // Test import and export of the header-first token.
249 :
250 : // The document has 6 pages, two page styles for the first and second half of pages.
251 2 : CPPUNIT_ASSERT_EQUAL(OUString("First header"), parseDump("/root/page[1]/header/txt/text()"));
252 2 : CPPUNIT_ASSERT_EQUAL(OUString("First footer"), parseDump("/root/page[1]/footer/txt/text()"));
253 2 : CPPUNIT_ASSERT_EQUAL(OUString("Left header"), parseDump("/root/page[2]/header/txt/text()"));
254 2 : CPPUNIT_ASSERT_EQUAL(OUString("Left footer"), parseDump("/root/page[2]/footer/txt/text()"));
255 2 : CPPUNIT_ASSERT_EQUAL(OUString("Right header"), parseDump("/root/page[3]/header/txt/text()"));
256 2 : CPPUNIT_ASSERT_EQUAL(OUString("Right footer"), parseDump("/root/page[3]/footer/txt/text()"));
257 2 : CPPUNIT_ASSERT_EQUAL(OUString("First header2"), parseDump("/root/page[4]/header/txt/text()"));
258 2 : CPPUNIT_ASSERT_EQUAL(OUString("First footer2"), parseDump("/root/page[4]/footer/txt/text()"));
259 2 : CPPUNIT_ASSERT_EQUAL(OUString("Right header2"), parseDump("/root/page[5]/header/txt/text()"));
260 2 : CPPUNIT_ASSERT_EQUAL(OUString("Right footer2"), parseDump("/root/page[5]/footer/txt/text()"));
261 2 : CPPUNIT_ASSERT_EQUAL(OUString("Left header2"), parseDump("/root/page[6]/header/txt/text()"));
262 2 : CPPUNIT_ASSERT_EQUAL(OUString("Left footer2"), parseDump("/root/page[6]/footer/txt/text()"));
263 2 : }
264 :
265 17 : DECLARE_ODFEXPORT_TEST(testTextframeGradient, "textframe-gradient.odt")
266 : {
267 2 : uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY);
268 4 : uno::Reference<container::XIndexAccess> xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY);
269 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess->getCount());
270 :
271 4 : uno::Reference<beans::XPropertySet> xFrame(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
272 2 : CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_GRADIENT, getProperty<drawing::FillStyle>(xFrame, "FillStyle"));
273 2 : awt::Gradient aGradient = getProperty<awt::Gradient>(xFrame, "FillGradient");
274 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0xC0504D), aGradient.StartColor);
275 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0xD99594), aGradient.EndColor);
276 2 : CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_AXIAL, aGradient.Style);
277 :
278 2 : xFrame.set(xIndexAccess->getByIndex(1), uno::UNO_QUERY);
279 2 : CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_GRADIENT, getProperty<drawing::FillStyle>(xFrame, "FillStyle"));
280 2 : aGradient = getProperty<awt::Gradient>(xFrame, "FillGradient");
281 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0x000000), aGradient.StartColor);
282 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0x666666), aGradient.EndColor);
283 4 : CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_AXIAL, aGradient.Style);
284 2 : }
285 :
286 17 : DECLARE_ODFEXPORT_TEST(testFdo60769, "fdo60769.odt")
287 : {
288 : // Test multi-paragraph comment range feature.
289 2 : uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
290 4 : uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY);
291 4 : uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
292 4 : uno::Reference<container::XEnumerationAccess> xRunEnumAccess(xParaEnum->nextElement(), uno::UNO_QUERY);
293 4 : uno::Reference<container::XEnumeration> xRunEnum = xRunEnumAccess->createEnumeration();
294 16 : while (xRunEnum->hasMoreElements())
295 : {
296 12 : uno::Reference<beans::XPropertySet> xPropertySet(xRunEnum->nextElement(), uno::UNO_QUERY);
297 24 : OUString aType = getProperty<OUString>(xPropertySet, "TextPortionType");
298 : // First paragraph: no field end, no anchor
299 12 : CPPUNIT_ASSERT(aType == "Text" || aType == "Annotation");
300 12 : }
301 :
302 2 : xRunEnumAccess.set(xParaEnum->nextElement(), uno::UNO_QUERY);
303 4 : while (xRunEnum->hasMoreElements())
304 : {
305 0 : uno::Reference<beans::XPropertySet> xPropertySet(xRunEnum->nextElement(), uno::UNO_QUERY);
306 0 : OUString aType = getProperty<OUString>(xPropertySet, "TextPortionType");
307 : // Second paragraph: no field start
308 0 : CPPUNIT_ASSERT(aType == "Text" || aType == "AnnotationEnd");
309 2 : }
310 2 : }
311 :
312 16 : DECLARE_ODFEXPORT_TEST(testFdo58949, "fdo58949.docx")
313 : {
314 : /*
315 : * The problem was that the exporter didn't insert "Obj102" to the
316 : * resulting zip file. No idea how to check for "broken" (missing OLE data
317 : * and replacement image) OLE objects using UNO, so we'll check the zip file directly.
318 : */
319 :
320 1 : utl::TempFile aTempFile;
321 1 : save("writer8", aTempFile);
322 :
323 2 : uno::Sequence<uno::Any> aArgs(1);
324 1 : aArgs[0] <<= OUString(aTempFile.GetURL());
325 2 : uno::Reference<container::XNameAccess> xNameAccess(m_xSFactory->createInstanceWithArguments("com.sun.star.packages.zip.ZipFileAccess", aArgs), uno::UNO_QUERY);
326 2 : CPPUNIT_ASSERT_EQUAL(true, bool(xNameAccess->hasByName("Obj102")));
327 1 : }
328 :
329 17 : DECLARE_ODFEXPORT_TEST(testCharacterBorder, "charborder.odt")
330 : {
331 : // Make sure paragraph and character attributes don't interfere
332 : // First paragraph has a paragraph border and a character border included by the paragraph style
333 :
334 : // Paragraph border of first paragraph
335 : {
336 2 : const table::BorderLine2 aFirstParTopBorder(0x6666FF,2,26,26,7,55);
337 2 : const sal_Int32 aFirstParTopPadding(150);
338 2 : uno::Reference<beans::XPropertySet> xSet(getParagraph(1), uno::UNO_QUERY);
339 :
340 : // Top border
341 2 : CPPUNIT_ASSERT_BORDER_EQUAL(aFirstParTopBorder, getProperty<table::BorderLine2>(xSet,"TopBorder"));
342 2 : CPPUNIT_ASSERT_EQUAL(aFirstParTopPadding, getProperty<sal_Int32>(xSet,"TopBorderDistance"));
343 :
344 : // Bottom border (same as top border)
345 2 : CPPUNIT_ASSERT_BORDER_EQUAL(aFirstParTopBorder, getProperty<table::BorderLine2>(xSet,"BottomBorder"));
346 2 : CPPUNIT_ASSERT_EQUAL(aFirstParTopPadding, getProperty<sal_Int32>(xSet,"BottomBorderDistance"));
347 :
348 : // Left border (same as top border)
349 2 : CPPUNIT_ASSERT_BORDER_EQUAL(aFirstParTopBorder, getProperty<table::BorderLine2>(xSet,"LeftBorder"));
350 2 : CPPUNIT_ASSERT_EQUAL(aFirstParTopPadding, getProperty<sal_Int32>(xSet,"LeftBorderDistance"));
351 :
352 : // Right border (same as top border)
353 2 : CPPUNIT_ASSERT_BORDER_EQUAL(aFirstParTopBorder, getProperty<table::BorderLine2>(xSet,"RightBorder"));
354 2 : CPPUNIT_ASSERT_EQUAL(aFirstParTopPadding, getProperty<sal_Int32>(xSet,"RightBorderDistance"));
355 :
356 : // Shadow
357 2 : const table::ShadowFormat aShadow = getProperty<table::ShadowFormat>(xSet,"ParaShadowFormat");
358 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aShadow.Color);
359 2 : CPPUNIT_ASSERT_EQUAL(false, (bool)aShadow.IsTransparent);
360 2 : CPPUNIT_ASSERT_EQUAL(table::ShadowLocation(0), aShadow.Location);
361 2 : CPPUNIT_ASSERT_EQUAL(sal_Int16(0), aShadow.ShadowWidth);
362 : }
363 :
364 : // Character border for first paragraph
365 : {
366 2 : const table::BorderLine2 aFirstParCharTopBorder(0xFF3333,0,37,0,2,37);
367 2 : const sal_Int32 aFirstParCharTopPadding(450);
368 2 : uno::Reference<beans::XPropertySet> xSet(getParagraph(1), uno::UNO_QUERY);
369 :
370 : // Top border
371 2 : CPPUNIT_ASSERT_BORDER_EQUAL(aFirstParCharTopBorder, getProperty<table::BorderLine2>(xSet,"CharTopBorder"));
372 2 : CPPUNIT_ASSERT_EQUAL(aFirstParCharTopPadding, getProperty<sal_Int32>(xSet,"CharTopBorderDistance"));
373 :
374 : // Bottom border (same as top border)
375 2 : CPPUNIT_ASSERT_BORDER_EQUAL(aFirstParCharTopBorder, getProperty<table::BorderLine2>(xSet,"CharBottomBorder"));
376 2 : CPPUNIT_ASSERT_EQUAL(aFirstParCharTopPadding, getProperty<sal_Int32>(xSet,"CharBottomBorderDistance"));
377 :
378 : // Left border (same as top border)
379 2 : CPPUNIT_ASSERT_BORDER_EQUAL(aFirstParCharTopBorder, getProperty<table::BorderLine2>(xSet,"CharLeftBorder"));
380 2 : CPPUNIT_ASSERT_EQUAL(aFirstParCharTopPadding, getProperty<sal_Int32>(xSet,"CharLeftBorderDistance"));
381 :
382 : // Right border (same as top border)
383 2 : CPPUNIT_ASSERT_BORDER_EQUAL(aFirstParCharTopBorder, getProperty<table::BorderLine2>(xSet,"CharRightBorder"));
384 2 : CPPUNIT_ASSERT_EQUAL(aFirstParCharTopPadding, getProperty<sal_Int32>(xSet,"CharRightBorderDistance"));
385 :
386 : // Shadow
387 2 : const table::ShadowFormat aShadow = getProperty<table::ShadowFormat>(xSet,"CharShadowFormat");
388 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0xFF3333), aShadow.Color);
389 2 : CPPUNIT_ASSERT_EQUAL(false, (bool)aShadow.IsTransparent);
390 2 : CPPUNIT_ASSERT_EQUAL(table::ShadowLocation(2), aShadow.Location);
391 2 : CPPUNIT_ASSERT_EQUAL(sal_Int16(280), aShadow.ShadowWidth);
392 :
393 : // Check autostyle
394 : {
395 2 : uno::Reference< style::XAutoStyleFamily > xAutoStyleFamily(getAutoStyles("ParagraphStyles"));
396 4 : uno::Reference < container::XEnumeration > xAutoStylesEnum( xAutoStyleFamily->createEnumeration() );
397 2 : CPPUNIT_ASSERT_EQUAL(true, (bool)xAutoStylesEnum->hasMoreElements());
398 :
399 : // First paragraph autostyle
400 4 : uno::Reference < beans::XPropertySet > xPSet( xAutoStylesEnum->nextElement(), uno::UNO_QUERY );
401 :
402 : // Top border
403 2 : CPPUNIT_ASSERT_BORDER_EQUAL(aFirstParCharTopBorder, getProperty<table::BorderLine2>(xSet,"CharTopBorder"));
404 2 : CPPUNIT_ASSERT_EQUAL(aFirstParCharTopPadding, getProperty<sal_Int32>(xSet,"CharTopBorderDistance"));
405 :
406 : // Bottom border
407 2 : CPPUNIT_ASSERT_BORDER_EQUAL(aFirstParCharTopBorder, getProperty<table::BorderLine2>(xSet,"CharBottomBorder"));
408 2 : CPPUNIT_ASSERT_EQUAL(aFirstParCharTopPadding, getProperty<sal_Int32>(xSet,"CharBottomBorderDistance"));
409 :
410 : // Left border
411 2 : CPPUNIT_ASSERT_BORDER_EQUAL(aFirstParCharTopBorder, getProperty<table::BorderLine2>(xSet,"CharLeftBorder"));
412 2 : CPPUNIT_ASSERT_EQUAL(aFirstParCharTopPadding, getProperty<sal_Int32>(xSet,"CharLeftBorderDistance"));
413 :
414 : // Right border
415 2 : CPPUNIT_ASSERT_BORDER_EQUAL(aFirstParCharTopBorder, getProperty<table::BorderLine2>(xSet,"CharRightBorder"));
416 4 : CPPUNIT_ASSERT_EQUAL(aFirstParCharTopPadding, getProperty<sal_Int32>(xSet,"CharRightBorderDistance"));
417 2 : }
418 : }
419 :
420 : // Second paragraph's second text portion has a character style named CharDiffBor
421 : // This style includes border with different sides
422 : {
423 :
424 : table::BorderLine2 aBorderArray[4] =
425 : {
426 : table::BorderLine2(0xFF3333,0,37,0,14,37), // Top (fine dashed line)
427 : table::BorderLine2(0x99FF66,26,26,53,11,106), // Bottom
428 : table::BorderLine2(0x6666FF,9,26,9,12,71), // Left
429 : table::BorderLine2(0,0,0,0,0,0) // Right
430 2 : };
431 :
432 2 : sal_Int32 aDistances[4] = { 400 /*Top*/, 300 /*Bottom*/, 250 /*Left*/, 0 /*Right*/ };
433 :
434 : // Get second text portion of second paragraph
435 2 : uno::Reference < beans::XPropertySet > xSet( getRun(getParagraph(2),2), uno::UNO_QUERY );
436 :
437 : // Top border
438 2 : CPPUNIT_ASSERT_BORDER_EQUAL(aBorderArray[0], getProperty<table::BorderLine2>(xSet,"CharTopBorder"));
439 2 : CPPUNIT_ASSERT_EQUAL(aDistances[0], getProperty<sal_Int32>(xSet,"CharTopBorderDistance"));
440 :
441 : // Bottom border
442 2 : CPPUNIT_ASSERT_BORDER_EQUAL(aBorderArray[1], getProperty<table::BorderLine2>(xSet,"CharBottomBorder"));
443 2 : CPPUNIT_ASSERT_EQUAL(aDistances[1], getProperty<sal_Int32>(xSet,"CharBottomBorderDistance"));
444 :
445 : // Left border
446 2 : CPPUNIT_ASSERT_BORDER_EQUAL(aBorderArray[2], getProperty<table::BorderLine2>(xSet,"CharLeftBorder"));
447 2 : CPPUNIT_ASSERT_EQUAL(aDistances[2], getProperty<sal_Int32>(xSet,"CharLeftBorderDistance"));
448 :
449 : // Right border
450 2 : CPPUNIT_ASSERT_BORDER_EQUAL(aBorderArray[3], getProperty<table::BorderLine2>(xSet,"CharRightBorder"));
451 2 : CPPUNIT_ASSERT_EQUAL(aDistances[3], getProperty<sal_Int32>(xSet,"CharRightBorderDistance"));
452 :
453 : // Shadow
454 2 : const table::ShadowFormat aShadow = getProperty<table::ShadowFormat>(xSet,"CharShadowFormat");
455 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aShadow.Color);
456 2 : CPPUNIT_ASSERT_EQUAL(false, (bool)aShadow.IsTransparent);
457 2 : CPPUNIT_ASSERT_EQUAL(table::ShadowLocation(3), aShadow.Location);
458 2 : CPPUNIT_ASSERT_EQUAL(sal_Int16(79), aShadow.ShadowWidth);
459 :
460 : // Check character style
461 : {
462 2 : uno::Reference< container::XNameAccess > xStyleFamily(getStyles("CharacterStyles"), uno::UNO_QUERY);
463 4 : uno::Reference < beans::XPropertySet > xStyleSet(xStyleFamily->getByName("CharDiffBor"), uno::UNO_QUERY);
464 :
465 : // Top border
466 2 : CPPUNIT_ASSERT_BORDER_EQUAL(aBorderArray[0], getProperty<table::BorderLine2>(xSet,"CharTopBorder"));
467 2 : CPPUNIT_ASSERT_EQUAL(aDistances[0], getProperty<sal_Int32>(xSet,"CharTopBorderDistance"));
468 :
469 : // Bottom border
470 2 : CPPUNIT_ASSERT_BORDER_EQUAL(aBorderArray[1], getProperty<table::BorderLine2>(xSet,"CharBottomBorder"));
471 2 : CPPUNIT_ASSERT_EQUAL(aDistances[1], getProperty<sal_Int32>(xSet,"CharBottomBorderDistance"));
472 :
473 : // Left border
474 2 : CPPUNIT_ASSERT_BORDER_EQUAL(aBorderArray[2], getProperty<table::BorderLine2>(xSet,"CharLeftBorder"));
475 2 : CPPUNIT_ASSERT_EQUAL(aDistances[2], getProperty<sal_Int32>(xSet,"CharLeftBorderDistance"));
476 :
477 : // Right border
478 2 : CPPUNIT_ASSERT_BORDER_EQUAL(aBorderArray[3], getProperty<table::BorderLine2>(xSet,"CharRightBorder"));
479 4 : CPPUNIT_ASSERT_EQUAL(aDistances[3], getProperty<sal_Int32>(xSet,"CharRightBorderDistance"));
480 2 : }
481 : }
482 2 : }
483 :
484 17 : DECLARE_ODFEXPORT_TEST(testFdo43807, "fdo43807.odt")
485 : {
486 2 : uno::Reference<beans::XPropertySet> xSet(getParagraph(1), uno::UNO_QUERY);
487 2 : CPPUNIT_ASSERT_EQUAL(OUString("Drop Caps"),getProperty<OUString>(xSet,"DropCapCharStyleName"));
488 :
489 2 : xSet = uno::Reference<beans::XPropertySet>(getParagraph(2), uno::UNO_QUERY);
490 2 : CPPUNIT_ASSERT_EQUAL(OUString("User Defined Drop Caps"),getProperty<OUString>(xSet,"DropCapCharStyleName"));
491 2 : }
492 :
493 17 : DECLARE_ODFEXPORT_TEST(testTextframeTransparentShadow, "textframe-transparent-shadow.odt")
494 : {
495 2 : uno::Reference<drawing::XShape> xPicture = getShape(1);
496 : // ODF stores opacity of 75%, that means 25% transparency.
497 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(25), getProperty<sal_Int32>(xPicture, "ShadowTransparence"));
498 2 : }
499 :
500 17 : DECLARE_ODFEXPORT_TEST(testRelhPage, "relh-page.odt")
501 : {
502 2 : uno::Reference<drawing::XShape> xTextFrame = getShape(1);
503 : // This was text::RelOrientation::FRAME (the default), RelativeHeightRelation was not handled in xmloff.
504 2 : CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, getProperty<sal_Int16>(xTextFrame, "RelativeHeightRelation"));
505 : // Make sure rel-height-rel doesn't affect width.
506 2 : CPPUNIT_ASSERT_EQUAL(text::RelOrientation::FRAME, getProperty<sal_Int16>(xTextFrame, "RelativeWidthRelation"));
507 :
508 : // This was 2601, 20% height was relative from margin, not page.
509 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(3168), parseDump("/root/page/body/txt/anchored/fly/infos/bounds", "height").toInt32());
510 2 : }
511 :
512 17 : DECLARE_ODFEXPORT_TEST(testRelwPage, "relw-page.odt")
513 : {
514 2 : uno::Reference<drawing::XShape> xTextFrame = getShape(1);
515 : // This was text::RelOrientation::FRAME (the default), RelativeWidthRelation was not handled in xmloff.
516 2 : CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, getProperty<sal_Int16>(xTextFrame, "RelativeWidthRelation"));
517 : // Make sure rel-width-rel doesn't affect height.
518 2 : CPPUNIT_ASSERT_EQUAL(text::RelOrientation::FRAME, getProperty<sal_Int16>(xTextFrame, "RelativeHeightRelation"));
519 :
520 : // This was 3762, 40% width was relative from margin, not page.
521 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(4896), parseDump("/root/page/body/txt/anchored/fly/infos/bounds", "width").toInt32());
522 2 : }
523 :
524 17 : DECLARE_ODFEXPORT_TEST(testTextFrameVertAdjust, "textframe-vertadjust.odt")
525 : {
526 : // Test import/export of new frame attribute called TextVerticalAdjust
527 :
528 : // 1st frame's context is adjusted to the top
529 2 : uno::Reference<beans::XPropertySet> xFrame(getTextFrameByName("Rectangle 1"), uno::UNO_QUERY);
530 2 : CPPUNIT_ASSERT_EQUAL(drawing::TextVerticalAdjust_TOP, getProperty<drawing::TextVerticalAdjust>(xFrame, "TextVerticalAdjust"));
531 : // 2nd frame's context is adjusted to the center
532 2 : xFrame.set(getTextFrameByName("Rectangle 2"), uno::UNO_QUERY);
533 2 : CPPUNIT_ASSERT_EQUAL(drawing::TextVerticalAdjust_CENTER, getProperty<drawing::TextVerticalAdjust>(xFrame, "TextVerticalAdjust"));
534 : // 3rd frame's context is adjusted to the bottom
535 2 : xFrame.set(getTextFrameByName("Rectangle 3"), uno::UNO_QUERY);
536 2 : CPPUNIT_ASSERT_EQUAL(drawing::TextVerticalAdjust_BOTTOM, getProperty<drawing::TextVerticalAdjust>(xFrame, "TextVerticalAdjust"));
537 2 : }
538 :
539 17 : DECLARE_ODFEXPORT_TEST(testShapeRelsize, "shape-relsize.odt")
540 : {
541 2 : uno::Reference<drawing::XShape> xShape = getShape(1);
542 : // These were all 0, as style:rel-width/height was ignored on import for shapes.
543 2 : CPPUNIT_ASSERT_EQUAL(sal_Int16(40), getProperty<sal_Int16>(xShape, "RelativeWidth"));
544 2 : CPPUNIT_ASSERT_EQUAL(sal_Int16(20), getProperty<sal_Int16>(xShape, "RelativeHeight"));
545 :
546 : // Relation was "page" for both width and height, should be "paragraph" for width.
547 2 : CPPUNIT_ASSERT_EQUAL(text::RelOrientation::FRAME, getProperty<sal_Int16>(xShape, "RelativeWidthRelation"));
548 : // And make sure that height stays "page".
549 2 : CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, getProperty<sal_Int16>(xShape, "RelativeHeightRelation"));
550 2 : }
551 :
552 17 : DECLARE_ODFEXPORT_TEST(testTextboxRoundedCorners, "textbox-rounded-corners.odt")
553 : {
554 2 : uno::Reference<drawing::XShape> xShape = getShape(1);
555 4 : comphelper::SequenceAsHashMap aCustomShapeGeometry = comphelper::SequenceAsHashMap(getProperty< uno::Sequence<beans::PropertyValue> >(xShape, "CustomShapeGeometry"));
556 :
557 : // Test that the shape is a rounded rectangle.
558 2 : CPPUNIT_ASSERT_EQUAL(OUString("round-rectangle"), aCustomShapeGeometry["Type"].get<OUString>());
559 :
560 : // The shape text should start with a table, with "a" in its A1 cell.
561 4 : uno::Reference<text::XText> xText = uno::Reference<text::XTextRange>(xShape, uno::UNO_QUERY)->getText();
562 4 : uno::Reference<text::XTextTable> xTable(getParagraphOrTable(1, xText), uno::UNO_QUERY);
563 4 : uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY);
564 2 : CPPUNIT_ASSERT_EQUAL(OUString("a"), xCell->getString());
565 :
566 : // Table inside a textbox should be in the extension namespace.
567 2 : if (xmlDocPtr pXmlDoc = parseExport("content.xml"))
568 : // This failed, as draw:custom-shape had a table:table child.
569 3 : assertXPath(pXmlDoc, "//draw:custom-shape/loext:table", "name", "Table1");
570 2 : }
571 :
572 17 : DECLARE_ODFEXPORT_TEST(testFdo86963, "fdo86963.odt")
573 : {
574 : // Export of this document failed with beans::UnknownPropertyException.
575 2 : uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
576 4 : uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
577 4 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xDrawPage->getCount());
578 2 : }
579 :
580 17 : DECLARE_ODFEXPORT_TEST(testGerrit13858, "gerrit13858.odt")
581 : {
582 : // Just make sure the output is valid.
583 2 : }
584 :
585 : #endif
586 :
587 4 : CPPUNIT_PLUGIN_IMPLEMENT();
588 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|