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 <com/sun/star/style/BreakType.hpp>
13 #include <com/sun/star/style/ParagraphAdjust.hpp>
14 #include <com/sun/star/text/WritingMode2.hpp>
15 #include <com/sun/star/text/XDependentTextField.hpp>
16 #include <com/sun/star/text/RubyAdjust.hpp>
17 #include <com/sun/star/text/RubyPosition.hpp>
18 #include <com/sun/star/text/XDocumentIndex.hpp>
19 #include <com/sun/star/drawing/FillStyle.hpp>
20 #include <com/sun/star/text/XTextTable.hpp>
21 #include <com/sun/star/style/TabStop.hpp>
22 #include <com/sun/star/packages/zip/ZipFileAccess.hpp>
24 #include <comphelper/processfactory.hxx>
25 #include <comphelper/sequenceashashmap.hxx>
27 #include <unotxdoc.hxx>
29 #include <o3tl/string_view.hxx>
31 class Test
: public SwModelTestBase
34 Test() : SwModelTestBase(u
"/sw/qa/extras/ooxmlexport/data/"_ustr
, u
"Office Open XML Text"_ustr
) {}
37 DECLARE_OOXMLEXPORT_TEST(testTdf57589_hashColor
, "tdf57589_hashColor.docx")
39 CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_SOLID
, getProperty
<drawing::FillStyle
>(getParagraph(1), u
"FillStyle"_ustr
));
40 CPPUNIT_ASSERT_EQUAL(COL_LIGHTMAGENTA
, getProperty
<Color
>(getParagraph(1), u
"ParaBackColor"_ustr
));
41 CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_NONE
, getProperty
<drawing::FillStyle
>(getParagraph(2), u
"FillStyle"_ustr
));
42 CPPUNIT_ASSERT_EQUAL(COL_AUTO
, getProperty
<Color
>(getParagraph(2), u
"ParaBackColor"_ustr
));
45 DECLARE_OOXMLEXPORT_TEST(testTdf90906_colAuto
, "tdf90906_colAuto.docx")
47 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
48 uno::Reference
<container::XIndexAccess
> xTables(xTextTablesSupplier
->getTextTables(), uno::UNO_QUERY
);
49 uno::Reference
<text::XTextTable
> xTable(xTables
->getByIndex(0), uno::UNO_QUERY
);
50 uno::Reference
<text::XTextRange
> xCell(xTable
->getCellByName(u
"A1"_ustr
), uno::UNO_QUERY
);
51 uno::Reference
<container::XEnumerationAccess
> xParaEnumAccess(xCell
->getText(), uno::UNO_QUERY
);
52 uno::Reference
<container::XEnumeration
> xParaEnum
= xParaEnumAccess
->createEnumeration();
53 uno::Reference
<text::XTextRange
> xPara(xParaEnum
->nextElement(), uno::UNO_QUERY
);
54 CPPUNIT_ASSERT_EQUAL(COL_AUTO
, getProperty
<Color
>(getRun(xPara
, 1, u
"Nazwa"_ustr
), u
"CharBackColor"_ustr
));
57 DECLARE_OOXMLEXPORT_TEST(testTdf90906_colAutoB
, "tdf90906_colAutoB.docx")
59 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
60 uno::Reference
<container::XIndexAccess
> xTables(xTextTablesSupplier
->getTextTables(), uno::UNO_QUERY
);
61 uno::Reference
<text::XTextTable
> xTable(xTables
->getByIndex(0), uno::UNO_QUERY
);
63 uno::Reference
<table::XCell
> xCell
= xTable
->getCellByName(u
"A1"_ustr
);
64 CPPUNIT_ASSERT_EQUAL(COL_LIGHTGREEN
, getProperty
<Color
>(xCell
, u
"BackColor"_ustr
));
65 xCell
.set(xTable
->getCellByName(u
"A2"_ustr
));
66 CPPUNIT_ASSERT_EQUAL(COL_AUTO
, getProperty
<Color
>(xCell
, u
"BackColor"_ustr
));
67 xCell
.set(xTable
->getCellByName(u
"B1"_ustr
));
68 CPPUNIT_ASSERT_EQUAL(COL_AUTO
, getProperty
<Color
>(xCell
, u
"BackColor"_ustr
));
69 xCell
.set(xTable
->getCellByName(u
"B2"_ustr
));
70 CPPUNIT_ASSERT_EQUAL(COL_LIGHTBLUE
, getProperty
<Color
>(xCell
, u
"BackColor"_ustr
));
72 uno::Reference
<text::XTextRange
> xText(getParagraph(2, u
"Paragraphs too"_ustr
));
73 CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_NONE
, getProperty
<drawing::FillStyle
>(xText
, u
"FillStyle"_ustr
));
74 CPPUNIT_ASSERT_EQUAL(COL_AUTO
, getProperty
<Color
>(xText
, u
"ParaBackColor"_ustr
));
77 CPPUNIT_TEST_FIXTURE(Test
, testTdf92524_autoColor
)
79 loadAndReload("tdf92524_autoColor.doc");
80 CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_NONE
, getProperty
<drawing::FillStyle
>(getParagraph(1), u
"FillStyle"_ustr
));
81 CPPUNIT_ASSERT_EQUAL(COL_AUTO
, getProperty
<Color
>(getParagraph(1), u
"ParaBackColor"_ustr
));
84 CPPUNIT_TEST_FIXTURE(Test
, testTdf116436_rowFill
)
86 loadAndReload("tdf116436_rowFill.odt");
87 CPPUNIT_ASSERT_EQUAL(1, getPages());
88 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
89 uno::Reference
<container::XIndexAccess
> xTables(xTextTablesSupplier
->getTextTables(), uno::UNO_QUERY
);
90 uno::Reference
<text::XTextTable
> xTable(xTables
->getByIndex(0), uno::UNO_QUERY
);
91 uno::Reference
<table::XCell
> xCell
= xTable
->getCellByName(u
"A1"_ustr
);
92 CPPUNIT_ASSERT_EQUAL(Color(0xF8DF7C), getProperty
<Color
>(xCell
, u
"BackColor"_ustr
));
95 DECLARE_OOXMLEXPORT_TEST(testTdf121665_back2backColumnBreaks
, "tdf121665_back2backColumnBreaks.docx")
97 CPPUNIT_ASSERT_EQUAL_MESSAGE("Column break type",
98 style::BreakType_COLUMN_BEFORE
, getProperty
<style::BreakType
>(getParagraph(2), u
"BreakType"_ustr
));
101 CPPUNIT_TEST_FIXTURE(Test
, testTdf126795_TabsRelativeToIndent0
)
103 loadAndReload("tdf126795_TabsRelativeToIndent0.odt");
104 CPPUNIT_ASSERT_EQUAL(1, getPages());
105 uno::Sequence
< style::TabStop
> stops
= getProperty
< uno::Sequence
<style::TabStop
> >(getParagraph( 2 ), u
"ParaTabStops"_ustr
);
106 CPPUNIT_ASSERT_EQUAL( sal_Int32(1), stops
.getLength());
107 CPPUNIT_ASSERT_EQUAL( css::style::TabAlign_LEFT
, stops
[ 0 ].Alignment
);
108 CPPUNIT_ASSERT_EQUAL( sal_Int32(499), stops
[ 0 ].Position
);
111 CPPUNIT_TEST_FIXTURE(Test
, testTdf126795_TabsRelativeToIndent1
)
113 loadAndReload("tdf126795_TabsRelativeToIndent1.odt");
114 CPPUNIT_ASSERT_EQUAL(1, getPages());
115 uno::Sequence
< style::TabStop
> stops
= getProperty
< uno::Sequence
<style::TabStop
> >(getParagraph( 2 ), u
"ParaTabStops"_ustr
);
116 CPPUNIT_ASSERT_EQUAL( sal_Int32(1), stops
.getLength());
117 CPPUNIT_ASSERT_EQUAL( css::style::TabAlign_LEFT
, stops
[ 0 ].Alignment
);
118 CPPUNIT_ASSERT_EQUAL( sal_Int32(499), stops
[ 0 ].Position
);
121 DECLARE_OOXMLEXPORT_TEST(testTdf46938_clearTabStop
, "tdf46938_clearTabStop.docx")
123 // Number of tabstops should be zero, overriding the one in the style
124 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty
< uno::Sequence
<style::TabStop
> >(getParagraph(1), u
"ParaTabStops"_ustr
).getLength());
127 DECLARE_OOXMLEXPORT_TEST(testTdf63561_clearTabs
, "tdf63561_clearTabs.docx")
129 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), getProperty
< uno::Sequence
<style::TabStop
> >(getParagraph(1), u
"ParaTabStops"_ustr
).getLength());
130 CPPUNIT_ASSERT_EQUAL(sal_Int32(7), getProperty
< uno::Sequence
<style::TabStop
> >(getParagraph(3), u
"ParaTabStops"_ustr
).getLength());
131 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), getProperty
< uno::Sequence
<style::TabStop
> >(getParagraph(4), u
"ParaTabStops"_ustr
).getLength());
134 DECLARE_OOXMLEXPORT_TEST(testTdf63561_clearTabs2
, "tdf63561_clearTabs2.docx")
136 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getProperty
< uno::Sequence
<style::TabStop
> >(getParagraph(1), u
"ParaTabStops"_ustr
).getLength());
137 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), getProperty
< uno::Sequence
<style::TabStop
> >(getParagraph(3), u
"ParaTabStops"_ustr
).getLength());
138 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), getProperty
< uno::Sequence
<style::TabStop
> >(getParagraph(4), u
"ParaTabStops"_ustr
).getLength());
141 DECLARE_OOXMLEXPORT_TEST(testTdf124384
, "tdf124384.docx")
143 // There should be no crash during loading of the document
144 // so, let's check just how much pages we have
145 CPPUNIT_ASSERT_EQUAL(1, getPages());
148 CPPUNIT_TEST_FIXTURE(Test
, testTdf121456_tabsOffset
)
150 loadAndReload("tdf121456_tabsOffset.odt");
151 for (int i
=2; i
<8; i
++)
153 uno::Sequence
< style::TabStop
> stops
= getProperty
< uno::Sequence
<style::TabStop
> >(getParagraph( i
), u
"ParaTabStops"_ustr
);
154 CPPUNIT_ASSERT_EQUAL( sal_Int32(1), stops
.getLength());
155 CPPUNIT_ASSERT_EQUAL( css::style::TabAlign_RIGHT
, stops
[ 0 ].Alignment
);
156 CPPUNIT_ASSERT_EQUAL( sal_Int32(17000), stops
[ 0 ].Position
);
160 // tdf#121561: make sure w:sdt/w:sdtContent around TOC is written during ODT->DOCX conversion
161 CPPUNIT_TEST_FIXTURE(Test
, testTdf121561_tocTitle
)
163 loadAndSave("tdf121456_tabsOffset.odt");
164 xmlDocUniquePtr pXmlDoc
= parseExport(u
"word/document.xml"_ustr
);
165 assertXPathContent(pXmlDoc
, "/w:document/w:body/w:sdt/w:sdtContent/w:p/w:r/w:t", u
"Inhaltsverzeichnis");
166 assertXPathContent(pXmlDoc
, "/w:document/w:body/w:sdt/w:sdtContent/w:p/w:r/w:instrText", u
" TOC \\f \\o \"1-9\" \\h");
167 assertXPath(pXmlDoc
, "/w:document/w:body/w:sdt/w:sdtPr/w:docPartObj/w:docPartGallery", "val", u
"Table of Contents");
168 assertXPath(pXmlDoc
, "/w:document/w:body/w:sdt/w:sdtPr/w:docPartObj/w:docPartUnique", 1);
171 CPPUNIT_TEST_FIXTURE(Test
, testTdf129525
)
173 loadAndSave("tdf129525.rtf");
174 xmlDocUniquePtr pXmlDoc
= parseExport(u
"word/document.xml"_ustr
);
175 assertXPathContent(pXmlDoc
, "/w:document/w:body/w:sdt/w:sdtContent/w:p[1]/w:r[4]/w:t", u
"Overview");
176 assertXPathContent(pXmlDoc
, "/w:document/w:body/w:sdt/w:sdtContent/w:p[1]/w:r[5]/w:t", u
"3");
177 assertXPathContent(pXmlDoc
, "/w:document/w:body/w:sdt/w:sdtContent/w:p[2]/w:r[1]/w:t", u
"More detailed description");
178 assertXPathContent(pXmlDoc
, "/w:document/w:body/w:sdt/w:sdtContent/w:p[2]/w:r[2]/w:t", u
"4");
181 // Related issue tdf#121561: w:sdt/w:sdtContent around TOC
182 DECLARE_OOXMLEXPORT_TEST(testTdf124106
, "tdf121456.docx")
184 uno::Reference
<text::XTextDocument
> textDocument(mxComponent
, uno::UNO_QUERY
);
185 uno::Reference
<text::XText
> text
= textDocument
->getText();
186 // -1 if the 'Y' character does not occur
187 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), text
->getString().indexOf('Y'));
188 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), text
->getString().indexOf('y'));
191 CPPUNIT_TEST_FIXTURE(Test
, testTdf121561_tocTitleDocx
)
193 loadAndSave("tdf121456_tabsOffset.odt");
194 CPPUNIT_ASSERT_EQUAL(7, getPages());
195 xmlDocUniquePtr pXmlDoc
= parseExport(u
"word/document.xml"_ustr
);
198 uno::Reference
<text::XDocumentIndexesSupplier
> xIndexSupplier(mxComponent
, uno::UNO_QUERY
);
199 uno::Reference
<container::XIndexAccess
> xIndexes
= xIndexSupplier
->getDocumentIndexes( );
200 uno::Reference
<text::XDocumentIndex
> xTOCIndex(xIndexes
->getByIndex(0), uno::UNO_QUERY
);
202 // ensure TOC title was set in TOC properties
203 CPPUNIT_ASSERT_EQUAL(u
"Inhaltsverzeichnis"_ustr
, getProperty
<OUString
>(xTOCIndex
, u
"Title"_ustr
));
205 // ensure TOC end-field mark is placed inside TOC section
206 assertXPath(pXmlDoc
, "/w:document/w:body/w:sdt/w:sdtContent/w:p[16]/w:r/w:fldChar", "fldCharType", u
"end");
209 DECLARE_OOXMLEXPORT_TEST(testTdf106174_rtlParaAlign
, "tdf106174_rtlParaAlign.docx")
211 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_CENTER
), getProperty
<sal_Int16
>(getParagraph(1), u
"ParaAdjust"_ustr
));
212 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_CENTER
), getProperty
<sal_Int16
>(getParagraph(2), u
"ParaAdjust"_ustr
));
213 uno::Reference
<beans::XPropertySet
> xPropertySet(getStyles(u
"ParagraphStyles"_ustr
)->getByName(u
"Another paragraph aligned to right"_ustr
), uno::UNO_QUERY
);
214 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT
), getProperty
<sal_Int16
>(xPropertySet
, u
"ParaAdjust"_ustr
));
215 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT
), getProperty
<sal_Int16
>(getParagraph(3), u
"ParaAdjust"_ustr
));
216 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT
), getProperty
<sal_Int16
>(getParagraph(4), u
"ParaAdjust"_ustr
));
217 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT
), getProperty
<sal_Int16
>(getParagraph(5), u
"ParaAdjust"_ustr
));
218 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_LEFT
), getProperty
<sal_Int16
>(getParagraph(6), u
"ParaAdjust"_ustr
));
219 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT
), getProperty
<sal_Int16
>(getParagraph(7), u
"ParaAdjust"_ustr
));
220 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT
), getProperty
<sal_Int16
>(getParagraph(8), u
"ParaAdjust"_ustr
));
221 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_LEFT
), getProperty
<sal_Int16
>(getParagraph(9), u
"ParaAdjust"_ustr
));
222 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_LEFT
), getProperty
<sal_Int16
>(getParagraph(10), u
"ParaAdjust"_ustr
));
223 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT
), getProperty
<sal_Int16
>(getParagraph(11), u
"ParaAdjust"_ustr
));
224 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_LEFT
), getProperty
<sal_Int16
>(getParagraph(12), u
"ParaAdjust"_ustr
));
225 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_LEFT
), getProperty
<sal_Int16
>(getParagraph(13), u
"ParaAdjust"_ustr
));
226 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT
), getProperty
<sal_Int16
>(getParagraph(14), u
"ParaAdjust"_ustr
));
229 DECLARE_OOXMLEXPORT_TEST(testTdf82065_Ind_start_strict
, "tdf82065_Ind_start_strict.docx")
231 uno::Reference
<beans::XPropertySet
> xPropertySet(getStyles(u
"NumberingStyles"_ustr
)->getByName(u
"WWNum1"_ustr
), uno::UNO_QUERY
);
232 uno::Reference
<container::XIndexAccess
> xLevels(xPropertySet
->getPropertyValue(u
"NumberingRules"_ustr
), uno::UNO_QUERY
);
233 uno::Sequence
<beans::PropertyValue
> aProps
;
234 xLevels
->getByIndex(0) >>= aProps
; // 1st level
235 bool bFoundIndentAt
= false;
236 for (beans::PropertyValue
const& rProp
: aProps
)
238 if (rProp
.Name
== "IndentAt")
240 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("IndentAt", double(6001), rProp
.Value
.get
<double>(), 10 );
241 bFoundIndentAt
= true;
244 CPPUNIT_ASSERT_EQUAL_MESSAGE("IndentAt defined", true, bFoundIndentAt
);
247 CPPUNIT_TEST_FIXTURE(Test
, testTdf76683_negativeTwipsMeasure
)
249 loadAndSave("tdf76683_negativeTwipsMeasure.docx");
250 xmlDocUniquePtr pXmlDoc
= parseExport(u
"word/document.xml"_ustr
);
251 assertXPath(pXmlDoc
, "/w:document/w:body/w:sectPr/w:cols/w:col", 2);
252 sal_uInt32 nColumn1
= getXPath(pXmlDoc
, "/w:document/w:body/w:sectPr/w:cols/w:col[1]", "w").toUInt32();
253 sal_uInt32 nColumn2
= getXPath(pXmlDoc
, "/w:document/w:body/w:sectPr/w:cols/w:col[2]", "w").toUInt32();
254 CPPUNIT_ASSERT( nColumn1
> nColumn2
);
257 DECLARE_OOXMLEXPORT_TEST(testTdf118361_RTLfootnoteSeparator
, "tdf118361_RTLfootnoteSeparator.docx")
259 uno::Any aPageStyle
= getStyles(u
"PageStyles"_ustr
)->getByName(u
"Standard"_ustr
);
260 CPPUNIT_ASSERT_EQUAL_MESSAGE("Footnote separator RTL", sal_Int16(2), getProperty
<sal_Int16
>(aPageStyle
, u
"FootnoteLineAdjust"_ustr
));
263 DECLARE_OOXMLEXPORT_TEST(testTdf115861
, "tdf115861.docx")
265 // Second item in the paragraph enumeration was a table, 2nd paragraph was
267 CPPUNIT_ASSERT_EQUAL(u
"(k)"_ustr
, getParagraph(2)->getString());
270 DECLARE_OOXMLEXPORT_TEST(testTdf67207_MERGEFIELD
, "mailmerge.docx")
272 uno::Reference
<beans::XPropertySet
> xTextField
= getProperty
< uno::Reference
<beans::XPropertySet
> >(getRun(getParagraph(1), 2), u
"TextField"_ustr
);
273 CPPUNIT_ASSERT(xTextField
.is());
274 uno::Reference
<lang::XServiceInfo
> xServiceInfo(xTextField
, uno::UNO_QUERY_THROW
);
275 uno::Reference
<text::XDependentTextField
> xDependent(xTextField
, uno::UNO_QUERY_THROW
);
277 CPPUNIT_ASSERT(xServiceInfo
->supportsService(u
"com.sun.star.text.TextField.Database"_ustr
));
279 xTextField
->getPropertyValue(u
"Content"_ustr
) >>= sValue
;
280 CPPUNIT_ASSERT_EQUAL(u
"«Name»"_ustr
, sValue
);
282 uno::Reference
<beans::XPropertySet
> xFiledMaster
= xDependent
->getTextFieldMaster();
283 uno::Reference
<lang::XServiceInfo
> xFiledMasterServiceInfo(xFiledMaster
, uno::UNO_QUERY_THROW
);
285 CPPUNIT_ASSERT(xFiledMasterServiceInfo
->supportsService(u
"com.sun.star.text.fieldmaster.Database"_ustr
));
287 // Defined properties: DataBaseName, Name, DataTableName, DataColumnName, DependentTextFields, DataCommandType, InstanceName, DataBaseURL
288 CPPUNIT_ASSERT(xFiledMaster
->getPropertyValue(u
"Name"_ustr
) >>= sValue
);
289 CPPUNIT_ASSERT_EQUAL(u
"Name"_ustr
, sValue
);
290 CPPUNIT_ASSERT(xFiledMaster
->getPropertyValue(u
"DataColumnName"_ustr
) >>= sValue
);
291 CPPUNIT_ASSERT_EQUAL(u
"Name"_ustr
, sValue
);
292 CPPUNIT_ASSERT(xFiledMaster
->getPropertyValue(u
"InstanceName"_ustr
) >>= sValue
);
293 CPPUNIT_ASSERT_EQUAL(u
"com.sun.star.text.fieldmaster.DataBase.Name"_ustr
, sValue
);
296 DECLARE_OOXMLEXPORT_TEST(testTdf115719
, "tdf115719.docx")
298 // This was a single page, instead of pushing the textboxes to the second
300 CPPUNIT_ASSERT_EQUAL(2, getPages());
303 DECLARE_OOXMLEXPORT_TEST(testTdf115719b
, "tdf115719b.docx")
305 // This is similar to testTdf115719, but here the left textbox is not aligned "from left, by
306 // 0cm" but simply aligned to left, which is a different codepath.
308 // Without the accompanying fix in place, this test would have failed with:
311 // i.e. the textboxes did not appear on the 2nd page, but everything was on a single page.
312 CPPUNIT_ASSERT_EQUAL(2, getPages());
315 DECLARE_OOXMLEXPORT_TEST(testTdf123243
, "tdf123243.docx")
317 // Without the accompanying fix in place, this test would have failed with 'Expected: 1; Actual:
318 // 2'; i.e. unexpected paragraph margin created 2 pages.
319 CPPUNIT_ASSERT_EQUAL(1, getPages());
322 DECLARE_OOXMLEXPORT_TEST(testTdf116410
, "tdf116410.docx")
324 // Opposite of the above, was 2 pages, should be 1 page.
325 CPPUNIT_ASSERT_EQUAL(1, getPages());
328 DECLARE_OOXMLEXPORT_TEST(testDefaultStyle
, "defaultStyle.docx")
330 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Default Style", u
"Title"_ustr
, getProperty
<OUString
>(getParagraph(1), u
"ParaStyleName"_ustr
) );
331 CPPUNIT_ASSERT_EQUAL(2, getPages());
334 DECLARE_OOXMLEXPORT_TEST(testTdf147115_defaultStyle
, "tdf147115_defaultStyle.docx")
336 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Default Style", u
"Standard"_ustr
, getProperty
<OUString
>(getParagraph(1), u
"ParaStyleName"_ustr
) );
339 DECLARE_OOXMLEXPORT_TEST(testTdf117988
, "tdf117988.docx")
341 CPPUNIT_ASSERT_EQUAL(1, getPages());
344 DECLARE_OOXMLEXPORT_TEST(testTdf94801
, "tdf94801.docx")
346 // This was a 2-page document with unwanted line breaking in table cells, because
347 // the table was narrower, than defined (< 1/100 mm loss during twip to 1/100 mm conversion)
348 CPPUNIT_ASSERT_EQUAL(1, getPages());
351 CPPUNIT_TEST_FIXTURE(Test
, testParagraphSplitOnSectionBorder
)
353 loadAndSave("parasplit-on-section-border.odt");
354 CPPUNIT_ASSERT_EQUAL(2, getPages());
355 xmlDocUniquePtr pXmlDoc
= parseExport(u
"word/document.xml"_ustr
);
357 // Test document has only two paragraphs. After splitting, it should contain
359 assertXPath(pXmlDoc
, "//w:sectPr", 2);
360 assertXPath(pXmlDoc
, "//w:p", 3);
363 CPPUNIT_TEST_FIXTURE(Test
, testTdf44832_testSectionWithDifferentHeader
)
365 loadAndSave("tdf44832_section_new_header.odt");
366 CPPUNIT_ASSERT_EQUAL(2, getPages());
367 xmlDocUniquePtr pXmlDoc
= parseExport(u
"word/document.xml"_ustr
);
368 assertXPath(pXmlDoc
, "/w:document/w:body/w:sectPr/w:headerReference", 1);
371 DECLARE_OOXMLEXPORT_TEST(testSignatureLineShape
, "signature-line-all-props-set.docx")
373 uno::Reference
<drawing::XShape
> xSignatureLineShape
= getShape(1);
374 uno::Reference
<beans::XPropertySet
> xPropSet(xSignatureLineShape
, uno::UNO_QUERY
);
376 bool bIsSignatureLine
;
377 xPropSet
->getPropertyValue(u
"IsSignatureLine"_ustr
) >>= bIsSignatureLine
;
378 CPPUNIT_ASSERT_EQUAL(true, bIsSignatureLine
);
381 xPropSet
->getPropertyValue(u
"SignatureLineShowSignDate"_ustr
) >>= bShowSignDate
;
382 CPPUNIT_ASSERT_EQUAL(true, bShowSignDate
);
385 xPropSet
->getPropertyValue(u
"SignatureLineCanAddComment"_ustr
) >>= bCanAddComment
;
386 CPPUNIT_ASSERT_EQUAL(true, bCanAddComment
);
388 OUString aSignatureLineId
;
389 xPropSet
->getPropertyValue(u
"SignatureLineId"_ustr
) >>= aSignatureLineId
;
390 CPPUNIT_ASSERT_EQUAL(u
"{0EBE47D5-A1BD-4C9E-A52E-6256E5C345E9}"_ustr
, aSignatureLineId
);
392 OUString aSuggestedSignerName
;
393 xPropSet
->getPropertyValue(u
"SignatureLineSuggestedSignerName"_ustr
) >>= aSuggestedSignerName
;
394 CPPUNIT_ASSERT_EQUAL(u
"John Doe"_ustr
, aSuggestedSignerName
);
396 OUString aSuggestedSignerTitle
;
397 xPropSet
->getPropertyValue(u
"SignatureLineSuggestedSignerTitle"_ustr
) >>= aSuggestedSignerTitle
;
398 CPPUNIT_ASSERT_EQUAL(u
"Farmer"_ustr
, aSuggestedSignerTitle
);
400 OUString aSuggestedSignerEmail
;
401 xPropSet
->getPropertyValue(u
"SignatureLineSuggestedSignerEmail"_ustr
) >>= aSuggestedSignerEmail
;
402 CPPUNIT_ASSERT_EQUAL(u
"john@thefarmers.com"_ustr
, aSuggestedSignerEmail
);
404 OUString aSigningInstructions
;
405 xPropSet
->getPropertyValue(u
"SignatureLineSigningInstructions"_ustr
) >>= aSigningInstructions
;
406 CPPUNIT_ASSERT_EQUAL(u
"Check the machines!"_ustr
, aSigningInstructions
);
409 CPPUNIT_TEST_FIXTURE(Test
, testTdf117805
)
411 loadAndSave("tdf117805.odt");
412 CPPUNIT_ASSERT_EQUAL(1, getShapes());
413 CPPUNIT_ASSERT_EQUAL(1, getPages());
414 uno::Reference
<packages::zip::XZipFileAccess2
> xNameAccess
415 = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory
),
416 maTempFile
.GetURL());
417 // This failed, the header was lost. It's still referenced at an incorrect
418 // location in document.xml, though.
419 CPPUNIT_ASSERT(xNameAccess
->hasByName(u
"word/header1.xml"_ustr
));
421 uno::Reference
<text::XText
> textbox(getShape(1), uno::UNO_QUERY
);
422 CPPUNIT_ASSERT_EQUAL(8, getParagraphs(textbox
));
425 DECLARE_OOXMLEXPORT_TEST(testTdf113183
, "tdf113183.docx")
427 // The horizontal positioning of the star shape affected the positioning of
428 // the triangle one, so the triangle was outside the page frame.
429 xmlDocUniquePtr pXmlDoc
= parseLayoutDump();
430 sal_Int32 nPageLeft
= getXPath(pXmlDoc
, "/root/page[1]/infos/bounds", "left").toInt32();
431 sal_Int32 nPageWidth
= getXPath(pXmlDoc
, "/root/page[1]/infos/bounds", "width").toInt32();
433 = getXPath(pXmlDoc
, "/root/page/body/txt/anchored/SwAnchoredDrawObject[2]/bounds", "left")
435 sal_Int32 nShapeWidth
436 = getXPath(pXmlDoc
, "/root/page/body/txt/anchored/SwAnchoredDrawObject[2]/bounds", "width")
438 // Make sure the second triangle shape is within the page bounds (with ~1px tolerance).
439 CPPUNIT_ASSERT_GREATEREQUAL(nShapeLeft
+ nShapeWidth
, nPageLeft
+ nPageWidth
+ 21);
442 DECLARE_OOXMLEXPORT_TEST(testGraphicObjectFliph
, "graphic-object-fliph.docx")
444 CPPUNIT_ASSERT(getProperty
<bool>(getShape(1), u
"HoriMirroredOnEvenPages"_ustr
));
445 CPPUNIT_ASSERT(getProperty
<bool>(getShape(1), u
"HoriMirroredOnOddPages"_ustr
));
448 DECLARE_OOXMLEXPORT_TEST(testTdf113547
, "tdf113547.docx")
450 uno::Reference
<beans::XPropertySet
> xPropertySet(
451 getStyles(u
"NumberingStyles"_ustr
)->getByName(u
"WWNum1"_ustr
), uno::UNO_QUERY
);
452 uno::Reference
<container::XIndexAccess
> xLevels(
453 xPropertySet
->getPropertyValue(u
"NumberingRules"_ustr
), uno::UNO_QUERY
);
454 comphelper::SequenceAsHashMap
aProps(xLevels
->getByIndex(0)); // 1st level
455 // This was 0, first-line left margin of the numbering was lost.
456 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(-635), aProps
[u
"FirstLineIndent"_ustr
].get
<sal_Int32
>());
459 CPPUNIT_TEST_FIXTURE(Test
, testTdf113399
)
461 loadAndReload("tdf113399.doc");
462 // 0 padding was not preserved
463 // In LO 0 is the default, but in OOXML format the default is 254 / 127
464 uno::Reference
<beans::XPropertySet
> xPropSet(getShape(1), uno::UNO_QUERY
);
465 sal_Int32 nPaddingValue
;
466 xPropSet
->getPropertyValue(u
"TextLeftDistance"_ustr
) >>= nPaddingValue
;
467 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(0), nPaddingValue
);
468 xPropSet
->getPropertyValue(u
"TextRightDistance"_ustr
) >>= nPaddingValue
;
469 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(0), nPaddingValue
);
470 xPropSet
->getPropertyValue(u
"TextUpperDistance"_ustr
) >>= nPaddingValue
;
471 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(0), nPaddingValue
);
472 xPropSet
->getPropertyValue(u
"TextLowerDistance"_ustr
) >>= nPaddingValue
;
473 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(0), nPaddingValue
);
476 DECLARE_OOXMLEXPORT_TEST(testTdf114882
, "tdf114882.docx")
478 // fastserializer must not fail assertion because of mismatching elements
481 DECLARE_OOXMLEXPORT_TEST(testTdf49073
, "tdf49073.docx")
483 // test case for Asian phontic guide (ruby text.)
484 sal_Unicode aRuby
[3] = {0x304D,0x3082,0x3093};
485 OUString
sRuby(aRuby
, SAL_N_ELEMENTS(aRuby
));
486 CPPUNIT_ASSERT_EQUAL(sRuby
,getProperty
<OUString
>(getParagraph(1)->getStart(), u
"RubyText"_ustr
));
487 OUString sStyle
= getProperty
<OUString
>( getParagraph(1)->getStart(), u
"RubyCharStyleName"_ustr
);
488 uno::Reference
<beans::XPropertySet
> xPropertySet(getStyles(u
"CharacterStyles"_ustr
)->getByName(sStyle
), uno::UNO_QUERY
);
489 CPPUNIT_ASSERT_EQUAL(5.f
, getProperty
<float>(xPropertySet
, u
"CharHeight"_ustr
));
490 CPPUNIT_ASSERT_EQUAL(sal_Int16(text::RubyAdjust_CENTER
) ,getProperty
<sal_Int16
>(getParagraph(2)->getStart(),u
"RubyAdjust"_ustr
));
491 CPPUNIT_ASSERT_EQUAL(sal_Int16(text::RubyAdjust_BLOCK
) ,getProperty
<sal_Int16
>(getParagraph(3)->getStart(),u
"RubyAdjust"_ustr
));
492 CPPUNIT_ASSERT_EQUAL(sal_Int16(text::RubyAdjust_INDENT_BLOCK
),getProperty
<sal_Int16
>(getParagraph(4)->getStart(),u
"RubyAdjust"_ustr
));
493 CPPUNIT_ASSERT_EQUAL(sal_Int16(text::RubyAdjust_LEFT
) ,getProperty
<sal_Int16
>(getParagraph(5)->getStart(),u
"RubyAdjust"_ustr
));
494 CPPUNIT_ASSERT_EQUAL(sal_Int16(text::RubyAdjust_RIGHT
) ,getProperty
<sal_Int16
>(getParagraph(6)->getStart(),u
"RubyAdjust"_ustr
));
495 CPPUNIT_ASSERT_EQUAL(sal_Int16(text::RubyPosition::INTER_CHARACTER
) ,getProperty
<sal_Int16
>(getParagraph(7)->getStart(),u
"RubyPosition"_ustr
));
498 DECLARE_OOXMLEXPORT_TEST(testTdf114703
, "tdf114703.docx")
500 uno::Reference
<container::XIndexAccess
> xRules
501 = getProperty
<uno::Reference
<container::XIndexAccess
>>(
502 getStyles(u
"NumberingStyles"_ustr
)->getByName(u
"WWNum1"_ustr
), u
"NumberingRules"_ustr
);
503 // This was 0, level override "default" replaced the non-default value from
504 // the abstract level.
505 CPPUNIT_ASSERT_EQUAL(
506 static_cast<sal_Int32
>(-1000),
507 comphelper::SequenceAsHashMap(xRules
->getByIndex(0))[u
"FirstLineIndent"_ustr
].get
<sal_Int32
>());
510 DECLARE_OOXMLEXPORT_TEST(testTdf113258
, "tdf113258.docx")
512 uno::Reference
<text::XTextRange
> xShape(getShape(1), uno::UNO_QUERY
);
513 // This was 494, i.e. automatic spacing resulted in non-zero paragraph top
514 // margin for the first paragraph in a shape.
515 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(0),
516 getProperty
<sal_Int32
>(xShape
->getStart(), u
"ParaTopMargin"_ustr
));
519 DECLARE_OOXMLEXPORT_TEST(testTdf113258_noBeforeAutospacing
, "tdf113258_noBeforeAutospacing.docx")
521 uno::Reference
<text::XTextRange
> xShape(getShape(1), uno::UNO_QUERY
);
522 // This was 0, i.e. disabled automatic spacing still resulted in zero paragraph
523 // top margin for the first paragraph in a shape.
524 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(1764),
525 getProperty
<sal_Int32
>(xShape
->getStart(), u
"ParaTopMargin"_ustr
));
528 DECLARE_OOXMLEXPORT_TEST(testTdf142542_cancelledAutospacing
, "tdf142542_cancelledAutospacing.docx")
530 //Direct formatting disabling autoSpacing must override paragraph-style's autoSpacing.
531 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(0), getProperty
<sal_Int32
>(getParagraph(1), u
"ParaTopMargin"_ustr
));
532 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(0), getProperty
<sal_Int32
>(getParagraph(1), u
"ParaBottomMargin"_ustr
));
535 CPPUNIT_TEST_FIXTURE(Test
, testTdf137655
)
537 loadAndSave("tdf137655.docx");
538 xmlDocUniquePtr pXmlDoc
= parseExport(u
"word/document.xml"_ustr
);
540 assertXPath(pXmlDoc
, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[1]/w:p[1]/w:pPr/w:spacing", "before", u
"0");
541 assertXPath(pXmlDoc
, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[2]/w:p[1]/w:pPr/w:spacing", "before", u
"0");
543 //tdf#142542: ensure that the original beforeAutospacing = 0 is not changed.
544 assertXPath(pXmlDoc
, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[1]/w:p[1]/w:pPr/w:spacing", "beforeAutospacing", u
"0");
547 DECLARE_OOXMLEXPORT_TEST(testTdf120511_eatenSection
, "tdf120511_eatenSection.docx")
549 xmlDocUniquePtr pXmlDoc
= parseLayoutDump();
550 sal_Int32 nHeight
= getXPath(pXmlDoc
, "/root/page[1]/infos/prtBounds", "height").toInt32();
551 sal_Int32 nWidth
= getXPath(pXmlDoc
, "/root/page[1]/infos/prtBounds", "width").toInt32();
552 CPPUNIT_ASSERT_MESSAGE( "Page1 is portrait", nWidth
< nHeight
);
553 nHeight
= getXPath(pXmlDoc
, "/root/page[2]/infos/prtBounds", "height").toInt32();
554 nWidth
= getXPath(pXmlDoc
, "/root/page[2]/infos/prtBounds", "width").toInt32();
555 CPPUNIT_ASSERT_MESSAGE( "Page2 is landscape", nWidth
> nHeight
);
558 DECLARE_OOXMLEXPORT_TEST(testTdf104354
, "tdf104354.docx")
560 uno::Reference
<text::XTextRange
> xShape(getShape(1), uno::UNO_QUERY
);
561 // This was 494, i.e. automatic spacing resulted in non-zero paragraph top
562 // margin for the first paragraph in a text frame.
563 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(0),
564 getProperty
<sal_Int32
>(xShape
->getStart(), u
"ParaTopMargin"_ustr
));
565 // still 494 in the second paragraph
566 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(494),
567 getProperty
<sal_Int32
>(xShape
->getEnd(), u
"ParaTopMargin"_ustr
));
570 DECLARE_OOXMLEXPORT_TEST(testTdf104354_firstParaInSection
, "tdf104354_firstParaInSection.docx")
572 uno::Reference
<text::XFootnotesSupplier
> xFootnotesSupplier(mxComponent
, uno::UNO_QUERY
);
573 uno::Reference
<container::XIndexAccess
> xFootnotes
= xFootnotesSupplier
->getFootnotes();
574 uno::Reference
<text::XText
> xText(xFootnotes
->getByIndex(0), uno::UNO_QUERY
);
575 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(494),
576 getProperty
<sal_Int32
>(getParagraphOfText(1, xText
), u
"ParaTopMargin"_ustr
));
577 CPPUNIT_ASSERT_EQUAL(1, getPages());
580 CPPUNIT_TEST_FIXTURE(Test
, testPageBreak_after
)
582 loadAndReload("pageBreak_after.odt");
583 // The problem was that the page breakAfter put the empty page BEFORE the table
584 xmlDocUniquePtr pDump
= parseLayoutDump();
585 assertXPath(pDump
, "/root/page[1]/body/tab", 1);
586 // There should be two pages actually - a blank page after a page break.
587 CPPUNIT_ASSERT_EQUAL_MESSAGE("Did you fix?? Table should be on page one of two", 1, getPages());
590 DECLARE_OOXMLEXPORT_TEST(testTdf107035
, "tdf107035.docx")
592 // Select the second run containing the page number field
593 auto xPgNumRun
= getRun(getParagraph(1), 2, u
"1"_ustr
);
595 // Check that the page number field colour is set to "automatic".
596 Color nPgNumColour
= getProperty
<Color
>(xPgNumRun
, u
"CharColor"_ustr
);
597 CPPUNIT_ASSERT_EQUAL(COL_AUTO
, nPgNumColour
);
600 DECLARE_OOXMLEXPORT_TEST(testTdf112118_DOCX
, "tdf112118.docx")
602 // The resulting left margin width (2081) differs from its DOC counterpart from ww8export2.cxx,
603 // because DOCX import does two conversions between mm/100 and twips on the route, losing one
604 // twip on the road and arriving with a value that is 2 mm/100 less. I don't see an obvious way
606 static const struct {
607 const char* styleName
;
609 const char* sideName
;
611 sal_Int32 nBorderDistance
;
612 sal_Int32 nBorderWidth
;
614 } styleParams
[] = { // Margin (MS-style), border distance, border width
618 { "Top", 496, 847, 159 }, // 851 twip, 24 pt (from text), 4.5 pt
619 { "Left", 2081, 706, 212 }, // 1701 twip, 20 pt (from text), 6.0 pt
620 { "Bottom", 1401, 564, 35 }, // 1134 twip, 16 pt (from text), 1.0 pt
621 { "Right", 3471, 423, 106 } // 2268 twip, 12 pt (from text), 3.0 pt
627 { "Top", 847, 496, 159 }, // 851 twip, 24 pt (from edge), 4.5 pt
628 { "Left", 706, 2081, 212 }, // 1701 twip, 20 pt (from edge), 6.0 pt
629 { "Bottom", 564, 1401, 35 }, // 1134 twip, 16 pt (from edge), 1.0 pt
630 { "Right", 423, 3471, 106 } // 2268 twip, 12 pt (from edge), 3.0 pt
634 auto xStyles
= getStyles(u
"PageStyles"_ustr
);
636 for (const auto& style
: styleParams
)
638 const OUString sName
= OUString::createFromAscii(style
.styleName
);
639 uno::Reference
<beans::XPropertySet
> xStyle(xStyles
->getByName(sName
), uno::UNO_QUERY_THROW
);
640 for (const auto& side
: style
.sideParams
)
642 const OUString sSide
= OUString::createFromAscii(side
.sideName
);
643 const OString sStage
= style
.styleName
+ OString::Concat(" ") + side
.sideName
;
645 sal_Int32 nMargin
= getProperty
<sal_Int32
>(xStyle
, sSide
+ "Margin");
646 CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(sStage
+ " margin width").getStr(),
647 side
.nMargin
, nMargin
);
649 sal_Int32 nBorderDistance
= getProperty
<sal_Int32
>(xStyle
, sSide
+ "BorderDistance");
650 CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(sStage
+ " border distance").getStr(),
651 side
.nBorderDistance
, nBorderDistance
);
653 table::BorderLine aBorder
= getProperty
<table::BorderLine
>(xStyle
, sSide
+ "Border");
654 CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(sStage
+ " border width").getStr(),
656 sal_Int32(aBorder
.OuterLineWidth
+ aBorder
.InnerLineWidth
+ aBorder
.LineDistance
));
658 // tdf#116472: check that AUTO border color is imported as black
659 CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(sStage
+ " border color").getStr(),
660 sal_Int32(COL_BLACK
), aBorder
.Color
);
665 DECLARE_OOXMLEXPORT_TEST(testTdf82177_outsideCellBorders
, "tdf82177_outsideCellBorders.docx")
667 uno::Reference
<text::XTextTablesSupplier
> xTablesSupplier(mxComponent
, uno::UNO_QUERY
);
668 uno::Reference
<container::XIndexAccess
> xTables(xTablesSupplier
->getTextTables(), uno::UNO_QUERY
);
669 uno::Reference
< text::XTextTable
> xTable( xTables
->getByIndex(0), uno::UNO_QUERY
);
670 uno::Reference
< table::XCell
> xCell
= xTable
->getCellByName( u
"E4"_ustr
);
671 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32
>(0), getProperty
<table::BorderLine2
>(xCell
, u
"TopBorder"_ustr
).LineWidth
);
672 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32
>(0), getProperty
<table::BorderLine2
>(xCell
, u
"LeftBorder"_ustr
).LineWidth
);
675 DECLARE_OOXMLEXPORT_TEST(testTdf82177_insideCellBorders
, "tdf82177_insideCellBorders.docx")
677 uno::Reference
<text::XTextTablesSupplier
> xTablesSupplier(mxComponent
, uno::UNO_QUERY
);
678 uno::Reference
<container::XIndexAccess
> xTables(xTablesSupplier
->getTextTables(), uno::UNO_QUERY
);
679 uno::Reference
< text::XTextTable
> xTable( xTables
->getByIndex(0), uno::UNO_QUERY
);
680 uno::Reference
< table::XCell
> xCell
= xTable
->getCellByName( u
"E4"_ustr
);
681 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32
>(0), getProperty
<table::BorderLine2
>(xCell
, u
"TopBorder"_ustr
).LineWidth
);
682 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32
>(0), getProperty
<table::BorderLine2
>(xCell
, u
"LeftBorder"_ustr
).LineWidth
);
685 DECLARE_OOXMLEXPORT_TEST(testTdf82177_tblBorders
, "tdf82177_tblBorders.docx")
687 uno::Reference
<text::XTextTablesSupplier
> xTablesSupplier(mxComponent
, uno::UNO_QUERY
);
688 uno::Reference
<container::XIndexAccess
> xTables(xTablesSupplier
->getTextTables(), uno::UNO_QUERY
);
689 uno::Reference
< text::XTextTable
> xTable( xTables
->getByIndex(0), uno::UNO_QUERY
);
690 uno::Reference
< table::XCell
> xCell
= xTable
->getCellByName( u
"A5"_ustr
);
691 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32
>(0), getProperty
<table::BorderLine2
>(xCell
, u
"BottomBorder"_ustr
).LineWidth
);
692 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32
>(0), getProperty
<table::BorderLine2
>(xCell
, u
"LeftBorder"_ustr
).LineWidth
);
693 xCell
.set(xTable
->getCellByName( u
"E5"_ustr
));
694 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32
>(0), getProperty
<table::BorderLine2
>(xCell
, u
"TopBorder"_ustr
).LineWidth
);
695 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32
>(0), getProperty
<table::BorderLine2
>(xCell
, u
"LeftBorder"_ustr
).LineWidth
);
698 DECLARE_OOXMLEXPORT_TEST(testTdf119760_positionCellBorder
, "tdf119760_positionCellBorder.docx")
700 //inconsistent in Word even. 2016 positions on last row, 2003 positions on first cell.
701 xmlDocUniquePtr pXmlDoc
= parseLayoutDump();
702 sal_Int32 nRowLeft
= getXPath(pXmlDoc
, "/root/page/body/tab[4]/row[1]/infos/bounds", "left").toInt32();
703 sal_Int32 nTextLeft
= getXPath(pXmlDoc
, "/root/page/body/tab[4]/row[1]/cell[1]/txt/infos/bounds", "left").toInt32();
704 CPPUNIT_ASSERT( nRowLeft
< nTextLeft
);
707 CPPUNIT_TEST_FIXTURE(Test
, testTdf98620_environmentBiDi
)
709 loadAndReload("tdf98620_environmentBiDi.odt");
710 CPPUNIT_ASSERT_EQUAL(2, getPages());
711 CPPUNIT_ASSERT_EQUAL(text::WritingMode2::RL_TB
, getProperty
<sal_Int16
>( getParagraph(1), u
"WritingMode"_ustr
));
712 CPPUNIT_ASSERT_EQUAL(sal_Int32(style::ParagraphAdjust_RIGHT
), getProperty
<sal_Int32
>( getParagraph(1), u
"ParaAdjust"_ustr
));
714 CPPUNIT_ASSERT_EQUAL(text::WritingMode2::LR_TB
, getProperty
<sal_Int16
>( getParagraph(2), u
"WritingMode"_ustr
));
715 CPPUNIT_ASSERT_EQUAL(sal_Int32(style::ParagraphAdjust_RIGHT
), getProperty
<sal_Int32
>( getParagraph(2), u
"ParaAdjust"_ustr
));
718 DECLARE_OOXMLEXPORT_TEST(testTdf116976
, "tdf116976.docx")
720 // This was 0, relative size of shape after bitmap was ignored.
721 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16
>(40),
722 getProperty
<sal_Int16
>(getShapeByName(u
"Text Box 2"), u
"RelativeWidth"_ustr
));
725 DECLARE_OOXMLEXPORT_TEST(testTdf116985
, "tdf116985.docx")
727 // Body frame width is 10800, 40% is the requested relative width, with 144
728 // spacing to text on the left/right side. So ideal width would be 4032,
729 // was 3431. Allow one pixel tolerance, though.
730 xmlDocUniquePtr pXmlDoc
= parseLayoutDump();
732 = getXPath(pXmlDoc
, "/root/page[1]/body/txt[1]/anchored/fly/infos/bounds", "width").toInt32();
733 CPPUNIT_ASSERT(nWidth
> 4000);
736 DECLARE_OOXMLEXPORT_TEST(testTdf116801
, "tdf116801.docx")
738 uno::Reference
<text::XTextTablesSupplier
> xTablesSupplier(mxComponent
, uno::UNO_QUERY
);
739 uno::Reference
<container::XIndexAccess
> xTables(xTablesSupplier
->getTextTables(),
741 // This raised a lang::IndexOutOfBoundsException, table was missing from
742 // the import result.
743 uno::Reference
<text::XTextTable
> xTable(xTables
->getByIndex(0), uno::UNO_QUERY
);
744 uno::Reference
<text::XTextRange
> xCell(xTable
->getCellByName(u
"D1"_ustr
), uno::UNO_QUERY
);
745 CPPUNIT_ASSERT_EQUAL(u
"D1"_ustr
, xCell
->getString());
748 DECLARE_OOXMLEXPORT_TEST(testTdf107969
, "tdf107969.docx")
750 // A VML object in a footnote's tracked changes caused write past end of document.xml at export to docx.
751 // After that, importing after export failed with
752 // SAXParseException: '[word/document.xml line 2]: Extra content at the end of the document', Stream 'word/document.xml'.
755 DECLARE_OOXMLEXPORT_TEST(testOpenDocumentAsReadOnly
, "open-as-read-only.docx")
757 CPPUNIT_ASSERT(getSwDocShell()->IsSecurityOptOpenReadOnly());
760 DECLARE_OOXMLEXPORT_TEST(testNoDefault
, "noDefault.docx")
762 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
763 uno::Reference
<container::XIndexAccess
> xTables(xTextTablesSupplier
->getTextTables(), uno::UNO_QUERY
);
764 uno::Reference
<text::XTextTable
> xTable(xTables
->getByIndex(0), uno::UNO_QUERY
);
765 uno::Reference
<text::XTextRange
> xCell(xTable
->getCellByName(u
"A1"_ustr
), uno::UNO_QUERY
);
766 uno::Reference
<container::XEnumerationAccess
> xParaEnumAccess(xCell
->getText(), uno::UNO_QUERY
);
767 uno::Reference
<container::XEnumeration
> xParaEnum
= xParaEnumAccess
->createEnumeration();
768 uno::Reference
<text::XTextRange
> xPara(xParaEnum
->nextElement(), uno::UNO_QUERY
);
770 // Row 1: color directly applied to the paragraph, overrides table and style colors
771 CPPUNIT_ASSERT_EQUAL(Color(0x2E74B5), getProperty
<Color
>(getRun(xPara
,1), u
"CharColor"_ustr
));
773 // Row2: (still part of firstRow table-style) ought to use the Normal style color, not the table-style color(5B9BD5)
774 //xCell.set(xTable->getCellByName("A2"), uno::UNO_QUERY);
775 //xParaEnumAccess.set(xCell->getText(), uno::UNO_QUERY);
776 //xParaEnum = xParaEnumAccess->createEnumeration();
777 //xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
778 //CPPUNIT_ASSERT_EQUAL(sal_Int32(COL_LIGHTMAGENTA), getProperty<sal_Int32>(getRun(xPara,1), "CharColor"));
780 // Row 3+: Normal style still applied, even if nothing is specified with w:default="1"
781 xCell
.set(xTable
->getCellByName(u
"A3"_ustr
), uno::UNO_QUERY
);
782 xParaEnumAccess
.set(xCell
->getText(), uno::UNO_QUERY
);
783 xParaEnum
= xParaEnumAccess
->createEnumeration();
784 xPara
.set(xParaEnum
->nextElement(), uno::UNO_QUERY
);
785 CPPUNIT_ASSERT_EQUAL(sal_Int32(COL_LIGHTMAGENTA
), getProperty
<sal_Int32
>(getRun(xPara
,1), u
"CharColor"_ustr
));
788 DECLARE_OOXMLEXPORT_TEST(testMarginsFromStyle
, "margins_from_style.docx")
790 // tdf#118521 paragraphs with direct formatting of top or bottom margins have
791 // lost the other margin comes from paragraph style, getting a bad
792 // margin from the default style
794 // from direct formatting
795 CPPUNIT_ASSERT_EQUAL(sal_Int32(35), getProperty
<sal_Int32
>(getParagraph(1), u
"ParaTopMargin"_ustr
));
796 // from paragraph style
797 CPPUNIT_ASSERT_EQUAL(sal_Int32(106), getProperty
<sal_Int32
>(getParagraph(1), u
"ParaBottomMargin"_ustr
));
799 // from paragraph style
800 CPPUNIT_ASSERT_EQUAL(sal_Int32(388), getProperty
<sal_Int32
>(getParagraph(3), u
"ParaTopMargin"_ustr
));
801 // from direct formatting
802 CPPUNIT_ASSERT_EQUAL(sal_Int32(600), getProperty
<sal_Int32
>(getParagraph(3), u
"ParaBottomMargin"_ustr
));
805 DECLARE_OOXMLEXPORT_TEST(testTdf134784
, "tdf134784.docx")
807 uno::Reference
<text::XText
> textbox(getShape(1), uno::UNO_QUERY
);
808 CPPUNIT_ASSERT_EQUAL(3, getParagraphs(textbox
));
809 uno::Reference
<text::XTextRange
> xParagraph
= getParagraphOfText(1, textbox
);
810 CPPUNIT_ASSERT_EQUAL(sal_Int32(212), getProperty
<sal_Int32
>(xParagraph
, u
"ParaBottomMargin"_ustr
));
812 // This wasn't zero (it was inherited from style of the previous paragraph in the main text)
813 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty
<sal_Int32
>(xParagraph
, u
"ParaTopMargin"_ustr
));
816 DECLARE_OOXMLEXPORT_TEST(testTdf136955
, "tdf134784.docx")
818 uno::Reference
<text::XText
> textbox(getShape(1), uno::UNO_QUERY
);
819 CPPUNIT_ASSERT_EQUAL(3, getParagraphs(textbox
));
820 uno::Reference
<text::XTextRange
> xParagraph
= getParagraphOfText(2, textbox
);
822 // These weren't zero (values inherited from style of the previous paragraph in the main text)
823 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty
<sal_Int32
>(xParagraph
, u
"ParaBottomMargin"_ustr
));
824 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty
<sal_Int32
>(xParagraph
, u
"ParaTopMargin"_ustr
));
827 DECLARE_OOXMLEXPORT_TEST(testTdf104348_contextMargin
, "tdf104348_contextMargin.docx")
829 // tdf#104348 shows that ContextMargin belongs with Top/Bottom handling
831 uno::Reference
<beans::XPropertySet
> xMyStyle(getStyles(u
"ParagraphStyles"_ustr
)->getByName(u
"MyStyle"_ustr
), uno::UNO_QUERY
);
832 // from paragraph style - this is what direct formatting should equal
833 sal_Int32 nMargin
= getProperty
<sal_Int32
>(xMyStyle
, u
"ParaBottomMargin"_ustr
);
834 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nMargin
);
835 // from direct formatting
836 CPPUNIT_ASSERT_EQUAL(nMargin
, getProperty
<sal_Int32
>(getParagraph(2), u
"ParaBottomMargin"_ustr
));
839 DECLARE_OOXMLEXPORT_TEST(testTdf152310
, "ColorOverwritten.docx")
841 uno::Reference
<text::XText
> xShape(getShape(1), uno::UNO_QUERY
);
843 CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED
,
844 getProperty
<Color
>(getParagraphOfText(1, xShape
), u
"CharColor"_ustr
));
845 CPPUNIT_ASSERT_EQUAL(Color(0x00b050),
846 getProperty
<Color
>(getParagraphOfText(2, xShape
), u
"CharColor"_ustr
));
849 DECLARE_OOXMLEXPORT_TEST(testTdf149996
, "lorem_hyperlink.fodt")
851 // Without the accompanying fix in place, this test would have crashed,
852 // because the exported file was corrupted.
855 DECLARE_OOXMLEXPORT_TEST(testGroupedShapeLink
, "grouped_link.docx")
857 // tdf#145147 Hyperlink in grouped shape not imported
858 // tdf#154469 Hyperlink in grouped shape not exported
859 uno::Reference
<drawing::XShapes
> xGroupShape(getShape(1), uno::UNO_QUERY
);
860 CPPUNIT_ASSERT_EQUAL(u
"https://www.libreoffice.org"_ustr
,
861 getProperty
<OUString
>(xGroupShape
->getByIndex(0), u
"Hyperlink"_ustr
));
862 CPPUNIT_ASSERT_EQUAL(u
"https://www.documentfoundation.org"_ustr
,
863 getProperty
<OUString
>(xGroupShape
->getByIndex(1), u
"Hyperlink"_ustr
));
866 DECLARE_OOXMLEXPORT_TEST(testTdf147810
, "tdf147810.odt")
868 // Without the accompanying fix in place, this test would have crashed,
869 // because the exported file was corrupted.
872 CPPUNIT_PLUGIN_IMPLEMENT();
874 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */