1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <swmodeltestbase.hxx>
12 #include <config_features.h>
14 #include <com/sun/star/awt/XTextComponent.hpp>
15 #include <com/sun/star/awt/XControl.hpp>
16 #include <com/sun/star/awt/XControlModel.hpp>
17 #include <com/sun/star/awt/XWindowPeer.hpp>
18 #include <com/sun/star/awt/FontWeight.hpp>
19 #include <com/sun/star/drawing/FillStyle.hpp>
20 #include <com/sun/star/drawing/BitmapMode.hpp>
21 #include <com/sun/star/form/XForm.hpp>
22 #include <com/sun/star/form/XFormsSupplier.hpp>
23 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
24 #include <com/sun/star/style/PageStyleLayout.hpp>
25 #include <com/sun/star/style/FootnoteLineStyle.hpp>
26 #include <com/sun/star/table/BorderLine.hpp>
27 #include <com/sun/star/text/XTextField.hpp>
28 #include <com/sun/star/text/XTextSection.hpp>
29 #include <com/sun/star/text/XTextTable.hpp>
30 #include <com/sun/star/text/PageNumberType.hpp>
31 #include <com/sun/star/text/VertOrientation.hpp>
32 #include <com/sun/star/view/XControlAccess.hpp>
33 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
34 #include <com/sun/star/lang/Locale.hpp>
35 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
36 #include <com/sun/star/util/XRefreshable.hpp>
37 #include <com/sun/star/text/XTextDocument.hpp>
38 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
39 #include <com/sun/star/container/XIndexContainer.hpp>
40 #include <com/sun/star/drawing/XDrawPage.hpp>
41 #include <com/sun/star/text/XTextFramesSupplier.hpp>
42 #include <com/sun/star/document/XDocumentInsertable.hpp>
43 #include <com/sun/star/style/ParagraphAdjust.hpp>
44 #include <com/sun/star/document/MacroExecMode.hpp>
46 #include <comphelper/propertysequence.hxx>
47 #include <comphelper/propertyvalue.hxx>
48 #include <editeng/boxitem.hxx>
49 #include <vcl/scheduler.hxx>
51 #include <IDocumentSettingAccess.hxx>
54 #include <swdtflvr.hxx>
58 #include <hintids.hxx>
60 #include <unotxdoc.hxx>
64 #include <officecfg/Office/Common.hxx>
65 #include <unotools/securityoptions.hxx>
66 #include <systools/win32/comtools.hxx>
70 typedef std::map
<OUString
, css::uno::Sequence
< css::table::BorderLine
> > AllBordersMap
;
71 typedef std::pair
<OUString
, css::uno::Sequence
< css::table::BorderLine
> > StringSequencePair
;
73 class Test
: public SwModelTestBase
76 Test() : SwModelTestBase("/sw/qa/extras/odfimport/data/", "writer8") {}
79 CPPUNIT_TEST_FIXTURE(Test
, testEmptySvgFamilyName
)
81 createSwDoc("empty-svg-family-name.odt");
82 // .odt import did crash on the empty font list (which I think is valid according SVG spec)
85 CPPUNIT_TEST_FIXTURE(Test
, testHideAllSections
)
87 createSwDoc("fdo53210.odt");
88 // This document has a section that is conditionally hidden, but has no empty paragraph after it.
89 uno::Reference
<text::XTextFieldsSupplier
> xTextFieldsSupplier(mxComponent
, uno::UNO_QUERY
);
90 uno::Reference
<container::XNameAccess
> xMasters
= xTextFieldsSupplier
->getTextFieldMasters();
91 // Set _CS_Allgemein to 0
92 uno::Reference
<beans::XPropertySet
> xMaster(xMasters
->getByName("com.sun.star.text.fieldmaster.User._CS_Allgemein"), uno::UNO_QUERY
);
93 xMaster
->setPropertyValue("Content", uno::Any(OUString("0")));
95 uno::Reference
<util::XRefreshable
>(xTextFieldsSupplier
->getTextFields(), uno::UNO_QUERY_THROW
)->refresh();
98 CPPUNIT_TEST_FIXTURE(Test
, testOdtBorders
)
100 createSwDoc("borders_ooo33.odt");
103 map
.insert(StringSequencePair(OUString("B2"), { table::BorderLine(0, 2, 2, 35), // left
104 table::BorderLine(0, 2, 2, 35), // right
105 table::BorderLine(0, 2, 2, 35), // top
106 table::BorderLine(0, 2, 2, 35) })); // bottom
108 map
.insert(StringSequencePair(OUString("D2"), { table::BorderLine(0, 0, 2, 0),
109 table::BorderLine(0, 0, 2, 0),
110 table::BorderLine(0, 0, 2, 0),
111 table::BorderLine(0, 0, 2, 0) }));
113 map
.insert(StringSequencePair(OUString("B4"), { table::BorderLine(0, 2, 2, 88),
114 table::BorderLine(0, 2, 2, 88),
115 table::BorderLine(0, 2, 2, 88),
116 table::BorderLine(0, 2, 2, 88) }));
118 map
.insert(StringSequencePair(OUString("D4"), { table::BorderLine(0, 0, 18, 0),
119 table::BorderLine(0, 0, 18, 0),
120 table::BorderLine(0, 0, 18, 0),
121 table::BorderLine(0, 0, 18, 0) }));
123 map
.insert(StringSequencePair(OUString("B6"), { table::BorderLine(0, 35, 35, 35),
124 table::BorderLine(0, 35, 35, 35),
125 table::BorderLine(0, 35, 35, 35),
126 table::BorderLine(0, 35, 35, 35) }));
128 map
.insert(StringSequencePair(OUString("D6"), { table::BorderLine(0, 0, 35, 0),
129 table::BorderLine(0, 0, 35, 0),
130 table::BorderLine(0, 0, 35, 0),
131 table::BorderLine(0, 0, 35, 0) }));
133 map
.insert(StringSequencePair(OUString("B8"), { table::BorderLine(0, 88, 88, 88),
134 table::BorderLine(0, 88, 88, 88),
135 table::BorderLine(0, 88, 88, 88),
136 table::BorderLine(0, 88, 88, 88) }));
138 map
.insert(StringSequencePair(OUString("D8"), { table::BorderLine(0, 0, 88, 0),
139 table::BorderLine(0, 0, 88, 0),
140 table::BorderLine(0, 0, 88, 0),
141 table::BorderLine(0, 0, 88, 0) }));
143 map
.insert(StringSequencePair(OUString("B10"), { table::BorderLine(0, 2, 35, 88),
144 table::BorderLine(0, 2, 35, 88),
145 table::BorderLine(0, 2, 35, 88),
146 table::BorderLine(0, 2, 35, 88) }));
148 map
.insert(StringSequencePair(OUString("D10"), { table::BorderLine(0, 0, 141, 0),
149 table::BorderLine(0, 0, 141, 0),
150 table::BorderLine(0, 0, 141, 0),
151 table::BorderLine(0, 0, 141, 0) }));
153 map
.insert(StringSequencePair(OUString("B12"), { table::BorderLine(0, 2, 88, 88),
154 table::BorderLine(0, 2, 88, 88),
155 table::BorderLine(0, 2, 88, 88),
156 table::BorderLine(0, 2, 88, 88) }));
158 map
.insert(StringSequencePair(OUString("D12"), { table::BorderLine(0, 0, 176, 0),
159 table::BorderLine(0, 0, 176, 0),
160 table::BorderLine(0, 0, 176, 0),
161 table::BorderLine(0, 0, 176, 0) }));
163 map
.insert(StringSequencePair(OUString("B14"), { table::BorderLine(0, 2, 141, 88),
164 table::BorderLine(0, 2, 141, 88),
165 table::BorderLine(0, 2, 141, 88),
166 table::BorderLine(0, 2, 141, 88) }));
168 map
.insert(StringSequencePair(OUString("B16"), { table::BorderLine(0, 35, 88, 88),
169 table::BorderLine(0, 35, 88, 88),
170 table::BorderLine(0, 35, 88, 88),
171 table::BorderLine(0, 35, 88, 88) }));
173 map
.insert(StringSequencePair(OUString("B18"), { table::BorderLine(0, 88, 35, 35),
174 table::BorderLine(0, 88, 35, 35),
175 table::BorderLine(0, 88, 35, 35),
176 table::BorderLine(0, 88, 35, 35) }));
178 map
.insert(StringSequencePair(OUString("B20"), { table::BorderLine(0, 88, 141, 88),
179 table::BorderLine(0, 88, 141, 88),
180 table::BorderLine(0, 88, 141, 88),
181 table::BorderLine(0, 88, 141, 88) }));
183 map
.insert(StringSequencePair(OUString("B22"), { table::BorderLine(0, 141, 88, 88),
184 table::BorderLine(0, 141, 88, 88),
185 table::BorderLine(0, 141, 88, 88),
186 table::BorderLine(0, 141, 88, 88) }));
188 uno::Reference
<text::XTextDocument
> textDocument(mxComponent
, uno::UNO_QUERY
);
189 uno::Reference
<container::XEnumerationAccess
> xParaEnumAccess(textDocument
->getText(), uno::UNO_QUERY
);
190 // list of paragraphs
191 uno::Reference
<container::XEnumeration
> xParaEnum
= xParaEnumAccess
->createEnumeration();
194 uno::Reference
<lang::XServiceInfo
> xServiceInfo
;
195 if (xParaEnum
->nextElement() >>= xServiceInfo
)
197 if (xServiceInfo
->supportsService("com.sun.star.text.TextTable"))
199 uno::Reference
<text::XTextTable
> const xTextTable(xServiceInfo
, uno::UNO_QUERY_THROW
);
200 uno::Sequence
<OUString
> const cells
= xTextTable
->getCellNames();
201 sal_Int32 nLength
= cells
.getLength();
203 AllBordersMap::iterator it
= map
.begin();
205 for (sal_Int32 i
= 0; i
< nLength
; ++i
)
207 if(i
%10==6 || (i
%10==8 && i
<60)) // only B and D cells have borders, every 2 rows
209 uno::Reference
<table::XCell
> xCell
= xTextTable
->getCellByName(cells
[i
]);
210 uno::Reference
< beans::XPropertySet
> xPropSet(xCell
, uno::UNO_QUERY_THROW
);
211 it
= map
.find(cells
[i
]);
213 uno::Any aLeftBorder
= xPropSet
->getPropertyValue("LeftBorder");
214 table::BorderLine aLeftBorderLine
;
215 if (aLeftBorder
>>= aLeftBorderLine
)
217 sal_Int32 innerLineWidth
= aLeftBorderLine
.InnerLineWidth
;
218 sal_Int32 outerLineWidth
= aLeftBorderLine
.OuterLineWidth
;
219 sal_Int32 lineDistance
= aLeftBorderLine
.LineDistance
;
221 sal_Int32 perfectInner
= it
->second
[0].InnerLineWidth
;
222 sal_Int32 perfectOuter
= it
->second
[0].OuterLineWidth
;
223 sal_Int32 perfectDistance
= it
->second
[0].LineDistance
;
224 CPPUNIT_ASSERT_EQUAL(perfectInner
, innerLineWidth
);
225 CPPUNIT_ASSERT_EQUAL(perfectOuter
, outerLineWidth
);
226 CPPUNIT_ASSERT_EQUAL(perfectDistance
, lineDistance
);
229 uno::Any aRightBorder
= xPropSet
->getPropertyValue("RightBorder");
230 table::BorderLine aRightBorderLine
;
231 if (aRightBorder
>>= aRightBorderLine
)
233 sal_Int32 innerLineWidth
= aRightBorderLine
.InnerLineWidth
;
234 sal_Int32 outerLineWidth
= aRightBorderLine
.OuterLineWidth
;
235 sal_Int32 lineDistance
= aRightBorderLine
.LineDistance
;
237 sal_Int32 perfectInner
= it
->second
[1].InnerLineWidth
;
238 sal_Int32 perfectOuter
= it
->second
[1].OuterLineWidth
;
239 sal_Int32 perfectDistance
= it
->second
[1].LineDistance
;
240 CPPUNIT_ASSERT_EQUAL(perfectInner
, innerLineWidth
);
241 CPPUNIT_ASSERT_EQUAL(perfectOuter
, outerLineWidth
);
242 CPPUNIT_ASSERT_EQUAL(perfectDistance
, lineDistance
);
245 uno::Any aTopBorder
= xPropSet
->getPropertyValue("TopBorder");
246 table::BorderLine aTopBorderLine
;
247 if (aTopBorder
>>= aTopBorderLine
)
249 sal_Int32 innerLineWidth
= aTopBorderLine
.InnerLineWidth
;
250 sal_Int32 outerLineWidth
= aTopBorderLine
.OuterLineWidth
;
251 sal_Int32 lineDistance
= aTopBorderLine
.LineDistance
;
253 sal_Int32 perfectInner
= it
->second
[2].InnerLineWidth
;
254 sal_Int32 perfectOuter
= it
->second
[2].OuterLineWidth
;
255 sal_Int32 perfectDistance
= it
->second
[2].LineDistance
;
256 CPPUNIT_ASSERT_EQUAL(perfectInner
, innerLineWidth
);
257 CPPUNIT_ASSERT_EQUAL(perfectOuter
, outerLineWidth
);
258 CPPUNIT_ASSERT_EQUAL(perfectDistance
, lineDistance
);
261 uno::Any aBottomBorder
= xPropSet
->getPropertyValue("BottomBorder");
262 table::BorderLine aBottomBorderLine
;
263 if (aBottomBorder
>>= aBottomBorderLine
)
265 sal_Int32 innerLineWidth
= aBottomBorderLine
.InnerLineWidth
;
266 sal_Int32 outerLineWidth
= aBottomBorderLine
.OuterLineWidth
;
267 sal_Int32 lineDistance
= aBottomBorderLine
.LineDistance
;
269 sal_Int32 perfectInner
= it
->second
[3].InnerLineWidth
;
270 sal_Int32 perfectOuter
= it
->second
[3].OuterLineWidth
;
271 sal_Int32 perfectDistance
= it
->second
[3].LineDistance
;
272 CPPUNIT_ASSERT_EQUAL(perfectInner
, innerLineWidth
);
273 CPPUNIT_ASSERT_EQUAL(perfectOuter
, outerLineWidth
);
274 CPPUNIT_ASSERT_EQUAL(perfectDistance
, lineDistance
);
277 } //end of the 'for' loop
280 } while(xParaEnum
->hasMoreElements());
283 CPPUNIT_TEST_FIXTURE(Test
, testTdf41542_borderlessPadding
)
285 createSwDoc("tdf41542_borderlessPadding.odt");
286 // the page style's borderless padding should force this to 3 pages, not 1
287 CPPUNIT_ASSERT_EQUAL( 3, getPages() );
290 CPPUNIT_TEST_FIXTURE(Test
, testPageStyleLayoutDefault
)
292 createSwDoc("hello.odt");
293 uno::Reference
<beans::XPropertySet
> xPropertySet(getStyles("PageStyles")->getByName("Default Page Style"), uno::UNO_QUERY
);
294 // This was style::PageStyleLayout_MIRRORED.
295 CPPUNIT_ASSERT_EQUAL(style::PageStyleLayout_ALL
, getProperty
<style::PageStyleLayout
>(xPropertySet
, "PageStyleLayout"));
298 CPPUNIT_TEST_FIXTURE(Test
, testTimeFormFormats
)
300 createSwDoc("timeFormFormats.odt");
301 //FIXME: make it an ODFEXPORT_TEST. Validator fails with
302 //attribute "form:current-value" has a bad value: "PT12H12M" does not satisfy the "time" type
305 uno::Reference
<frame::XModel
> const xModel(mxComponent
, uno::UNO_QUERY
);
306 CPPUNIT_ASSERT(xModel
.is());
307 uno::Reference
<drawing::XDrawPageSupplier
> const xDPS(xModel
, uno::UNO_QUERY
);
308 uno::Reference
<drawing::XDrawPage
> const xDP
= xDPS
->getDrawPage();
309 CPPUNIT_ASSERT(xDP
.is());
310 uno::Reference
<form::XFormsSupplier
> const xFS(xDP
, uno::UNO_QUERY
);
311 CPPUNIT_ASSERT(xFS
.is());
312 uno::Reference
<container::XIndexContainer
> const xForms(xFS
->getForms(), uno::UNO_QUERY
);
313 CPPUNIT_ASSERT(xForms
.is());
314 uno::Reference
<form::XForm
> xForm(xForms
->getByIndex(0), uno::UNO_QUERY_THROW
);
315 CPPUNIT_ASSERT(xForm
.is());
316 uno::Reference
<container::XNameContainer
> xFormNC(xForm
, uno::UNO_QUERY
);
319 uno::Reference
<awt::XControlModel
> xControlModel
;
320 uno::Reference
<view::XControlAccess
> xController
;
321 uno::Reference
<awt::XControl
> xControl
;
322 uno::Reference
<awt::XWindowPeer
> xWindowPeer
;
323 uno::Reference
<awt::XTextComponent
> xTextComponent
;
324 OUString aName
= "Time Field ";
326 static const char* const aExpectedResults
[] = { "12:12", "12:12:00", "12:12PM", "06:00:00AM"};
328 for (size_t i
= 1; i
<= 4; ++i
)
330 aAny
= xFormNC
->getByName(aName
+ OUString::number(i
));
331 xControlModel
.set(aAny
, uno::UNO_QUERY
);
332 xController
.set(xModel
->getCurrentController(), uno::UNO_QUERY_THROW
);
333 xControl
= xController
->getControl(xControlModel
);
334 xWindowPeer
= xControl
->getPeer();
335 xTextComponent
.set(xWindowPeer
, uno::UNO_QUERY
);
336 CPPUNIT_ASSERT_EQUAL(OUString::fromUtf8(aExpectedResults
[i
- 1]), xTextComponent
->getText());
340 CPPUNIT_TEST_FIXTURE(Test
, testDateFormFormats
)
342 createSwDoc("dateFormFormats.odt");
343 //FIXME: make it an ODFEXPORT_TEST. Validator fails with
344 //unexpected attribute "form:input-required"
347 uno::Reference
<frame::XModel
> const xModel(mxComponent
, uno::UNO_QUERY
);
348 CPPUNIT_ASSERT(xModel
.is());
349 uno::Reference
<drawing::XDrawPageSupplier
> const xDPS(xModel
, uno::UNO_QUERY
);
350 uno::Reference
<drawing::XDrawPage
> const xDP
= xDPS
->getDrawPage();
351 CPPUNIT_ASSERT(xDP
.is());
352 uno::Reference
<form::XFormsSupplier
> const xFS(xDP
, uno::UNO_QUERY
);
353 CPPUNIT_ASSERT(xFS
.is());
354 uno::Reference
<container::XIndexContainer
> const xForms(xFS
->getForms(), uno::UNO_QUERY
);
355 CPPUNIT_ASSERT(xForms
.is());
356 uno::Reference
<form::XForm
> xForm(xForms
->getByIndex(0), uno::UNO_QUERY_THROW
);
357 CPPUNIT_ASSERT(xForm
.is());
358 uno::Reference
<container::XNameContainer
> xFormNC(xForm
, uno::UNO_QUERY
);
361 uno::Reference
<awt::XControlModel
> xControlModel
;
362 uno::Reference
<view::XControlAccess
> xController
;
363 uno::Reference
<awt::XControl
> xControl
;
364 uno::Reference
<awt::XWindowPeer
> xWindowPeer
;
365 uno::Reference
<awt::XTextComponent
> xTextComponent
;
366 OUString aName
= "Date Field ";
368 static const char* const aExpectedResults
[] = { "03/04/20", "03/04/20", "03/04/2020",
369 "Wednesday, March 4, 2020", "04/03/20", "03/04/20", "20/03/04", "04/03/2020", "03/04/2020",
370 "2020/03/04", "20-03-04", "2020-03-04"};
372 for (size_t i
= 1; i
<= 12; ++i
)
374 aAny
= xFormNC
->getByName(aName
+ OUString::number(i
));
375 xControlModel
.set(aAny
, uno::UNO_QUERY
);
376 xController
.set(xModel
->getCurrentController(), uno::UNO_QUERY_THROW
);
377 xControl
= xController
->getControl(xControlModel
);
378 xWindowPeer
= xControl
->getPeer();
379 xTextComponent
.set(xWindowPeer
, uno::UNO_QUERY
);
380 CPPUNIT_ASSERT_EQUAL(OUString::fromUtf8(aExpectedResults
[i
- 1]), xTextComponent
->getText());
384 CPPUNIT_TEST_FIXTURE(Test
, testTdf149978
)
386 createSwDoc("tdf149978.fodt");
387 // on Linux the bug only reproduces if a document has been loaded previously
388 createSwDoc("tdf149978.fodt");
389 // this was nondeterministic so try 10 times
390 for (int i
= 1; i
<= 10; ++i
)
392 CPPUNIT_ASSERT_EQUAL(COL_WHITE
, getProperty
<Color
>(getRun(getParagraph(i
), 2, "bar"), "CharBackColor"));
396 CPPUNIT_TEST_FIXTURE(Test
, testTdf64038
)
398 createSwDoc("space.odt");
400 CPPUNIT_ASSERT_EQUAL(OUString("a"), getRun(getParagraph(4), 1)->getString());
401 CPPUNIT_ASSERT_EQUAL(OUString("b"), getRun(getParagraph(4), 2)->getString());
403 CPPUNIT_ASSERT_EQUAL(OUString("a "), getRun(getParagraph(6), 1)->getString());
404 CPPUNIT_ASSERT_EQUAL(OUString("b"), getRun(getParagraph(6), 2)->getString());
405 CPPUNIT_ASSERT_EQUAL(OUString("a"), getRun(getParagraph(7), 1)->getString());
406 CPPUNIT_ASSERT_EQUAL(OUString(" "), getRun(getParagraph(7), 2)->getString());
407 CPPUNIT_ASSERT_EQUAL(OUString("b"), getRun(getParagraph(7), 3)->getString());
408 CPPUNIT_ASSERT_EQUAL(OUString("a"), getRun(getParagraph(8), 1)->getString());
409 CPPUNIT_ASSERT_EQUAL(OUString(" b"), getRun(getParagraph(8), 2)->getString());
411 CPPUNIT_ASSERT_EQUAL(OUString("a"), getRun(getParagraph(10), 1)->getString());
412 CPPUNIT_ASSERT_EQUAL(OUString(" "), getRun(getParagraph(10), 2)->getString());
413 CPPUNIT_ASSERT_EQUAL(OUString("b"), getRun(getParagraph(10), 3)->getString());
414 CPPUNIT_ASSERT_EQUAL(OUString("a "), getRun(getParagraph(11), 1)->getString());
415 CPPUNIT_ASSERT_EQUAL(OUString("b"), getRun(getParagraph(11), 2)->getString());
416 CPPUNIT_ASSERT_EQUAL(OUString("a "), getRun(getParagraph(12), 1)->getString());
417 CPPUNIT_ASSERT_EQUAL(OUString("b"), getRun(getParagraph(12), 2)->getString());
419 CPPUNIT_ASSERT_EQUAL(OUString("a "), getRun(getParagraph(14), 1)->getString());
420 CPPUNIT_ASSERT_EQUAL(OUString("b"), getRun(getParagraph(14), 2)->getString());
422 CPPUNIT_ASSERT_EQUAL(OUString("a"), getRun(getParagraph(17), 1)->getString());
423 CPPUNIT_ASSERT_EQUAL(OUString(" "), getRun(getParagraph(17), 2)->getString());
424 CPPUNIT_ASSERT_EQUAL(OUString("b"), getRun(getParagraph(17), 3)->getString());
426 CPPUNIT_ASSERT_EQUAL(OUString("a "), getRun(getParagraph(19), 1)->getString());
427 CPPUNIT_ASSERT_EQUAL(OUString(" "), getRun(getParagraph(19), 2)->getString());
428 CPPUNIT_ASSERT_EQUAL(OUString("b"), getRun(getParagraph(19), 3)->getString());
429 CPPUNIT_ASSERT_EQUAL(OUString("a"), getRun(getParagraph(20), 1)->getString());
430 CPPUNIT_ASSERT_EQUAL(OUString(" "), getRun(getParagraph(20), 2)->getString());
431 CPPUNIT_ASSERT_EQUAL(OUString("b"), getRun(getParagraph(20), 3)->getString());
432 CPPUNIT_ASSERT_EQUAL(OUString("a"), getRun(getParagraph(21), 1)->getString());
433 CPPUNIT_ASSERT_EQUAL(OUString(" "), getRun(getParagraph(21), 2)->getString());
434 CPPUNIT_ASSERT_EQUAL(OUString("b"), getRun(getParagraph(21), 3)->getString());
435 CPPUNIT_ASSERT_EQUAL(OUString("a"), getRun(getParagraph(22), 1)->getString());
436 CPPUNIT_ASSERT_EQUAL(OUString(" "), getRun(getParagraph(22), 2)->getString());
437 CPPUNIT_ASSERT_EQUAL(OUString(" b"), getRun(getParagraph(22), 3)->getString());
439 CPPUNIT_ASSERT_EQUAL(OUString("a "), getRun(getParagraph(24), 1)->getString());
440 CPPUNIT_ASSERT_EQUAL(OUString(" "), getRun(getParagraph(24), 2)->getString());
441 CPPUNIT_ASSERT_EQUAL(OUString("b"), getRun(getParagraph(24), 3)->getString());
442 CPPUNIT_ASSERT_EQUAL(OUString("a "), getRun(getParagraph(25), 1)->getString());
443 CPPUNIT_ASSERT_EQUAL(OUString(" "), getRun(getParagraph(25), 2)->getString());
444 CPPUNIT_ASSERT_EQUAL(OUString("b"), getRun(getParagraph(25), 3)->getString());
445 CPPUNIT_ASSERT_EQUAL(OUString("a "), getRun(getParagraph(26), 1)->getString());
446 CPPUNIT_ASSERT_EQUAL(OUString(" "), getRun(getParagraph(26), 2)->getString());
447 CPPUNIT_ASSERT_EQUAL(OUString(" b"), getRun(getParagraph(26), 3)->getString());
448 CPPUNIT_ASSERT_EQUAL(OUString("a"), getRun(getParagraph(27), 1)->getString());
449 CPPUNIT_ASSERT_EQUAL(OUString(" "), getRun(getParagraph(27), 2)->getString());
450 CPPUNIT_ASSERT_EQUAL(OUString("b"), getRun(getParagraph(27), 3)->getString());
451 CPPUNIT_ASSERT_EQUAL(OUString("a"), getRun(getParagraph(28), 1)->getString());
452 CPPUNIT_ASSERT_EQUAL(OUString(" "), getRun(getParagraph(28), 2)->getString());
453 CPPUNIT_ASSERT_EQUAL(OUString(" b"), getRun(getParagraph(28), 3)->getString());
454 CPPUNIT_ASSERT_EQUAL(OUString("a"), getRun(getParagraph(29), 1)->getString());
455 CPPUNIT_ASSERT_EQUAL(OUString(" "), getRun(getParagraph(29), 2)->getString());
456 CPPUNIT_ASSERT_EQUAL(OUString("b"), getRun(getParagraph(29), 3)->getString());
458 CPPUNIT_ASSERT_EQUAL(OUString("a"), getRun(getParagraph(31), 1)->getString());
459 CPPUNIT_ASSERT_EQUAL(OUString(" "), getRun(getParagraph(31), 2)->getString());
460 CPPUNIT_ASSERT_EQUAL(OUString("b"), getRun(getParagraph(31), 3)->getString());
461 CPPUNIT_ASSERT_EQUAL(OUString("a "), getRun(getParagraph(32), 1)->getString());
462 CPPUNIT_ASSERT_EQUAL(OUString(" "), getRun(getParagraph(32), 2)->getString());
463 CPPUNIT_ASSERT_EQUAL(OUString("b"), getRun(getParagraph(32), 3)->getString());
464 CPPUNIT_ASSERT_EQUAL(OUString("a "), getRun(getParagraph(33), 1)->getString());
465 CPPUNIT_ASSERT_EQUAL(OUString(" "), getRun(getParagraph(33), 2)->getString());
466 CPPUNIT_ASSERT_EQUAL(OUString(" b"), getRun(getParagraph(33), 3)->getString());
467 CPPUNIT_ASSERT_EQUAL(OUString("a "), getRun(getParagraph(34), 1)->getString());
468 CPPUNIT_ASSERT_EQUAL(OUString(" "), getRun(getParagraph(34), 2)->getString());
469 CPPUNIT_ASSERT_EQUAL(OUString("b"), getRun(getParagraph(34), 3)->getString());
471 CPPUNIT_ASSERT_EQUAL(OUString("a "), getRun(getParagraph(36), 1)->getString());
472 CPPUNIT_ASSERT_EQUAL(OUString(" "), getRun(getParagraph(36), 2)->getString());
473 CPPUNIT_ASSERT_EQUAL(OUString("b"), getRun(getParagraph(36), 3)->getString());
476 CPPUNIT_TEST_FIXTURE(Test
, testTdf74524
)
478 createSwDoc("tdf74524.odt");
479 uno::Reference
<text::XTextFieldsSupplier
> xTextFieldsSupplier(mxComponent
, uno::UNO_QUERY
);
480 uno::Reference
<container::XEnumerationAccess
> xFieldsAccess(xTextFieldsSupplier
->getTextFields());
481 uno::Reference
<container::XEnumeration
> xFields(xFieldsAccess
->createEnumeration());
482 uno::Any aField1
= xFields
->nextElement();
483 uno::Reference
<lang::XServiceInfo
> xServiceInfo1(aField1
, uno::UNO_QUERY
);
484 CPPUNIT_ASSERT(xServiceInfo1
->supportsService("com.sun.star.text.textfield.PageNumber"));
485 uno::Reference
<beans::XPropertySet
> xPropertySet(aField1
, uno::UNO_QUERY
);
486 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int16(style::NumberingType::PAGE_DESCRIPTOR
)), xPropertySet
->getPropertyValue("NumberingType"));
487 CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int16(0)), xPropertySet
->getPropertyValue("Offset"));
488 CPPUNIT_ASSERT_EQUAL(uno::Any(text::PageNumberType_CURRENT
), xPropertySet
->getPropertyValue("SubType"));
489 uno::Reference
<text::XTextContent
> xField1(aField1
, uno::UNO_QUERY
);
490 CPPUNIT_ASSERT_EQUAL(OUString("1"), xField1
->getAnchor()->getString());
491 uno::Any aField2
= xFields
->nextElement();
492 uno::Reference
<lang::XServiceInfo
> xServiceInfo2(aField2
, uno::UNO_QUERY
);
493 CPPUNIT_ASSERT(xServiceInfo2
->supportsService("com.sun.star.text.textfield.Annotation"));
494 uno::Reference
<beans::XPropertySet
> xPropertySet2(aField2
, uno::UNO_QUERY
);
495 CPPUNIT_ASSERT_EQUAL(uno::Any(OUString("Comment 1")), xPropertySet2
->getPropertyValue("Content"));
496 uno::Reference
<text::XTextContent
> xField2(aField2
, uno::UNO_QUERY
);
497 CPPUNIT_ASSERT_EQUAL(OUString("Hello 1World"), xField2
->getAnchor()->getString());
498 CPPUNIT_ASSERT(!xFields
->hasMoreElements());
501 CPPUNIT_TEST_FIXTURE(Test
, testPageStyleLayoutRight
)
503 createSwDoc("hello.odt");
504 uno::Reference
<beans::XPropertySet
> xPropertySet(getStyles("PageStyles")->getByName("Default Page Style"), uno::UNO_QUERY
);
505 // This caused a crash.
506 xPropertySet
->setPropertyValue("PageStyleLayout", uno::Any(style::PageStyleLayout_RIGHT
));
509 CPPUNIT_TEST_FIXTURE(Test
, testFdo61952
)
511 createSwDoc("hello.odt");
512 uno::Reference
<beans::XPropertySet
> xPara(getParagraph(1), uno::UNO_QUERY
);
513 xPara
->setPropertyValue("PageDescName", uno::Any(OUString("Left Page")));
514 xPara
->setPropertyValue("PageDescName", uno::Any(OUString("Right Page")));
515 xPara
->setPropertyValue("PageDescName", uno::Any(OUString("Left Page")));
516 xPara
->setPropertyValue("PageDescName", uno::Any(OUString("Right Page")));
519 CPPUNIT_TEST_FIXTURE(Test
, testFdo60842
)
521 createSwDoc("fdo60842.odt");
522 uno::Reference
<text::XTextContent
> const xTable(getParagraphOrTable(1));
523 getCell(xTable
, "A1", "");
524 getCell(xTable
, "B1", "18/02/2012");
525 getCell(xTable
, "C1", "USD"); // this is the cell with office:string-value
526 getCell(xTable
, "D1", "");
527 getCell(xTable
, "E1", "01/04/2012");
530 CPPUNIT_TEST_FIXTURE(Test
, testFdo79269
)
532 createSwDoc("fdo79269.odt");
533 CPPUNIT_ASSERT_EQUAL(2, getPages());
535 // The problem was that the first-footer was shared.
536 uno::Reference
<beans::XPropertySet
> xPropSet(getStyles("PageStyles")->getByName("Standard"), uno::UNO_QUERY
);
537 CPPUNIT_ASSERT_EQUAL(false, getProperty
<bool>(xPropSet
, "FirstIsShared"));
539 uno::Reference
<text::XTextRange
> xFooter1
= getProperty
< uno::Reference
<text::XTextRange
> >(xPropSet
, "FooterTextFirst");
540 CPPUNIT_ASSERT_EQUAL(OUString("first"), xFooter1
->getString());
541 uno::Reference
<text::XTextRange
> xFooter
= getProperty
< uno::Reference
<text::XTextRange
> >(xPropSet
, "FooterText");
542 CPPUNIT_ASSERT_EQUAL(OUString("second"), xFooter
->getString());
545 CPPUNIT_TEST_FIXTURE(Test
, testFdo79269_header
)
547 createSwDoc("fdo79269_header.odt");
548 CPPUNIT_ASSERT_EQUAL(2, getPages());
550 uno::Reference
<beans::XPropertySet
> xPropSet(getStyles("PageStyles")->getByName("Standard"), uno::UNO_QUERY
);
551 CPPUNIT_ASSERT_EQUAL(false, getProperty
<bool>(xPropSet
, "FirstIsShared"));
553 uno::Reference
<text::XTextRange
> xFooter1
= getProperty
< uno::Reference
<text::XTextRange
> >(xPropSet
, "HeaderTextFirst");
554 CPPUNIT_ASSERT_EQUAL(OUString("first"), xFooter1
->getString());
555 uno::Reference
<text::XTextRange
> xFooter
= getProperty
< uno::Reference
<text::XTextRange
> >(xPropSet
, "HeaderText");
556 CPPUNIT_ASSERT_EQUAL(OUString("second"), xFooter
->getString());
559 CPPUNIT_TEST_FIXTURE(Test
, testPageBackground
)
561 createSwDoc("PageBackground.odt");
562 uno::Reference
<beans::XPropertySet
> xPropertySet(getStyles("PageStyles")->getByName("Default Page Style"), uno::UNO_QUERY
);
563 // The background image was lost
564 CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_BITMAP
, getProperty
<drawing::FillStyle
>(xPropertySet
, "FillStyle"));
565 CPPUNIT_ASSERT_EQUAL(OUString("Sky"), getProperty
<OUString
>(xPropertySet
, "FillBitmapName"));
566 CPPUNIT_ASSERT_EQUAL(drawing::BitmapMode_REPEAT
, getProperty
<drawing::BitmapMode
>(xPropertySet
, "FillBitmapMode"));
568 uno::Reference
<beans::XPropertySet
> xPropertySetOld(getStyles("PageStyles")->getByName("OldStandard"), uno::UNO_QUERY
);
569 // The background image was overridden by color
570 CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_BITMAP
, getProperty
<drawing::FillStyle
>(xPropertySetOld
, "FillStyle"));
571 CPPUNIT_ASSERT_EQUAL(OUString("Sky"), getProperty
<OUString
>(xPropertySetOld
, "FillBitmapName"));
572 CPPUNIT_ASSERT_EQUAL(drawing::BitmapMode_REPEAT
, getProperty
<drawing::BitmapMode
>(xPropertySetOld
, "FillBitmapMode"));
575 CPPUNIT_TEST_FIXTURE(Test
, testBibliographyEntryField
)
577 createSwDoc("BibliographyEntryField.odt");
578 uno::Reference
<text::XTextFieldsSupplier
> xTextFieldsSupplier(mxComponent
, uno::UNO_QUERY
);
579 uno::Reference
<container::XEnumerationAccess
> xFieldsAccess(xTextFieldsSupplier
->getTextFields());
580 uno::Reference
<container::XEnumeration
> xFields(xFieldsAccess
->createEnumeration());
582 if( !xFields
->hasMoreElements() ) {
583 CPPUNIT_ASSERT(false);
587 uno::Reference
<text::XTextField
> xEnumerationAccess(xFields
->nextElement(), uno::UNO_QUERY
);
588 CPPUNIT_ASSERT_EQUAL(OUString("Bibliography entry"), xEnumerationAccess
->getPresentation(true).trim());
589 CPPUNIT_ASSERT_EQUAL(OUString("[ABC]"), xEnumerationAccess
->getPresentation(false).trim());
592 CPPUNIT_TEST_FIXTURE(Test
, testFdo56272
)
594 createSwDoc("fdo56272.odt");
595 uno::Reference
<drawing::XShape
> xShape
= getShape(1);
596 // Vertical position was incorrect.
597 CPPUNIT_ASSERT_EQUAL(sal_Int32(422), xShape
->getPosition().Y
); // Was -2371
600 CPPUNIT_TEST_FIXTURE(Test
, testIncorrectSum
)
602 createSwDoc("incorrectsum.odt");
603 Scheduler::ProcessEventsToIdle();
604 uno::Reference
<text::XTextTablesSupplier
> xTablesSupplier(mxComponent
, uno::UNO_QUERY
);
605 uno::Reference
<container::XIndexAccess
> xTables(xTablesSupplier
->getTextTables( ), uno::UNO_QUERY
);
606 uno::Reference
<text::XTextTable
> xTextTable(xTables
->getByIndex(0), uno::UNO_QUERY
);
607 uno::Reference
<text::XTextRange
> xCell(xTextTable
->getCellByName("C3"), uno::UNO_QUERY
);
608 // Use indexOf instead of exact match since the result contains an Euro sign which OUString doesn't like
609 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xCell
->getString().indexOf("1,278"));
612 CPPUNIT_TEST_FIXTURE(Test
, testTdf128737
)
614 createSwDoc("tdf128737.odt");
615 // Without the fix in place, this test would have crashed
616 CPPUNIT_ASSERT_EQUAL(4, getPages());
617 CPPUNIT_ASSERT_EQUAL(8, getShapes());
620 CPPUNIT_TEST_FIXTURE(Test
, testCalcFootnoteContent
)
622 createSwDoc("ooo32780-1.odt");
623 //this was a CalcFootnoteContent crash
626 CPPUNIT_TEST_FIXTURE(Test
, testMoveSubTree
)
628 createSwDoc("ooo77837-1.odt");
629 //this was a MoveSubTree crash
632 CPPUNIT_TEST_FIXTURE(Test
, testFdo75872_ooo33
)
634 createSwDoc("fdo75872_ooo33.odt");
635 // graphics default style: line color and fill color changed
636 uno::Reference
<drawing::XShape
> xShape
= getShape(1);
637 CPPUNIT_ASSERT_EQUAL(COL_BLACK
,
638 getProperty
<Color
>(xShape
, "LineColor"));
639 CPPUNIT_ASSERT_EQUAL(Color(0x99ccff),
640 getProperty
<Color
>(xShape
, "FillColor"));
643 CPPUNIT_TEST_FIXTURE(Test
, testFdo75872_aoo40
)
645 createSwDoc("fdo75872_aoo40.odt");
646 // graphics default style: line color and fill color changed
647 uno::Reference
<drawing::XShape
> xShape
= getShape(1);
648 CPPUNIT_ASSERT_EQUAL(Color(0x808080),
649 getProperty
<Color
>(xShape
, "LineColor"));
650 CPPUNIT_ASSERT_EQUAL(Color(0xcfe7f5),
651 getProperty
<Color
>(xShape
, "FillColor"));
654 CPPUNIT_TEST_FIXTURE(Test
, testFdo55814
)
656 createSwDoc("fdo55814.odt");
657 uno::Reference
<text::XTextFieldsSupplier
> xTextFieldsSupplier(mxComponent
, uno::UNO_QUERY
);
658 uno::Reference
<container::XEnumerationAccess
> xFieldsAccess(xTextFieldsSupplier
->getTextFields());
659 uno::Reference
<container::XEnumeration
> xFields(xFieldsAccess
->createEnumeration());
660 uno::Reference
<beans::XPropertySet
> xField(xFields
->nextElement(), uno::UNO_QUERY
);
661 xField
->setPropertyValue("Content", uno::Any(OUString("Yes")));
662 uno::Reference
<util::XRefreshable
>(xTextFieldsSupplier
->getTextFields(), uno::UNO_QUERY_THROW
)->refresh();
663 uno::Reference
<text::XTextSectionsSupplier
> xTextSectionsSupplier(mxComponent
, uno::UNO_QUERY
);
664 uno::Reference
<container::XIndexAccess
> xSections(xTextSectionsSupplier
->getTextSections(), uno::UNO_QUERY
);
666 CPPUNIT_ASSERT_EQUAL(OUString("Hide==\"Yes\""), getProperty
<OUString
>(xSections
->getByIndex(0), "Condition"));
669 static void lcl_CheckShape(
670 uno::Reference
<drawing::XShape
> const& xShape
, OUString
const& rExpected
)
672 uno::Reference
<container::XNamed
> const xNamed(xShape
, uno::UNO_QUERY
);
673 CPPUNIT_ASSERT(xNamed
.is());
674 CPPUNIT_ASSERT_EQUAL(rExpected
, xNamed
->getName());
677 CPPUNIT_TEST_FIXTURE(Test
, testFdo68839
)
679 createSwDoc("fdo68839.odt");
680 CPPUNIT_ASSERT_EQUAL(4, getShapes());
682 lcl_CheckShape(getShape(1), "FrameXXX");
683 lcl_CheckShape(getShape(2), "ObjectXXX");
684 lcl_CheckShape(getShape(3), "FrameY");
685 lcl_CheckShape(getShape(4), "graphicsXXX");
686 // check prev/next chain
687 uno::Reference
<beans::XPropertySet
> xFrame1(getShape(1), uno::UNO_QUERY
);
688 uno::Reference
<beans::XPropertySet
> xFrame2(getShape(3), uno::UNO_QUERY
);
689 CPPUNIT_ASSERT_EQUAL(OUString(),
690 getProperty
<OUString
>(xFrame1
, "ChainPrevName"));
691 CPPUNIT_ASSERT_EQUAL(OUString("FrameY"),
692 getProperty
<OUString
>(xFrame1
, "ChainNextName"));
693 CPPUNIT_ASSERT_EQUAL(OUString("FrameXXX"),
694 getProperty
<OUString
>(xFrame2
, "ChainPrevName"));
695 CPPUNIT_ASSERT_EQUAL(OUString(),
696 getProperty
<OUString
>(xFrame2
, "ChainNextName"));
699 CPPUNIT_TEST_FIXTURE(Test
, testFdo82165
)
701 createSwDoc("fdo82165.odt");
702 CPPUNIT_ASSERT_EQUAL(1, getShapes());
703 // there was a duplicate shape in the left header
704 lcl_CheckShape(getShape(1), "Picture 9");
707 CPPUNIT_TEST_FIXTURE(Test
, testTdf89802
)
709 createSwDoc("tdf89802.fodt");
710 // the text frame was dropped during import
711 uno::Reference
<text::XTextFramesSupplier
> const xTextFramesSupplier(mxComponent
, uno::UNO_QUERY
);
712 uno::Reference
<container::XIndexAccess
> const xIndexAccess(xTextFramesSupplier
->getTextFrames(), uno::UNO_QUERY
);
713 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
714 uno::Reference
<beans::XPropertySet
> const xFrame(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
715 CPPUNIT_ASSERT_EQUAL(Color(ColorTransparency
, 0x3f004586), getProperty
<Color
>(xFrame
, "BackColor"));
719 CPPUNIT_TEST_FIXTURE(Test
, testFdo37606
)
721 createSwDoc("fdo37606.odt");
722 SwXTextDocument
* pTextDoc
= dynamic_cast<SwXTextDocument
*>(mxComponent
.get());
723 CPPUNIT_ASSERT(pTextDoc
);
724 SwWrtShell
* pWrtShell
= pTextDoc
->GetDocShell()->GetWrtShell();
725 SwShellCursor
* pShellCursor
= pWrtShell
->getShellCursor(false);
728 pWrtShell
->SelAll(); // Selects A1.
729 SwTextNode
& rCellEnd
= dynamic_cast<SwTextNode
&>(pShellCursor
->End()->GetNode());
730 // fdo#72486 This was "Hello.", i.e. a single select-all selected the whole document, not just the cell only.
731 CPPUNIT_ASSERT_EQUAL(OUString("A1"), rCellEnd
.GetText());
733 pWrtShell
->SelAll(); // Selects the whole table.
734 pWrtShell
->SelAll(); // Selects the whole document.
735 pShellCursor
= pWrtShell
->getShellCursor(false);
737 SwTextNode
& rStart
= dynamic_cast<SwTextNode
&>(pShellCursor
->Start()->GetNode());
738 CPPUNIT_ASSERT_EQUAL(OUString("A1"), rStart
.GetText());
740 SwTextNode
& rEnd
= dynamic_cast<SwTextNode
&>(pShellCursor
->End()->GetNode());
741 // This was "A1", i.e. Ctrl-A only selected the A1 cell of the table, not the whole document.
742 CPPUNIT_ASSERT_EQUAL(OUString("Hello."), rEnd
.GetText());
746 pWrtShell
->SttEndDoc(false); // Go to the end of the doc.
747 pWrtShell
->SelAll(); // And now that we're outside of the table, try Ctrl-A again.
748 SwTextNode
& rStart
= dynamic_cast<SwTextNode
&>(pShellCursor
->Start()->GetNode());
749 // This was "Hello", i.e. Ctrl-A did not select the starting table.
750 CPPUNIT_ASSERT_EQUAL(OUString("A1"), rStart
.GetText());
752 SwTextNode
& rEnd
= dynamic_cast<SwTextNode
&>(pShellCursor
->End()->GetNode());
753 CPPUNIT_ASSERT_EQUAL(OUString("Hello."), rEnd
.GetText());
757 pWrtShell
->Delete(); // Delete the selection
758 // And make sure the table got deleted as well.
759 SwNodes
& rNodes
= pWrtShell
->GetDoc()->GetNodes();
760 SwNodeIndex
nNode(rNodes
.GetEndOfExtras());
761 SwContentNode
* pContentNode
= rNodes
.GoNext(&nNode
);
762 // First content node was in a table -> table wasn't deleted.
763 CPPUNIT_ASSERT(!pContentNode
->FindTableNode());
768 CPPUNIT_TEST_FIXTURE(Test
, testFdo37606Copy
)
770 createSwDoc("fdo37606.odt");
771 SwXTextDocument
* pTextDoc
= dynamic_cast<SwXTextDocument
*>(mxComponent
.get());
772 CPPUNIT_ASSERT(pTextDoc
);
773 SwWrtShell
* pWrtShell
= pTextDoc
->GetDocShell()->GetWrtShell();
775 pWrtShell
->SelAll(); // Selects A1.
776 pWrtShell
->SelAll(); // Selects the whole table.
777 pWrtShell
->SelAll(); // Selects the whole document.
780 rtl::Reference
<SwTransferable
> xTransferable(new SwTransferable(*pWrtShell
));
781 xTransferable
->Copy();
783 pWrtShell
->SttEndDoc(false); // Go to the end of the doc.
786 TransferableDataHelper
aDataHelper(TransferableDataHelper::CreateFromSystemClipboard(&pWrtShell
->GetView().GetEditWin()));
787 SwTransferable::Paste( *pWrtShell
, aDataHelper
);
789 // Previously copy&paste failed to copy the table in case it was the document-starting one.
790 uno::Reference
<text::XTextTablesSupplier
> xTablesSupplier(mxComponent
, uno::UNO_QUERY
);
791 uno::Reference
<container::XIndexAccess
> xTables(xTablesSupplier
->getTextTables(), uno::UNO_QUERY
);
792 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTables
->getCount());
796 CPPUNIT_TEST_FIXTURE(Test
, testFdo69862
)
798 createSwDoc("fdo69862.odt");
799 // The test doc is special in that it starts with a table and it also has a footnote.
800 SwXTextDocument
* pTextDoc
= dynamic_cast<SwXTextDocument
*>(mxComponent
.get());
801 CPPUNIT_ASSERT(pTextDoc
);
802 SwWrtShell
* pWrtShell
= pTextDoc
->GetDocShell()->GetWrtShell();
804 pWrtShell
->SelAll(); // Selects A1.
805 pWrtShell
->SelAll(); // Selects the whole table.
806 pWrtShell
->SelAll(); // Selects the whole document.
807 SwShellCursor
* pShellCursor
= pWrtShell
->getShellCursor(false);
808 SwTextNode
& rStart
= dynamic_cast<SwTextNode
&>(pShellCursor
->Start()->GetNode());
809 // This was "Footnote.", as Ctrl-A also selected footnotes, but it should not.
810 CPPUNIT_ASSERT_EQUAL(OUString("A1"), rStart
.GetText());
812 SwTextNode
& rEnd
= dynamic_cast<SwTextNode
&>(pShellCursor
->End()->GetNode());
813 CPPUNIT_ASSERT_EQUAL(OUString("H" "\x01" "ello."), rEnd
.GetText());
816 CPPUNIT_TEST_FIXTURE(Test
, testFdo69979
)
818 createSwDoc("fdo69979.odt");
819 // The test doc is special in that it starts with a table and it also has a header.
820 SwXTextDocument
* pTextDoc
= dynamic_cast<SwXTextDocument
*>(mxComponent
.get());
821 CPPUNIT_ASSERT(pTextDoc
);
822 SwWrtShell
* pWrtShell
= pTextDoc
->GetDocShell()->GetWrtShell();
823 SwShellCursor
* pShellCursor
= pWrtShell
->getShellCursor(false);
825 pWrtShell
->SelAll(); // Selects A1.
826 pWrtShell
->SelAll(); // Selects the whole table.
827 pWrtShell
->SelAll(); // Selects the whole document.
828 SwTextNode
& rStart
= dynamic_cast<SwTextNode
&>(pShellCursor
->Start()->GetNode());
829 // This was "", as Ctrl-A also selected headers, but it should not.
830 CPPUNIT_ASSERT_EQUAL(OUString("A1"), rStart
.GetText());
832 SwTextNode
& rEnd
= dynamic_cast<SwTextNode
&>(pShellCursor
->End()->GetNode());
833 CPPUNIT_ASSERT_EQUAL(OUString("Hello."), rEnd
.GetText());
836 CPPUNIT_TEST_FIXTURE(Test
, testSpellmenuRedline
)
838 createSwDoc("spellmenu-redline.odt");
839 SwXTextDocument
* pTextDoc
= dynamic_cast<SwXTextDocument
*>(mxComponent
.get());
840 CPPUNIT_ASSERT(pTextDoc
);
841 SwWrtShell
* pWrtShell
= pTextDoc
->GetDocShell()->GetWrtShell();
842 uno::Reference
<linguistic2::XSpellAlternatives
> xAlt
;
843 SwSpellPopup
aPopup(pWrtShell
, xAlt
, OUString());
844 Menu
& rMenu
= aPopup
.GetMenu();
845 // Make sure that if we show the spellcheck popup menu (for the current
846 // document, which contains redlines), then the last two entries will be
847 // always 'go to next/previous change'.
848 CPPUNIT_ASSERT_EQUAL(OUString("next"), rMenu
.GetItemIdent(rMenu
.GetItemId(rMenu
.GetItemCount() - 2)));
849 CPPUNIT_ASSERT_EQUAL(OUString("prev"), rMenu
.GetItemIdent(rMenu
.GetItemId(rMenu
.GetItemCount() - 1)));
852 CPPUNIT_TEST_FIXTURE(Test
, testTdf107776
)
854 createSwDoc("tdf107776.fodt");
855 // Shape with a Graphics parent style name was imported as textbox.
856 CPPUNIT_ASSERT(!getProperty
<bool>(getShape(1), "TextBox"));
859 CPPUNIT_TEST_FIXTURE(Test
, testAnnotationFormatting
)
861 createSwDoc("annotation-formatting.odt");
862 uno::Reference
<beans::XPropertySet
> xTextField
= getProperty
< uno::Reference
<beans::XPropertySet
> >(getRun(getParagraph(1), 1), "TextField");
863 uno::Reference
<text::XText
> xText
= getProperty
< uno::Reference
<text::XText
> >(xTextField
, "TextRange");
864 // Make sure we test the right annotation.
865 uno::Reference
<text::XTextRange
> xParagraph
= getParagraphOfText(1, xText
, "Looses: bold");
866 // Formatting was lost: the second text portion was NORMAL, not BOLD.
867 CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD
, getProperty
<float>(getRun(xParagraph
, 2), "CharWeight"));
870 CPPUNIT_TEST_FIXTURE(Test
, fdo81223
)
872 createSwDoc("fdo81223.odt");
873 uno::Reference
<text::XTextFramesSupplier
> xTextFramesSupplier(mxComponent
, uno::UNO_QUERY
);
874 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextFramesSupplier
->getTextFrames(), uno::UNO_QUERY
);
875 uno::Reference
<beans::XPropertySet
> xFrame(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
876 CPPUNIT_ASSERT_EQUAL(COL_TRANSPARENT
, getProperty
<Color
>(xFrame
, "BackColor"));
879 CPPUNIT_TEST_FIXTURE(Test
, fdo90130_1
)
881 createSwDoc("fdo90130-1.odt");
882 uno::Reference
<text::XTextFramesSupplier
> xTextFramesSupplier(mxComponent
, uno::UNO_QUERY
);
883 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextFramesSupplier
->getTextFrames(), uno::UNO_QUERY
);
884 uno::Reference
<beans::XPropertySet
> xFrame(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
885 CPPUNIT_ASSERT_EQUAL(Color(0xff3333), getProperty
<Color
>(xFrame
, "BackColor"));
888 CPPUNIT_TEST_FIXTURE(Test
, fdo90130_2
)
890 createSwDoc("fdo90130-2.odt");
891 uno::Reference
<text::XTextFramesSupplier
> xTextFramesSupplier(mxComponent
, uno::UNO_QUERY
);
892 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextFramesSupplier
->getTextFrames(), uno::UNO_QUERY
);
893 uno::Reference
<beans::XPropertySet
> xFrame(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
895 xFrame
->getPropertyValue("BackColorTransparency") >>= nValue
;
896 CPPUNIT_ASSERT_EQUAL(sal_Int32(50), nValue
);
899 CPPUNIT_TEST_FIXTURE(Test
, testBnc800714
)
901 createSwDoc("bnc800714.fodt");
902 // Document's second paragraph wants to be together with the third one, but:
903 // - it's in a section with multiple columns
904 // - contains a single as-char anchored frame
905 // This was a layout loop.
906 CPPUNIT_ASSERT(getProperty
< uno::Reference
<text::XTextSection
> >(getParagraph(2), "TextSection").is());
907 CPPUNIT_ASSERT(getProperty
<bool>(getParagraph(2), "ParaKeepTogether"));
910 CPPUNIT_TEST_FIXTURE(Test
, testTdf92586
)
912 createSwDoc("tdf92586.odt");
913 uno::Any aPageStyle
= getStyles("PageStyles")->getByName("Standard");
914 // This was BitmapMode_NO_REPEAT.
915 CPPUNIT_ASSERT_EQUAL(drawing::BitmapMode_STRETCH
, getProperty
<drawing::BitmapMode
>(aPageStyle
, "FillBitmapMode"));
918 CPPUNIT_TEST_FIXTURE(Test
, testTdf103025
)
920 createSwDoc("tdf103025.odt");
921 CPPUNIT_ASSERT_EQUAL(OUString("2014-01"), parseDump("/root/page[1]/header/tab[2]/row[2]/cell[3]/txt/SwParaPortion/SwLineLayout/SwFieldPortion", "expand"));
922 CPPUNIT_ASSERT_EQUAL(OUString("2014-01"), parseDump("/root/page[2]/header/tab[2]/row[2]/cell[3]/txt/SwParaPortion/SwLineLayout/SwFieldPortion", "expand"));
923 CPPUNIT_ASSERT_EQUAL(OUString("2014-02"), parseDump("/root/page[3]/header/tab[2]/row[2]/cell[3]/txt/SwParaPortion/SwLineLayout/SwFieldPortion", "expand"));
924 CPPUNIT_ASSERT_EQUAL(OUString("2014-03"), parseDump("/root/page[4]/header/tab[2]/row[2]/cell[3]/txt/SwParaPortion/SwLineLayout/SwFieldPortion", "expand"));
925 CPPUNIT_ASSERT_EQUAL(OUString("2014-03"), parseDump("/root/page[5]/header/tab[2]/row[2]/cell[3]/txt/SwParaPortion/SwLineLayout/SwFieldPortion", "expand"));
928 CPPUNIT_TEST_FIXTURE(Test
, testTdf76322_columnBreakInHeader
)
930 createSwDoc("tdf76322_columnBreakInHeader.docx");
931 // column breaks were ignored. First line should start in column 2
932 CPPUNIT_ASSERT_EQUAL( OUString("Test1"), parseDump("/root/page[1]/header/section/column[2]/body/txt/text()") );
935 CPPUNIT_TEST_FIXTURE(Test
, testTdf76349_1columnBreak
)
937 createSwDoc("tdf76349_1columnBreak.odt");
938 //single-column breaks should only be treated as page breaks for MS formats - should be only one page here.
939 CPPUNIT_ASSERT_EQUAL(1, getPages());
942 CPPUNIT_TEST_FIXTURE(Test
, testTdf96113
)
944 createSwDoc("tdf96113.odt");
945 // Background of the formula frame was white (0xffffff), not green.
946 CPPUNIT_ASSERT_EQUAL(Color(0x00ff00), getProperty
<Color
>(getShape(1), "BackColor"));
949 CPPUNIT_TEST_FIXTURE(Test
, testFdo47267
)
951 createSwDoc("fdo47267-3.odt");
952 // This was a Style Families getByName() crash
955 CPPUNIT_TEST_FIXTURE(Test
, testTdf75221
)
957 createSwDoc("tdf75221.odt");
958 // When "Don't add space between paragraphs of the same style" setting set,
959 // spacing between same-style paragraphs must be equal to their line spacing.
961 OUString top
= parseDump("/root/page/body/txt[2]/infos/prtBounds", "top");
962 CPPUNIT_ASSERT(top
.toInt32() > 0);
965 CPPUNIT_TEST_FIXTURE(Test
, testTdf101729
)
967 createSwDoc("tdf101729.odt");
968 sal_Int32 l
= parseDump("/root/page/body/tab/row/cell[1]/infos/bounds", "left").toInt32();
969 sal_Int32 w
= parseDump("/root/page/body/tab/row/cell[1]/infos/bounds", "width").toInt32();
970 sal_Int32 x
= parseDump("/root/page/body/tab/row/cell[1]/txt/infos/bounds", "left").toInt32();
971 // Make sure the text does not go outside and verify it is centered roughly
972 CPPUNIT_ASSERT( l
+ w
/ 4 < x
);
973 CPPUNIT_ASSERT( x
< l
+ 3 * w
/ 4);
976 CPPUNIT_TEST_FIXTURE(Test
, testTdf107392
)
978 createSwDoc("tdf107392.odt");
979 // Shapes from bottom to top were Frame, SVG, Bitmap, i.e. in the order as
980 // they appeared in the document, not according to their requested z-index,
981 // as sorting failed.
982 // So instead of 0, 1, 2 these were 2, 0, 1.
984 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty
<sal_Int32
>(getShapeByName(u
"Bitmap"), "ZOrder"));
985 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getProperty
<sal_Int32
>(getShapeByName(u
"Frame"), "ZOrder"));
986 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), getProperty
<sal_Int32
>(getShapeByName(u
"SVG"), "ZOrder"));
989 CPPUNIT_TEST_FIXTURE(Test
, testTdf100033_1
)
991 createSwDoc("tdf100033_1.odt");
992 // Test document have three duplicated frames with the same name and position/size -> import one frame
993 uno::Reference
<text::XTextFramesSupplier
> xTextFramesSupplier(mxComponent
, uno::UNO_QUERY
);
994 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextFramesSupplier
->getTextFrames(), uno::UNO_QUERY
);
995 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
998 CPPUNIT_TEST_FIXTURE(Test
, testWordAsCharShape
)
1000 createSwDoc("Word2010AsCharShape.odt");
1001 // As-char shape had VertOrient "from-top"/NONE default from GetVOrient()
1002 uno::Reference
<drawing::XShape
> const xShape(getShape(1));
1003 CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AS_CHARACTER
, getProperty
<text::TextContentAnchorType
>(xShape
, "AnchorType"));
1004 CPPUNIT_ASSERT_EQUAL(text::VertOrientation::TOP
, getProperty
<sal_Int16
>(xShape
, "VertOrient"));
1005 // also, the paragraph default fo:bottom-margin was wrongly applied to
1007 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty
<sal_Int32
>(xShape
, "BottomMargin"));
1010 CPPUNIT_TEST_FIXTURE(Test
, testTdf100033_2
)
1012 createSwDoc("tdf100033_2.odt");
1013 // Test document have three different frames anchored to different paragraphs -> import all frames
1014 uno::Reference
<text::XTextFramesSupplier
> xTextFramesSupplier(mxComponent
, uno::UNO_QUERY
);
1015 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextFramesSupplier
->getTextFrames(), uno::UNO_QUERY
);
1016 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xIndexAccess
->getCount());
1019 CPPUNIT_TEST_FIXTURE(Test
, testI61225
)
1021 createSwDoc("i61225.sxw");
1022 // Part of ooo61225-1.sxw from crashtesting.
1024 // This never returned.
1028 CPPUNIT_TEST_FIXTURE(Test
, testTdf109080_loext_ns
)
1030 createSwDoc("tdf109080_loext_ns.odt");
1031 // Test we can import <loext:header-first> and <loext:footer-first>
1033 CPPUNIT_ASSERT_EQUAL(OUString("This is the first page header"),
1034 parseDump("/root/page[1]/header/txt/text()"));
1035 CPPUNIT_ASSERT_EQUAL(OUString("This is the non-first-page header"),
1036 parseDump("/root/page[2]/header/txt/text()"));
1038 CPPUNIT_ASSERT_EQUAL(OUString("This is the first page footer"),
1039 parseDump("/root/page[1]/footer/txt/text()"));
1040 CPPUNIT_ASSERT_EQUAL(OUString("This is the non-first-page footer"),
1041 parseDump("/root/page[2]/footer/txt/text()"));
1044 CPPUNIT_TEST_FIXTURE(Test
, testTdf109080_style_ns
)
1046 createSwDoc("tdf109080_style_ns.odt");
1047 // Test we can import <style:header-first> and <style:footer-first>
1048 // (produced by LibreOffice 4.0 - 5.x)
1050 CPPUNIT_ASSERT_EQUAL(OUString("This is the first page header"),
1051 parseDump("/root/page[1]/header/txt/text()"));
1052 CPPUNIT_ASSERT_EQUAL(OUString("This is the non-first-page header"),
1053 parseDump("/root/page[2]/header/txt/text()"));
1055 CPPUNIT_ASSERT_EQUAL(OUString("This is the first page footer"),
1056 parseDump("/root/page[1]/footer/txt/text()"));
1057 CPPUNIT_ASSERT_EQUAL(OUString("This is the non-first-page footer"),
1058 parseDump("/root/page[2]/footer/txt/text()"));
1061 CPPUNIT_TEST_FIXTURE(Test
, testTdf109228
)
1063 createSwDoc("tdf109228.odt");
1064 // Embedded object with no frame name was imported incorrectly, it was anchored 'to character' instead of 'as character'
1065 CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AS_CHARACTER
, getProperty
<text::TextContentAnchorType
>(getShape(1), "AnchorType"));
1068 CPPUNIT_TEST_FIXTURE(Test
, testTdf94882
)
1070 createSwDoc("tdf94882.odt");
1071 // Get the header of the page containing our content
1072 // (done this way to skip past any blank page inserted before it
1073 // due to the page number being even)
1074 OUString headertext
= parseDump(
1075 "/root/page[starts-with(body/txt/text(),'The paragraph style on this')]"
1076 "/header/txt/text()"
1078 // This header should be the first page header
1079 CPPUNIT_ASSERT_EQUAL(OUString("This is the first page header"), headertext
);
1082 CPPUNIT_TEST_FIXTURE(Test
, testBlankBeforeFirstPage
)
1084 createSwDoc("tdf94882.odt");
1085 // This document starts on page 50, which is even, but it should not have a
1086 // blank page inserted before it to make it a left page
1088 CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be 1 pages output",
1089 OUString("1"), parseDump("count(/root/page)")
1093 CPPUNIT_TEST_FIXTURE(Test
, testTdf115079
)
1095 createSwDoc("tdf115079.odt");
1096 // This document caused segfault when layouting
1099 CPPUNIT_TEST_FIXTURE(Test
, testTdf108482
)
1101 createSwDoc("tdf108482.odt");
1102 CPPUNIT_ASSERT_EQUAL_MESSAGE("The table on second page must have two rows",
1103 OUString("2"), parseDump("count(/root/page[2]/body/tab/row)")
1105 CPPUNIT_ASSERT_EQUAL_MESSAGE("The second page table's first row must be the repeated headline",
1106 OUString("Header"), parseDump("/root/page[2]/body/tab/row[1]/cell/txt")
1108 // The first (repeated headline) row with vertical text orientation must have non-zero height
1109 // (in my tests, it was 1135)
1110 CPPUNIT_ASSERT_GREATER(
1111 sal_Int32(1000), parseDump("/root/page[2]/body/tab/row[1]/infos/bounds", "height").toInt32()
1115 CPPUNIT_TEST_FIXTURE(Test
, testTdf116195
)
1117 createSwDoc("tdf116195.odt");
1118 // The image was set to zero height due to a regression
1119 CPPUNIT_ASSERT_EQUAL(
1120 sal_Int32(12960), parseDump("/root/page/anchored/fly/notxt/infos/bounds", "height").toInt32()
1124 CPPUNIT_TEST_FIXTURE(Test
, testTdf120677
)
1126 createSwDoc("tdf120677.fodt");
1127 // The document used to hang the layout, consuming memory until OOM
1130 CPPUNIT_TEST_FIXTURE(Test
, testTdf152015
)
1132 // it hangs at import time
1133 createSwDoc("tdf152015.odt");
1135 CPPUNIT_ASSERT_EQUAL( 1, getPages() );
1138 CPPUNIT_TEST_FIXTURE(Test
, testTdf123829
)
1140 createSwDoc("tdf123829.odt");
1141 SwXTextDocument
* pTextDoc
= dynamic_cast<SwXTextDocument
*>(mxComponent
.get());
1142 CPPUNIT_ASSERT(pTextDoc
);
1143 SwDoc
* pDoc
= pTextDoc
->GetDocShell()->GetDoc();
1144 CPPUNIT_ASSERT_EQUAL_MESSAGE(
1145 "Compatibility: collapse cell paras should not be set", false,
1146 pDoc
->getIDocumentSettingAccess().get(DocumentSettingId::COLLAPSE_EMPTY_CELL_PARA
));
1149 CPPUNIT_TEST_FIXTURE(Test
, testTdf113289
)
1151 createSwDoc("tdf113289.odt");
1152 uno::Any aPageStyle
= getStyles("PageStyles")->getByName("Standard");
1153 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int8
>(style::FootnoteLineStyle::SOLID
),
1154 getProperty
<sal_Int8
>(aPageStyle
, "FootnoteLineStyle"));
1157 CPPUNIT_TEST_FIXTURE(Test
, testTdf123968
)
1159 createSwDoc("tdf123968.odt");
1160 // The test doc is special in that it starts with a table and it also has a header.
1161 SwXTextDocument
* pTextDoc
= dynamic_cast<SwXTextDocument
*>(mxComponent
.get());
1162 CPPUNIT_ASSERT(pTextDoc
);
1163 SwWrtShell
* pWrtShell
= pTextDoc
->GetDocShell()->GetWrtShell();
1164 SwShellCursor
* pShellCursor
= pWrtShell
->getShellCursor(false);
1166 pWrtShell
->SelAll();
1167 SwTextNode
& rStart
= dynamic_cast<SwTextNode
&>(pShellCursor
->Start()->GetNode());
1169 // The field is now editable like any text, thus the field content "New value" shows up for the cursor.
1170 CPPUNIT_ASSERT_EQUAL(OUString("inputfield: " + OUStringChar(CH_TXT_ATR_INPUTFIELDSTART
)
1171 + "New value" + OUStringChar(CH_TXT_ATR_INPUTFIELDEND
)),
1175 CPPUNIT_TEST_FIXTURE(Test
, testTdf133459
)
1177 createSwDoc("tdf133459.odt");
1178 // Test that the number format was correctly imported, and used by both fields.
1179 uno::Reference
<text::XTextFieldsSupplier
> xTextFieldsSupplier(mxComponent
, uno::UNO_QUERY
);
1180 uno::Reference
<container::XEnumeration
> xFields(xTextFieldsSupplier
->getTextFields()->createEnumeration());
1183 uno::Reference
<text::XTextField
> xField(xFields
->nextElement(), uno::UNO_QUERY
);
1184 const OUString
sPresentation(xField
->getPresentation(false));
1185 const sal_Int32
nFormat(getProperty
<sal_Int32
>(xField
, "NumberFormat"));
1186 CPPUNIT_ASSERT_EQUAL(sal_True
, getProperty
<sal_Bool
>(xField
, "IsFixedLanguage"));
1189 xField
.set(xFields
->nextElement(), uno::UNO_QUERY
);
1190 CPPUNIT_ASSERT_EQUAL(sPresentation
, xField
->getPresentation(false));
1191 CPPUNIT_ASSERT_EQUAL(nFormat
, getProperty
<sal_Int32
>(xField
, "NumberFormat"));
1192 CPPUNIT_ASSERT_EQUAL(sal_True
, getProperty
<sal_Bool
>(xField
, "IsFixedLanguage"));
1194 // Test the number format itself
1195 uno::Reference
<util::XNumberFormatsSupplier
> xNumberFormatsSupplier(mxComponent
, uno::UNO_QUERY
);
1196 uno::Reference
<beans::XPropertySet
> xFormat(xNumberFormatsSupplier
->getNumberFormats()->getByKey(nFormat
));
1197 lang::Locale
aLocale(getProperty
<lang::Locale
>(xFormat
, "Locale"));
1198 CPPUNIT_ASSERT_EQUAL(OUString("ru"), aLocale
.Language
);
1199 CPPUNIT_ASSERT_EQUAL(OUString("RU"), aLocale
.Country
);
1200 CPPUNIT_ASSERT_EQUAL(OUString("QQ YYYY"), getProperty
<OUString
>(xFormat
, "FormatString"));
1203 CPPUNIT_TEST_FIXTURE(Test
, testTdf134971
)
1205 createSwDoc("tdf134971a.odt");
1206 // now insert 2nd file somewhere - insertDocumentFromURL should
1207 // _not_ touch pool defaults
1208 uno::Sequence
<beans::PropertyValue
> aPropertyValues
= comphelper::InitPropertySequence(
1210 {"Name", uno::Any(createFileURL(u
"tdf134971b.odt"))},
1211 {"Filter", uno::Any(OUString("writer8"))},
1213 dispatchCommand(mxComponent
, ".uno:InsertDoc", aPropertyValues
);
1215 // tdf134971b re-defines default font as "Liberation Sans" - make sure this stays
1216 // Arial in final doc:
1218 uno::Reference
<container::XNameAccess
> xParaStyles(getStyles("ParagraphStyles"));
1219 uno::Reference
<beans::XPropertySet
> xStyle1(xParaStyles
->getByName(
1220 "Standard"), uno::UNO_QUERY
);
1221 xStyle1
->getPropertyValue("CharFontName") >>= sString
;
1222 CPPUNIT_ASSERT_EQUAL(OUString("Arial"), sString
);
1225 CPPUNIT_TEST_FIXTURE(Test
, testTdf151375
)
1229 uno::Reference
<text::XTextDocument
> xTextDocument(mxComponent
, uno::UNO_QUERY
);
1230 uno::Reference
<text::XText
> xText
= xTextDocument
->getText();
1231 uno::Reference
<document::XDocumentInsertable
> xCursor(xText
->createTextCursorByRange(xText
->getStart()), uno::UNO_QUERY
);
1233 // Without the fix in place, this test would have crashed here
1234 xCursor
->insertDocumentFromURL(createFileURL(u
"tdf151375.ott"), {});
1236 uno::Reference
<text::XTextFramesSupplier
> const xTextFramesSupplier(mxComponent
, uno::UNO_QUERY
);
1237 uno::Reference
<container::XIndexAccess
> const xIndexAccess(xTextFramesSupplier
->getTextFrames(), uno::UNO_QUERY
);
1238 CPPUNIT_ASSERT_EQUAL(sal_Int32(7), xIndexAccess
->getCount());
1241 CPPUNIT_TEST_FIXTURE(Test
, testTdf138879
)
1245 uno::Sequence
<beans::PropertyValue
> aPropertyValues
= comphelper::InitPropertySequence(
1247 {"Name", uno::Any(createFileURL(u
"tdf138879.odt"))},
1248 {"Filter", uno::Any(OUString("writer8"))},
1250 dispatchCommand(mxComponent
, ".uno:InsertDoc", aPropertyValues
);
1252 // Without the fix in place, this test would have failed with
1253 // - Expected: Heading 1
1254 // - Actual : Standard
1255 CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
1256 getProperty
<OUString
>(getParagraph(1), "ParaStyleName"));
1259 CPPUNIT_TEST_FIXTURE(Test
, testPasteFirstParaDirectFormat
)
1263 // Set some direct formatting on the first paragraph, but leave paragraph adjust at its
1265 uno::Reference
<beans::XPropertySet
> xParagraph(getParagraph(1), uno::UNO_QUERY
);
1266 xParagraph
->setPropertyValue("PageNumberOffset", uno::Any(static_cast<sal_Int16
>(0)));
1270 uno::Reference
<text::XTextDocument
> xTextDocument(mxComponent
, uno::UNO_QUERY
);
1271 uno::Reference
<text::XText
> xText
= xTextDocument
->getText();
1272 uno::Reference
<document::XDocumentInsertable
> xCursor(xText
->createTextCursorByRange(xText
->getStart()), uno::UNO_QUERY
);
1273 xCursor
->insertDocumentFromURL(createFileURL(u
"paste-first-para-direct-format.odt"), {});
1275 // Without the accompanying fix in place, this test would have failed with:
1276 // - Expected: 3 (center)
1277 // - Actual : 0 (left)
1278 // i.e. the inserted document's first paragraph's paragraph formatting was lost.
1279 uno::Reference
<beans::XPropertySet
> xParagraph(getParagraph(1), uno::UNO_QUERY
);
1280 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16
>(style::ParagraphAdjust_CENTER
),
1281 getProperty
<sal_Int16
>(xParagraph
, "ParaAdjust"));
1284 CPPUNIT_TEST_FIXTURE(Test
, testVerticallyMergedCellBorder
)
1286 // Given a document with two cells, vertically merged, when loading the document:
1287 createSwDoc("vmerge-cell-border.odt");
1288 SwDoc
* pDoc
= getSwDoc();
1290 // Then make sure that the first cell has a right border while the second has no right border:
1291 SwDocShell
* pDocShell
= pDoc
->GetDocShell();
1292 SwWrtShell
* pWrtShell
= pDocShell
->GetWrtShell();
1293 pWrtShell
->Down(/*bSelect=*/false, /*nCount=*/1);
1294 SwShellCursor
* pShellCursor
= pWrtShell
->getShellCursor(/*bBlock=*/false);
1295 SwStartNode
* pA1
= pShellCursor
->Start()->GetNode().StartOfSectionNode();
1296 const SwAttrSet
& rA1Set
= pA1
->GetTableBox()->GetFrameFormat()->GetAttrSet();
1297 CPPUNIT_ASSERT(rA1Set
.GetBox().GetRight());
1298 SwNodeIndex
aA2(*pA1
->EndOfSectionNode(), 1);
1299 const SwAttrSet
& rA2Set
= aA2
.GetNode().GetTableBox()->GetFrameFormat()->GetAttrSet();
1301 // Without the accompanying fix in place, this test would have failed, as the A2 cell also had a
1302 // right border, even if <table:covered-table-cell table:style-name="..."> explicitly disabled
1304 CPPUNIT_ASSERT(!rA2Set
.GetBox().GetRight());
1306 // Given this document model, when exporting to ODT:
1309 // Then make sure the covered cell has a style.
1310 xmlDocUniquePtr pXmlSettings
= parseExport("content.xml");
1311 // Without the accompanying fix in place, this test would have failed with:
1312 // - In <...>, XPath '//table:covered-table-cell' no attribute 'style-name' exist
1313 assertXPath(pXmlSettings
, "//table:covered-table-cell", "style-name", "Table1.A2");
1316 CPPUNIT_TEST_FIXTURE(Test
, testPageAnchorZIndexFirstPage
)
1318 createSwDoc("PageAnchorZIndexFirstPage.fodt");
1320 CPPUNIT_ASSERT_EQUAL_MESSAGE("Image1 index not 0",
1321 sal_Int32(0), getProperty
<sal_Int32
>(getShapeByName(u
"Image1"), "ZOrder"));
1322 CPPUNIT_ASSERT_EQUAL_MESSAGE("Image2 index not 1",
1323 sal_Int32(1), getProperty
<sal_Int32
>(getShapeByName(u
"Image2"), "ZOrder"));
1324 CPPUNIT_ASSERT_EQUAL_MESSAGE("Shape1 index not 2",
1325 sal_Int32(2), getProperty
<sal_Int32
>(getShapeByName(u
"Shape1"), "ZOrder"));
1326 CPPUNIT_ASSERT_EQUAL_MESSAGE("Shape2 index not 3",
1327 sal_Int32(3), getProperty
<sal_Int32
>(getShapeByName(u
"Shape2"), "ZOrder"));
1330 CPPUNIT_TEST_FIXTURE(Test
, testPageAnchorZIndexSecondPage
)
1332 createSwDoc("PageAnchorZIndexSecondPage.fodt");
1334 CPPUNIT_ASSERT_EQUAL_MESSAGE("Image1 index not 0",
1335 sal_Int32(0), getProperty
<sal_Int32
>(getShapeByName(u
"Image1"), "ZOrder"));
1336 CPPUNIT_ASSERT_EQUAL_MESSAGE("Image2 index not 1",
1337 sal_Int32(1), getProperty
<sal_Int32
>(getShapeByName(u
"Image2"), "ZOrder"));
1338 CPPUNIT_ASSERT_EQUAL_MESSAGE("Shape1 index not 2",
1339 sal_Int32(2), getProperty
<sal_Int32
>(getShapeByName(u
"Shape1"), "ZOrder"));
1340 CPPUNIT_ASSERT_EQUAL_MESSAGE("Shape2 index not 3",
1341 sal_Int32(3), getProperty
<sal_Int32
>(getShapeByName(u
"Shape2"), "ZOrder"));
1344 CPPUNIT_TEST_FIXTURE(Test
, testTdf146257
)
1346 createSwDoc("tdf146257.odt");
1348 // First list should contain no labels
1350 uno::Reference
<beans::XPropertySet
> xPara(getParagraph(2), uno::UNO_QUERY
);
1351 CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty
<OUString
>(xPara
, "ListLabelString"));
1354 uno::Reference
<beans::XPropertySet
> xPara(getParagraph(3), uno::UNO_QUERY
);
1355 CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty
<OUString
>(xPara
, "ListLabelString"));
1358 uno::Reference
<beans::XPropertySet
> xPara(getParagraph(4), uno::UNO_QUERY
);
1359 CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty
<OUString
>(xPara
, "ListLabelString"));
1361 // For second list ensure second level empty and third level should not contain extra dots
1363 uno::Reference
<beans::XPropertySet
> xPara(getParagraph(6), uno::UNO_QUERY
);
1364 CPPUNIT_ASSERT_EQUAL(OUString("1"), getProperty
<OUString
>(xPara
, "ListLabelString"));
1367 uno::Reference
<beans::XPropertySet
> xPara(getParagraph(7), uno::UNO_QUERY
);
1368 CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty
<OUString
>(xPara
, "ListLabelString"));
1371 uno::Reference
<beans::XPropertySet
> xPara(getParagraph(8), uno::UNO_QUERY
);
1372 CPPUNIT_ASSERT_EQUAL(OUString("1.1"), getProperty
<OUString
>(xPara
, "ListLabelString"));
1376 CPPUNIT_TEST_FIXTURE(Test
, testTdf146597
)
1378 createSwDoc("tdf146597.odt");
1379 // This was crashed before.
1382 // just care that it doesn't crash/assert
1383 CPPUNIT_TEST_FIXTURE(Test
, testForcepoint101
)
1385 createSwDoc("forcepoint101.fodt");
1388 // just care that it doesn't crash/assert
1389 CPPUNIT_TEST_FIXTURE(Test
, testForcepoint108
)
1391 //load would assert because it fails to load entirely, like testMathMalformedXml
1392 mxComponent
= mxDesktop
->loadComponentFromURL(createFileURL(u
"forcepoint108.fodt"), "_default", 0, {});
1397 static void runWindowsFileZoneTests(css::uno::Reference
<css::frame::XDesktop2
> const & aDesktop
,
1398 const OUString
& sFileName
, sal_Int32 configValue
, sal_Int32 zoneId
,
1399 bool expectedResult
)
1401 // Set desired configuration params
1402 auto xChanges
= comphelper::ConfigurationChanges::create();
1403 T::set(configValue
, xChanges
);
1406 // Set Windows Security Zone for temp file
1407 sal::systools::COMReference
<IZoneIdentifier
> pZoneId
;
1408 pZoneId
.CoCreateInstance(CLSID_PersistentZoneIdentifier
);
1410 // ignore setting of Zone 0, since at least for Windows Server
1411 // setups, that always leads to E_ACCESSDENIED - presumably since
1412 // the file is already local?
1414 // See below for the workaround (calling tests for ZONE_LOCAL
1418 CPPUNIT_ASSERT(SUCCEEDED(pZoneId
->SetId(zoneId
)));
1419 sal::systools::COMReference
<IPersistFile
> pPersist(pZoneId
, sal::systools::COM_QUERY_THROW
);
1420 OUString sTempFileWinPath
;
1421 osl::FileBase::getSystemPathFromFileURL(sFileName
, sTempFileWinPath
);
1423 SUCCEEDED(pPersist
->Save(reinterpret_cast<LPCOLESTR
>(sTempFileWinPath
.getStr()), TRUE
)));
1426 // Load doc with default for UI settings: do not suppress macro
1427 uno::Sequence
<beans::PropertyValue
> aLoadArgs
{ comphelper::makePropertyValue(
1428 "MacroExecutionMode", css::document::MacroExecMode::USE_CONFIG
) };
1429 auto aComponent
= aDesktop
->loadComponentFromURL(sFileName
, "_default", 0, aLoadArgs
);
1431 // Are macro enabled in doc?
1432 SwXTextDocument
* pTextDoc
= dynamic_cast<SwXTextDocument
*>(aComponent
.get());
1433 CPPUNIT_ASSERT_EQUAL(expectedResult
, bool(pTextDoc
->getAllowMacroExecution()));
1435 aComponent
->dispose();
1439 CPPUNIT_TEST_FIXTURE(Test
, testWindowsFileZone
)
1441 // This makes sense only for Windows
1443 // Create a temp copy of zone test file
1444 utl::TempFileNamed aTempFile
;
1445 aTempFile
.EnableKillingFile();
1446 SvStream
& aStreamDst
= *aTempFile
.GetStream(StreamMode::WRITE
);
1447 SvFileStream
aStreamSrc(createFileURL(u
"ZoneMacroTest.odt"), StreamMode::READ
);
1448 aStreamDst
.WriteStream(aStreamSrc
);
1449 aTempFile
.CloseStream();
1451 // Tweak macro security to 1
1452 SvtSecurityOptions::SetMacroSecurityLevel(1);
1454 // Run all tests: set for temp file security zone and then check if macro are enabled
1455 // depending on configuration values for given zone
1456 // There is no easy way to check default (0) variant, so macro are disabled by default in these tests.
1458 // run tests for ZoneLocal first, since runWindowsFileZoneTests
1459 // ignores Zone 0 (see above) - assuming the initial file state is
1460 // local after a copy, we're still triggering the expected
1462 runWindowsFileZoneTests
<
1463 officecfg::Office::Common::Security::Scripting::WindowsSecurityZone::ZoneLocal
>(
1464 mxDesktop
, aTempFile
.GetURL(), 0, 0, false);
1465 runWindowsFileZoneTests
<
1466 officecfg::Office::Common::Security::Scripting::WindowsSecurityZone::ZoneLocal
>(
1467 mxDesktop
, aTempFile
.GetURL(), 1, 0, true);
1468 runWindowsFileZoneTests
<
1469 officecfg::Office::Common::Security::Scripting::WindowsSecurityZone::ZoneLocal
>(
1470 mxDesktop
, aTempFile
.GetURL(), 2, 0, false);
1472 // run tests for other zones (these actually set the Windows
1473 // Security Zone at the file)
1474 runWindowsFileZoneTests
<
1475 officecfg::Office::Common::Security::Scripting::WindowsSecurityZone::ZoneUntrusted
>(
1476 mxDesktop
, aTempFile
.GetURL(), 0, 4, false);
1477 runWindowsFileZoneTests
<
1478 officecfg::Office::Common::Security::Scripting::WindowsSecurityZone::ZoneUntrusted
>(
1479 mxDesktop
, aTempFile
.GetURL(), 1, 4, true);
1480 runWindowsFileZoneTests
<
1481 officecfg::Office::Common::Security::Scripting::WindowsSecurityZone::ZoneUntrusted
>(
1482 mxDesktop
, aTempFile
.GetURL(), 2, 4, false);
1484 runWindowsFileZoneTests
<
1485 officecfg::Office::Common::Security::Scripting::WindowsSecurityZone::ZoneInternet
>(
1486 mxDesktop
, aTempFile
.GetURL(), 0, 3, false);
1487 runWindowsFileZoneTests
<
1488 officecfg::Office::Common::Security::Scripting::WindowsSecurityZone::ZoneInternet
>(
1489 mxDesktop
, aTempFile
.GetURL(), 1, 3, true);
1490 runWindowsFileZoneTests
<
1491 officecfg::Office::Common::Security::Scripting::WindowsSecurityZone::ZoneInternet
>(
1492 mxDesktop
, aTempFile
.GetURL(), 2, 3, false);
1494 runWindowsFileZoneTests
<
1495 officecfg::Office::Common::Security::Scripting::WindowsSecurityZone::ZoneTrusted
>(
1496 mxDesktop
, aTempFile
.GetURL(), 0, 2, false);
1497 runWindowsFileZoneTests
<
1498 officecfg::Office::Common::Security::Scripting::WindowsSecurityZone::ZoneTrusted
>(
1499 mxDesktop
, aTempFile
.GetURL(), 1, 2, true);
1500 runWindowsFileZoneTests
<
1501 officecfg::Office::Common::Security::Scripting::WindowsSecurityZone::ZoneTrusted
>(
1502 mxDesktop
, aTempFile
.GetURL(), 2, 2, false);
1504 runWindowsFileZoneTests
<
1505 officecfg::Office::Common::Security::Scripting::WindowsSecurityZone::ZoneIntranet
>(
1506 mxDesktop
, aTempFile
.GetURL(), 0, 1, false);
1507 runWindowsFileZoneTests
<
1508 officecfg::Office::Common::Security::Scripting::WindowsSecurityZone::ZoneIntranet
>(
1509 mxDesktop
, aTempFile
.GetURL(), 1, 1, true);
1510 runWindowsFileZoneTests
<
1511 officecfg::Office::Common::Security::Scripting::WindowsSecurityZone::ZoneIntranet
>(
1512 mxDesktop
, aTempFile
.GetURL(), 2, 1, false);
1516 CPPUNIT_TEST_FIXTURE(Test
, testEmptyTrailingSpans
)
1518 createSwDoc("emptyParagraphLoosesFontHeight.fodt");
1520 CPPUNIT_ASSERT_EQUAL(3, getParagraphs());
1522 auto xPara2
= getParagraph(2);
1523 CPPUNIT_ASSERT_EQUAL(float(11), getProperty
<float>(xPara2
, "CharHeight"));
1524 auto xRun
= getRun(xPara2
, 1);
1525 CPPUNIT_ASSERT_EQUAL(float(8), getProperty
<float>(xRun
, "CharHeight"));
1526 // Both empty spans merge -> no more runs
1527 CPPUNIT_ASSERT_THROW(getRun(xPara2
, 2), css::container::NoSuchElementException
);
1529 xmlDocUniquePtr pXmlDoc
= parseLayoutDump();
1531 auto height1
= getXPath(pXmlDoc
, "/root/page/body/txt[1]/infos/bounds", "height").toInt32();
1532 auto height2
= getXPath(pXmlDoc
, "/root/page/body/txt[2]/infos/bounds", "height").toInt32();
1533 CPPUNIT_ASSERT_EQUAL(height1
, height2
);
1534 CPPUNIT_ASSERT_DOUBLES_EQUAL(184, height2
, 1); // allow a bit of room for rounding just in case
1537 CPPUNIT_PLUGIN_IMPLEMENT();
1538 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */