Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / qa / extras / ooxmlexport / ooxmlexport11.cxx
blob4e8d2991d83bbfdb6102f98b55c59329933eab5c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <swmodeltestbase.hxx>
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>
28 #include <docsh.hxx>
29 #include <o3tl/string_view.hxx>
31 class Test : public SwModelTestBase
33 public:
34 Test() : SwModelTestBase("/sw/qa/extras/ooxmlexport/data/", "Office Open XML Text") {}
37 DECLARE_OOXMLEXPORT_TEST(testTdf57589_hashColor, "tdf57589_hashColor.docx")
39 CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_SOLID, getProperty<drawing::FillStyle>(getParagraph(1), "FillStyle"));
40 CPPUNIT_ASSERT_EQUAL(COL_LIGHTMAGENTA, getProperty<Color>(getParagraph(1), "ParaBackColor"));
41 CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_NONE, getProperty<drawing::FillStyle>(getParagraph(2), "FillStyle"));
42 CPPUNIT_ASSERT_EQUAL(COL_AUTO, getProperty<Color>(getParagraph(2), "ParaBackColor"));
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("A1"), 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, "Nazwa"), "CharBackColor"));
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("A1");
64 CPPUNIT_ASSERT_EQUAL(COL_LIGHTGREEN, getProperty<Color>(xCell, "BackColor"));
65 xCell.set(xTable->getCellByName("A2"));
66 CPPUNIT_ASSERT_EQUAL(COL_AUTO, getProperty<Color>(xCell, "BackColor"));
67 xCell.set(xTable->getCellByName("B1"));
68 CPPUNIT_ASSERT_EQUAL(COL_AUTO, getProperty<Color>(xCell, "BackColor"));
69 xCell.set(xTable->getCellByName("B2"));
70 CPPUNIT_ASSERT_EQUAL(COL_LIGHTBLUE, getProperty<Color>(xCell, "BackColor"));
72 uno::Reference<text::XTextRange> xText(getParagraph(2, "Paragraphs too"));
73 CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_NONE, getProperty<drawing::FillStyle>(xText, "FillStyle"));
74 CPPUNIT_ASSERT_EQUAL(COL_AUTO, getProperty<Color>(xText, "ParaBackColor"));
77 CPPUNIT_TEST_FIXTURE(Test, testTdf92524_autoColor)
79 loadAndReload("tdf92524_autoColor.doc");
80 CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_NONE, getProperty<drawing::FillStyle>(getParagraph(1), "FillStyle"));
81 CPPUNIT_ASSERT_EQUAL(COL_AUTO, getProperty<Color>(getParagraph(1), "ParaBackColor"));
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("A1");
92 CPPUNIT_ASSERT_EQUAL(Color(0xF8DF7C), getProperty<Color>(xCell, "BackColor"));
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), "BreakType"));
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 ), "ParaTabStops");
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 ), "ParaTabStops");
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), "ParaTabStops").getLength());
127 DECLARE_OOXMLEXPORT_TEST(testTdf63561_clearTabs, "tdf63561_clearTabs.docx")
129 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), getProperty< uno::Sequence<style::TabStop> >(getParagraph(1), "ParaTabStops").getLength());
130 CPPUNIT_ASSERT_EQUAL(sal_Int32(7), getProperty< uno::Sequence<style::TabStop> >(getParagraph(3), "ParaTabStops").getLength());
131 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), getProperty< uno::Sequence<style::TabStop> >(getParagraph(4), "ParaTabStops").getLength());
134 DECLARE_OOXMLEXPORT_TEST(testTdf63561_clearTabs2, "tdf63561_clearTabs2.docx")
136 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getProperty< uno::Sequence<style::TabStop> >(getParagraph(1), "ParaTabStops").getLength());
137 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), getProperty< uno::Sequence<style::TabStop> >(getParagraph(3), "ParaTabStops").getLength());
138 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), getProperty< uno::Sequence<style::TabStop> >(getParagraph(4), "ParaTabStops").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 ), "ParaTabStops");
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("word/document.xml");
165 assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p/w:r/w:t", "Inhaltsverzeichnis");
166 assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p/w:r/w:instrText", " TOC \\f \\o \"1-9\" \\h");
167 assertXPath(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtPr/w:docPartObj/w:docPartGallery", "val", "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("word/document.xml");
175 assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p[1]/w:r[4]/w:t", "Overview");
176 assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p[1]/w:r[5]/w:t", "3");
177 assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p[2]/w:r[1]/w:t", "More detailed description");
178 assertXPathContent(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtContent/w:p[2]/w:r[2]/w:t", "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("word/document.xml");
197 // get TOC node
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(OUString("Inhaltsverzeichnis"), getProperty<OUString>(xTOCIndex, "Title"));
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", "end");
209 DECLARE_OOXMLEXPORT_TEST(testTdf106174_rtlParaAlign, "tdf106174_rtlParaAlign.docx")
211 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_CENTER), getProperty<sal_Int16>(getParagraph(1), "ParaAdjust"));
212 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_CENTER), getProperty<sal_Int16>(getParagraph(2), "ParaAdjust"));
213 uno::Reference<beans::XPropertySet> xPropertySet(getStyles("ParagraphStyles")->getByName("Another paragraph aligned to right"), uno::UNO_QUERY);
214 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT), getProperty<sal_Int16>(xPropertySet, "ParaAdjust"));
215 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT), getProperty<sal_Int16>(getParagraph(3), "ParaAdjust"));
216 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT), getProperty<sal_Int16>(getParagraph(4), "ParaAdjust"));
217 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT), getProperty<sal_Int16>(getParagraph(5), "ParaAdjust"));
218 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_LEFT), getProperty<sal_Int16>(getParagraph(6), "ParaAdjust"));
219 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT), getProperty<sal_Int16>(getParagraph(7), "ParaAdjust"));
220 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT), getProperty<sal_Int16>(getParagraph(8), "ParaAdjust"));
221 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_LEFT), getProperty<sal_Int16>(getParagraph(9), "ParaAdjust"));
222 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_LEFT), getProperty<sal_Int16>(getParagraph(10), "ParaAdjust"));
223 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT), getProperty<sal_Int16>(getParagraph(11), "ParaAdjust"));
224 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_LEFT), getProperty<sal_Int16>(getParagraph(12), "ParaAdjust"));
225 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_LEFT), getProperty<sal_Int16>(getParagraph(13), "ParaAdjust"));
226 CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT), getProperty<sal_Int16>(getParagraph(14), "ParaAdjust"));
229 DECLARE_OOXMLEXPORT_TEST(testTdf82065_Ind_start_strict, "tdf82065_Ind_start_strict.docx")
231 uno::Reference<beans::XPropertySet> xPropertySet(getStyles("NumberingStyles")->getByName("WWNum1"), uno::UNO_QUERY);
232 uno::Reference<container::XIndexAccess> xLevels(xPropertySet->getPropertyValue("NumberingRules"), 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 : std::as_const(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("word/document.xml");
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(testTdf112694, "tdf112694.docx")
259 uno::Any aPageStyle = getStyles("PageStyles")->getByName("Standard");
260 // Header was on when header for file was for explicit first pages only
261 // (marked via <w:titlePg>).
262 CPPUNIT_ASSERT(!getProperty<bool>(aPageStyle, "HeaderIsOn"));
265 CPPUNIT_TEST_FIXTURE(Test, testTdf113849_evenAndOddHeaders)
267 loadAndReload("tdf113849_evenAndOddHeaders.odt");
268 CPPUNIT_ASSERT_EQUAL_MESSAGE("Header2 text", OUString("L. J. Kendall"), parseDump("/root/page[2]/header/txt"));
269 CPPUNIT_ASSERT_EQUAL_MESSAGE("Footer2 text", OUString("*"), parseDump("/root/page[2]/footer/txt"));
271 CPPUNIT_ASSERT_EQUAL_MESSAGE("Header3 text", OUString("Shadow Hunt"), parseDump("/root/page[3]/header/txt"));
272 CPPUNIT_ASSERT_EQUAL_MESSAGE("Footer3 text", OUString("*"), parseDump("/root/page[3]/footer/txt"));
274 CPPUNIT_ASSERT_EQUAL_MESSAGE("Header4 text", OUString("L. J. Kendall"), parseDump("/root/page[4]/header/txt"));
275 CPPUNIT_ASSERT_EQUAL_MESSAGE("Footer4 text", OUString("*"), parseDump("/root/page[4]/footer/txt"));
277 CPPUNIT_ASSERT_EQUAL_MESSAGE("Footer5 text", OUString(""), parseDump("/root/page[5]/footer/txt"));
278 CPPUNIT_ASSERT_EQUAL_MESSAGE("Footer6 text", OUString(""), parseDump("/root/page[6]/footer/txt"));
280 CPPUNIT_ASSERT_EQUAL_MESSAGE("Number of pages", 6, getPages() );
283 DECLARE_OOXMLEXPORT_TEST(testTdf118361_RTLfootnoteSeparator, "tdf118361_RTLfootnoteSeparator.docx")
285 uno::Any aPageStyle = getStyles("PageStyles")->getByName("Standard");
286 CPPUNIT_ASSERT_EQUAL_MESSAGE("Footnote separator RTL", sal_Int16(2), getProperty<sal_Int16>(aPageStyle, "FootnoteLineAdjust"));
289 DECLARE_OOXMLEXPORT_TEST(testTdf115861, "tdf115861.docx")
291 // Second item in the paragraph enumeration was a table, 2nd paragraph was
292 // lost.
293 CPPUNIT_ASSERT_EQUAL(OUString("(k)"), getParagraph(2)->getString());
296 DECLARE_OOXMLEXPORT_TEST(testTdf67207_MERGEFIELD, "mailmerge.docx")
298 uno::Reference<beans::XPropertySet> xTextField = getProperty< uno::Reference<beans::XPropertySet> >(getRun(getParagraph(1), 2), "TextField");
299 CPPUNIT_ASSERT(xTextField.is());
300 uno::Reference<lang::XServiceInfo> xServiceInfo(xTextField, uno::UNO_QUERY_THROW);
301 uno::Reference<text::XDependentTextField> xDependent(xTextField, uno::UNO_QUERY_THROW);
303 CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextField.Database"));
304 OUString sValue;
305 xTextField->getPropertyValue("Content") >>= sValue;
306 CPPUNIT_ASSERT_EQUAL(OUString(u"«Name»"), sValue);
308 uno::Reference<beans::XPropertySet> xFiledMaster = xDependent->getTextFieldMaster();
309 uno::Reference<lang::XServiceInfo> xFiledMasterServiceInfo(xFiledMaster, uno::UNO_QUERY_THROW);
311 CPPUNIT_ASSERT(xFiledMasterServiceInfo->supportsService("com.sun.star.text.fieldmaster.Database"));
313 // Defined properties: DataBaseName, Name, DataTableName, DataColumnName, DependentTextFields, DataCommandType, InstanceName, DataBaseURL
314 CPPUNIT_ASSERT(xFiledMaster->getPropertyValue("Name") >>= sValue);
315 CPPUNIT_ASSERT_EQUAL(OUString("Name"), sValue);
316 CPPUNIT_ASSERT(xFiledMaster->getPropertyValue("DataColumnName") >>= sValue);
317 CPPUNIT_ASSERT_EQUAL(OUString("Name"), sValue);
318 CPPUNIT_ASSERT(xFiledMaster->getPropertyValue("InstanceName") >>= sValue);
319 CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.text.fieldmaster.DataBase.Name"), sValue);
322 DECLARE_OOXMLEXPORT_TEST(testTdf115719, "tdf115719.docx")
324 // This was a single page, instead of pushing the textboxes to the second
325 // page.
326 CPPUNIT_ASSERT_EQUAL(2, getPages());
329 DECLARE_OOXMLEXPORT_TEST(testTdf115719b, "tdf115719b.docx")
331 // This is similar to testTdf115719, but here the left textbox is not aligned "from left, by
332 // 0cm" but simply aligned to left, which is a different codepath.
334 // Without the accompanying fix in place, this test would have failed with:
335 // - Expected: 2
336 // - Actual : 1
337 // i.e. the textboxes did not appear on the 2nd page, but everything was on a single page.
338 CPPUNIT_ASSERT_EQUAL(2, getPages());
341 DECLARE_OOXMLEXPORT_TEST(testTdf123243, "tdf123243.docx")
343 // Without the accompanying fix in place, this test would have failed with 'Expected: 1; Actual:
344 // 2'; i.e. unexpected paragraph margin created 2 pages.
345 CPPUNIT_ASSERT_EQUAL(1, getPages());
348 DECLARE_OOXMLEXPORT_TEST(testTdf116410, "tdf116410.docx")
350 // Opposite of the above, was 2 pages, should be 1 page.
351 CPPUNIT_ASSERT_EQUAL(1, getPages());
354 DECLARE_OOXMLEXPORT_TEST(testDefaultStyle, "defaultStyle.docx")
356 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Default Style", OUString("Title"), getProperty<OUString>(getParagraph(1), "ParaStyleName") );
357 CPPUNIT_ASSERT_EQUAL(2, getPages());
360 DECLARE_OOXMLEXPORT_TEST(testTdf147115_defaultStyle, "tdf147115_defaultStyle.docx")
362 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Default Style", OUString("Standard"), getProperty<OUString>(getParagraph(1), "ParaStyleName") );
365 DECLARE_OOXMLEXPORT_TEST(testTdf117988, "tdf117988.docx")
367 CPPUNIT_ASSERT_EQUAL(1, getPages());
370 DECLARE_OOXMLEXPORT_TEST(testTdf94801, "tdf94801.docx")
372 // This was a 2-page document with unwanted line breaking in table cells, because
373 // the table was narrower, than defined (< 1/100 mm loss during twip to 1/100 mm conversion)
374 CPPUNIT_ASSERT_EQUAL(1, getPages());
377 CPPUNIT_TEST_FIXTURE(Test, testParagraphSplitOnSectionBorder)
379 loadAndSave("parasplit-on-section-border.odt");
380 CPPUNIT_ASSERT_EQUAL(2, getPages());
381 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
383 // Test document has only two paragraphs. After splitting, it should contain
384 // three of them.
385 assertXPath(pXmlDoc, "//w:sectPr", 2);
386 assertXPath(pXmlDoc, "//w:p", 3);
389 CPPUNIT_TEST_FIXTURE(Test, testTdf44832_testSectionWithDifferentHeader)
391 loadAndSave("tdf44832_section_new_header.odt");
392 CPPUNIT_ASSERT_EQUAL(2, getPages());
393 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
394 assertXPath(pXmlDoc, "/w:document/w:body/w:sectPr/w:headerReference", 1);
397 DECLARE_OOXMLEXPORT_TEST(testSignatureLineShape, "signature-line-all-props-set.docx")
399 uno::Reference<drawing::XShape> xSignatureLineShape = getShape(1);
400 uno::Reference<beans::XPropertySet> xPropSet(xSignatureLineShape, uno::UNO_QUERY);
402 bool bIsSignatureLine;
403 xPropSet->getPropertyValue("IsSignatureLine") >>= bIsSignatureLine;
404 CPPUNIT_ASSERT_EQUAL(true, bIsSignatureLine);
406 bool bShowSignDate;
407 xPropSet->getPropertyValue("SignatureLineShowSignDate") >>= bShowSignDate;
408 CPPUNIT_ASSERT_EQUAL(true, bShowSignDate);
410 bool bCanAddComment;
411 xPropSet->getPropertyValue("SignatureLineCanAddComment") >>= bCanAddComment;
412 CPPUNIT_ASSERT_EQUAL(true, bCanAddComment);
414 OUString aSignatureLineId;
415 xPropSet->getPropertyValue("SignatureLineId") >>= aSignatureLineId;
416 CPPUNIT_ASSERT_EQUAL(OUString("{0EBE47D5-A1BD-4C9E-A52E-6256E5C345E9}"), aSignatureLineId);
418 OUString aSuggestedSignerName;
419 xPropSet->getPropertyValue("SignatureLineSuggestedSignerName") >>= aSuggestedSignerName;
420 CPPUNIT_ASSERT_EQUAL(OUString("John Doe"), aSuggestedSignerName);
422 OUString aSuggestedSignerTitle;
423 xPropSet->getPropertyValue("SignatureLineSuggestedSignerTitle") >>= aSuggestedSignerTitle;
424 CPPUNIT_ASSERT_EQUAL(OUString("Farmer"), aSuggestedSignerTitle);
426 OUString aSuggestedSignerEmail;
427 xPropSet->getPropertyValue("SignatureLineSuggestedSignerEmail") >>= aSuggestedSignerEmail;
428 CPPUNIT_ASSERT_EQUAL(OUString("john@thefarmers.com"), aSuggestedSignerEmail);
430 OUString aSigningInstructions;
431 xPropSet->getPropertyValue("SignatureLineSigningInstructions") >>= aSigningInstructions;
432 CPPUNIT_ASSERT_EQUAL(OUString("Check the machines!"), aSigningInstructions);
435 CPPUNIT_TEST_FIXTURE(Test, testTdf117805)
437 loadAndSave("tdf117805.odt");
438 CPPUNIT_ASSERT_EQUAL(1, getShapes());
439 CPPUNIT_ASSERT_EQUAL(1, getPages());
440 uno::Reference<packages::zip::XZipFileAccess2> xNameAccess
441 = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory),
442 maTempFile.GetURL());
443 // This failed, the header was lost. It's still referenced at an incorrect
444 // location in document.xml, though.
445 CPPUNIT_ASSERT(xNameAccess->hasByName("word/header1.xml"));
447 uno::Reference<text::XText> textbox(getShape(1), uno::UNO_QUERY);
448 CPPUNIT_ASSERT_EQUAL(8, getParagraphs(textbox));
451 DECLARE_OOXMLEXPORT_TEST(testTdf113183, "tdf113183.docx")
453 // The horizontal positioning of the star shape affected the positioning of
454 // the triangle one, so the triangle was outside the page frame.
455 xmlDocUniquePtr pXmlDoc = parseLayoutDump();
456 sal_Int32 nPageLeft = getXPath(pXmlDoc, "/root/page[1]/infos/bounds", "left").toInt32();
457 sal_Int32 nPageWidth = getXPath(pXmlDoc, "/root/page[1]/infos/bounds", "width").toInt32();
458 sal_Int32 nShapeLeft
459 = getXPath(pXmlDoc, "/root/page/body/txt/anchored/SwAnchoredDrawObject[2]/bounds", "left")
460 .toInt32();
461 sal_Int32 nShapeWidth
462 = getXPath(pXmlDoc, "/root/page/body/txt/anchored/SwAnchoredDrawObject[2]/bounds", "width")
463 .toInt32();
464 // Make sure the second triangle shape is within the page bounds (with ~1px tolerance).
465 CPPUNIT_ASSERT_GREATEREQUAL(nShapeLeft + nShapeWidth, nPageLeft + nPageWidth + 21);
468 DECLARE_OOXMLEXPORT_TEST(testGraphicObjectFliph, "graphic-object-fliph.docx")
470 CPPUNIT_ASSERT(getProperty<bool>(getShape(1), "HoriMirroredOnEvenPages"));
471 CPPUNIT_ASSERT(getProperty<bool>(getShape(1), "HoriMirroredOnOddPages"));
474 DECLARE_OOXMLEXPORT_TEST(testTdf113547, "tdf113547.docx")
476 uno::Reference<beans::XPropertySet> xPropertySet(
477 getStyles("NumberingStyles")->getByName("WWNum1"), uno::UNO_QUERY);
478 uno::Reference<container::XIndexAccess> xLevels(
479 xPropertySet->getPropertyValue("NumberingRules"), uno::UNO_QUERY);
480 comphelper::SequenceAsHashMap aProps(xLevels->getByIndex(0)); // 1st level
481 // This was 0, first-line left margin of the numbering was lost.
482 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-635), aProps["FirstLineIndent"].get<sal_Int32>());
485 CPPUNIT_TEST_FIXTURE(Test, testTdf113399)
487 loadAndReload("tdf113399.doc");
488 // 0 padding was not preserved
489 // In LO 0 is the default, but in OOXML format the default is 254 / 127
490 uno::Reference<beans::XPropertySet> xPropSet(getShape(1), uno::UNO_QUERY);
491 sal_Int32 nPaddingValue;
492 xPropSet->getPropertyValue("TextLeftDistance") >>= nPaddingValue;
493 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), nPaddingValue);
494 xPropSet->getPropertyValue("TextRightDistance") >>= nPaddingValue;
495 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), nPaddingValue);
496 xPropSet->getPropertyValue("TextUpperDistance") >>= nPaddingValue;
497 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), nPaddingValue);
498 xPropSet->getPropertyValue("TextLowerDistance") >>= nPaddingValue;
499 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), nPaddingValue);
502 DECLARE_OOXMLEXPORT_TEST(testTdf114882, "tdf114882.docx")
504 // fastserializer must not fail assertion because of mismatching elements
507 DECLARE_OOXMLEXPORT_TEST(testTdf49073, "tdf49073.docx")
509 // test case for Asian phontic guide (ruby text.)
510 sal_Unicode aRuby[3] = {0x304D,0x3082,0x3093};
511 OUString sRuby(aRuby, SAL_N_ELEMENTS(aRuby));
512 CPPUNIT_ASSERT_EQUAL(sRuby,getProperty<OUString>(getParagraph(1)->getStart(), "RubyText"));
513 OUString sStyle = getProperty<OUString>( getParagraph(1)->getStart(), "RubyCharStyleName");
514 uno::Reference<beans::XPropertySet> xPropertySet(getStyles("CharacterStyles")->getByName(sStyle), uno::UNO_QUERY );
515 CPPUNIT_ASSERT_EQUAL(5.f, getProperty<float>(xPropertySet, "CharHeight"));
516 CPPUNIT_ASSERT_EQUAL(sal_Int16(text::RubyAdjust_CENTER) ,getProperty<sal_Int16>(getParagraph(2)->getStart(),"RubyAdjust"));
517 CPPUNIT_ASSERT_EQUAL(sal_Int16(text::RubyAdjust_BLOCK) ,getProperty<sal_Int16>(getParagraph(3)->getStart(),"RubyAdjust"));
518 CPPUNIT_ASSERT_EQUAL(sal_Int16(text::RubyAdjust_INDENT_BLOCK),getProperty<sal_Int16>(getParagraph(4)->getStart(),"RubyAdjust"));
519 CPPUNIT_ASSERT_EQUAL(sal_Int16(text::RubyAdjust_LEFT) ,getProperty<sal_Int16>(getParagraph(5)->getStart(),"RubyAdjust"));
520 CPPUNIT_ASSERT_EQUAL(sal_Int16(text::RubyAdjust_RIGHT) ,getProperty<sal_Int16>(getParagraph(6)->getStart(),"RubyAdjust"));
521 CPPUNIT_ASSERT_EQUAL(sal_Int16(text::RubyPosition::INTER_CHARACTER) ,getProperty<sal_Int16>(getParagraph(7)->getStart(),"RubyPosition"));
524 DECLARE_OOXMLEXPORT_TEST(testTdf114703, "tdf114703.docx")
526 uno::Reference<container::XIndexAccess> xRules
527 = getProperty<uno::Reference<container::XIndexAccess>>(
528 getStyles("NumberingStyles")->getByName("WWNum1"), "NumberingRules");
529 // This was 0, level override "default" replaced the non-default value from
530 // the abstract level.
531 CPPUNIT_ASSERT_EQUAL(
532 static_cast<sal_Int32>(-1000),
533 comphelper::SequenceAsHashMap(xRules->getByIndex(0))["FirstLineIndent"].get<sal_Int32>());
536 DECLARE_OOXMLEXPORT_TEST(testTdf113258, "tdf113258.docx")
538 uno::Reference<text::XTextRange> xShape(getShape(1), uno::UNO_QUERY);
539 // This was 494, i.e. automatic spacing resulted in non-zero paragraph top
540 // margin for the first paragraph in a shape.
541 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0),
542 getProperty<sal_Int32>(xShape->getStart(), "ParaTopMargin"));
545 DECLARE_OOXMLEXPORT_TEST(testTdf113258_noBeforeAutospacing, "tdf113258_noBeforeAutospacing.docx")
547 uno::Reference<text::XTextRange> xShape(getShape(1), uno::UNO_QUERY);
548 // This was 0, i.e. disabled automatic spacing still resulted in zero paragraph
549 // top margin for the first paragraph in a shape.
550 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1764),
551 getProperty<sal_Int32>(xShape->getStart(), "ParaTopMargin"));
554 DECLARE_OOXMLEXPORT_TEST(testTdf142542_cancelledAutospacing, "tdf142542_cancelledAutospacing.docx")
556 //Direct formatting disabling autoSpacing must override paragraph-style's autoSpacing.
557 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), getProperty<sal_Int32>(getParagraph(1), "ParaTopMargin"));
558 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), getProperty<sal_Int32>(getParagraph(1), "ParaBottomMargin"));
561 CPPUNIT_TEST_FIXTURE(Test, testTdf137655)
563 loadAndSave("tdf137655.docx");
564 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
565 // These were 280.
566 assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[1]/w:p[1]/w:pPr/w:spacing", "before", "0");
567 assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[2]/w:p[1]/w:pPr/w:spacing", "before", "0");
569 //tdf#142542: ensure that the original beforeAutospacing = 0 is not changed.
570 assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[1]/w:p[1]/w:pPr/w:spacing", "beforeAutospacing", "0");
573 DECLARE_OOXMLEXPORT_TEST(testTdf120511_eatenSection, "tdf120511_eatenSection.docx")
575 xmlDocUniquePtr pXmlDoc = parseLayoutDump();
576 sal_Int32 nHeight = getXPath(pXmlDoc, "/root/page[1]/infos/prtBounds", "height").toInt32();
577 sal_Int32 nWidth = getXPath(pXmlDoc, "/root/page[1]/infos/prtBounds", "width").toInt32();
578 CPPUNIT_ASSERT_MESSAGE( "Page1 is portrait", nWidth < nHeight );
579 nHeight = getXPath(pXmlDoc, "/root/page[2]/infos/prtBounds", "height").toInt32();
580 nWidth = getXPath(pXmlDoc, "/root/page[2]/infos/prtBounds", "width").toInt32();
581 CPPUNIT_ASSERT_MESSAGE( "Page2 is landscape", nWidth > nHeight );
584 DECLARE_OOXMLEXPORT_TEST(testTdf104354, "tdf104354.docx")
586 uno::Reference<text::XTextRange> xShape(getShape(1), uno::UNO_QUERY);
587 // This was 494, i.e. automatic spacing resulted in non-zero paragraph top
588 // margin for the first paragraph in a text frame.
589 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0),
590 getProperty<sal_Int32>(xShape->getStart(), "ParaTopMargin"));
591 // still 494 in the second paragraph
592 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(494),
593 getProperty<sal_Int32>(xShape->getEnd(), "ParaTopMargin"));
596 DECLARE_OOXMLEXPORT_TEST(testTdf104354_firstParaInSection, "tdf104354_firstParaInSection.docx")
598 uno::Reference<text::XFootnotesSupplier> xFootnotesSupplier(mxComponent, uno::UNO_QUERY);
599 uno::Reference<container::XIndexAccess> xFootnotes = xFootnotesSupplier->getFootnotes();
600 uno::Reference<text::XText> xText(xFootnotes->getByIndex(0), uno::UNO_QUERY);
601 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(494),
602 getProperty<sal_Int32>(getParagraphOfText(1, xText), "ParaTopMargin"));
603 CPPUNIT_ASSERT_EQUAL(1, getPages());
606 CPPUNIT_TEST_FIXTURE(Test, testPageBreak_after)
608 loadAndReload("pageBreak_after.odt");
609 // The problem was that the page breakAfter put the empty page BEFORE the table
610 xmlDocUniquePtr pDump = parseLayoutDump();
611 assertXPath(pDump, "/root/page[1]/body/tab", 1);
612 // There should be two pages actually - a blank page after a page break.
613 CPPUNIT_ASSERT_EQUAL_MESSAGE("Did you fix?? Table should be on page one of two", 1, getPages());
616 DECLARE_OOXMLEXPORT_TEST(testTdf107035, "tdf107035.docx")
618 // Select the second run containing the page number field
619 auto xPgNumRun = getRun(getParagraph(1), 2, "1");
621 // Check that the page number field colour is set to "automatic".
622 Color nPgNumColour = getProperty<Color>(xPgNumRun, "CharColor");
623 CPPUNIT_ASSERT_EQUAL(COL_AUTO, nPgNumColour);
626 DECLARE_OOXMLEXPORT_TEST(testTdf112118_DOCX, "tdf112118.docx")
628 // The resulting left margin width (2081) differs from its DOC counterpart from ww8export2.cxx,
629 // because DOCX import does two conversions between mm/100 and twips on the route, losing one
630 // twip on the road and arriving with a value that is 2 mm/100 less. I don't see an obvious way
631 // to avoid that.
632 static const struct {
633 const char* styleName;
634 struct {
635 const char* sideName;
636 sal_Int32 nMargin;
637 sal_Int32 nBorderDistance;
638 sal_Int32 nBorderWidth;
639 } sideParams[4];
640 } styleParams[] = { // Margin (MS-style), border distance, border width
642 "Standard",
644 { "Top", 496, 847, 159 }, // 851 twip, 24 pt (from text), 4.5 pt
645 { "Left", 2081, 706, 212 }, // 1701 twip, 20 pt (from text), 6.0 pt
646 { "Bottom", 1401, 564, 35 }, // 1134 twip, 16 pt (from text), 1.0 pt
647 { "Right", 3471, 423, 106 } // 2268 twip, 12 pt (from text), 3.0 pt
651 "Converted1",
653 { "Top", 847, 496, 159 }, // 851 twip, 24 pt (from edge), 4.5 pt
654 { "Left", 706, 2081, 212 }, // 1701 twip, 20 pt (from edge), 6.0 pt
655 { "Bottom", 564, 1401, 35 }, // 1134 twip, 16 pt (from edge), 1.0 pt
656 { "Right", 423, 3471, 106 } // 2268 twip, 12 pt (from edge), 3.0 pt
660 auto xStyles = getStyles("PageStyles");
662 for (const auto& style : styleParams)
664 const OUString sName = OUString::createFromAscii(style.styleName);
665 uno::Reference<beans::XPropertySet> xStyle(xStyles->getByName(sName), uno::UNO_QUERY_THROW);
666 for (const auto& side : style.sideParams)
668 const OUString sSide = OUString::createFromAscii(side.sideName);
669 const OString sStage = style.styleName + OString::Concat(" ") + side.sideName;
671 sal_Int32 nMargin = getProperty<sal_Int32>(xStyle, sSide + "Margin");
672 CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(sStage + " margin width").getStr(),
673 side.nMargin, nMargin);
675 sal_Int32 nBorderDistance = getProperty<sal_Int32>(xStyle, sSide + "BorderDistance");
676 CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(sStage + " border distance").getStr(),
677 side.nBorderDistance, nBorderDistance);
679 table::BorderLine aBorder = getProperty<table::BorderLine>(xStyle, sSide + "Border");
680 CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(sStage + " border width").getStr(),
681 side.nBorderWidth,
682 sal_Int32(aBorder.OuterLineWidth + aBorder.InnerLineWidth + aBorder.LineDistance));
684 // tdf#116472: check that AUTO border color is imported as black
685 CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(sStage + " border color").getStr(),
686 sal_Int32(COL_BLACK), aBorder.Color);
691 DECLARE_OOXMLEXPORT_TEST(testTdf82177_outsideCellBorders, "tdf82177_outsideCellBorders.docx")
693 uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
694 uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), uno::UNO_QUERY);
695 uno::Reference< text::XTextTable > xTable( xTables->getByIndex(0), uno::UNO_QUERY );
696 uno::Reference< table::XCell > xCell = xTable->getCellByName( "E4" );
697 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(0), getProperty<table::BorderLine2>(xCell, "TopBorder").LineWidth);
698 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(0), getProperty<table::BorderLine2>(xCell, "LeftBorder").LineWidth);
701 DECLARE_OOXMLEXPORT_TEST(testTdf82177_insideCellBorders, "tdf82177_insideCellBorders.docx")
703 uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
704 uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), uno::UNO_QUERY);
705 uno::Reference< text::XTextTable > xTable( xTables->getByIndex(0), uno::UNO_QUERY );
706 uno::Reference< table::XCell > xCell = xTable->getCellByName( "E4" );
707 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(0), getProperty<table::BorderLine2>(xCell, "TopBorder").LineWidth);
708 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(0), getProperty<table::BorderLine2>(xCell, "LeftBorder").LineWidth);
711 DECLARE_OOXMLEXPORT_TEST(testTdf82177_tblBorders, "tdf82177_tblBorders.docx")
713 uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
714 uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), uno::UNO_QUERY);
715 uno::Reference< text::XTextTable > xTable( xTables->getByIndex(0), uno::UNO_QUERY );
716 uno::Reference< table::XCell > xCell = xTable->getCellByName( "A5" );
717 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(0), getProperty<table::BorderLine2>(xCell, "BottomBorder").LineWidth);
718 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(0), getProperty<table::BorderLine2>(xCell, "LeftBorder").LineWidth);
719 xCell.set(xTable->getCellByName( "E5" ));
720 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(0), getProperty<table::BorderLine2>(xCell, "TopBorder").LineWidth);
721 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(0), getProperty<table::BorderLine2>(xCell, "LeftBorder").LineWidth);
724 DECLARE_OOXMLEXPORT_TEST(testTdf119760_positionCellBorder, "tdf119760_positionCellBorder.docx")
726 //inconsistent in Word even. 2016 positions on last row, 2003 positions on first cell.
727 sal_Int32 nRowLeft = parseDump("/root/page/body/tab[4]/row[1]/infos/bounds", "left").toInt32();
728 sal_Int32 nTextLeft = parseDump("/root/page/body/tab[4]/row[1]/cell[1]/txt/infos/bounds", "left").toInt32();
729 CPPUNIT_ASSERT( nRowLeft < nTextLeft );
732 CPPUNIT_TEST_FIXTURE(Test, testTdf98620_environmentBiDi)
734 loadAndReload("tdf98620_environmentBiDi.odt");
735 CPPUNIT_ASSERT_EQUAL(2, getPages());
736 CPPUNIT_ASSERT_EQUAL(text::WritingMode2::RL_TB, getProperty<sal_Int16>( getParagraph(1), "WritingMode" ));
737 CPPUNIT_ASSERT_EQUAL(sal_Int32(style::ParagraphAdjust_RIGHT), getProperty<sal_Int32>( getParagraph(1), "ParaAdjust" ));
739 CPPUNIT_ASSERT_EQUAL(text::WritingMode2::LR_TB, getProperty<sal_Int16>( getParagraph(2), "WritingMode" ));
740 CPPUNIT_ASSERT_EQUAL(sal_Int32(style::ParagraphAdjust_RIGHT), getProperty<sal_Int32>( getParagraph(2), "ParaAdjust" ));
743 DECLARE_OOXMLEXPORT_TEST(testTdf116976, "tdf116976.docx")
745 // This was 0, relative size of shape after bitmap was ignored.
746 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(40),
747 getProperty<sal_Int16>(getShape(1), "RelativeWidth"));
750 DECLARE_OOXMLEXPORT_TEST(testTdf116985, "tdf116985.docx")
752 // Body frame width is 10800, 40% is the requested relative width, with 144
753 // spacing to text on the left/right side. So ideal width would be 4032,
754 // was 3431. Allow one pixel tolerance, though.
755 sal_Int32 nWidth
756 = parseDump("/root/page[1]/body/txt[1]/anchored/fly/infos/bounds", "width").toInt32();
757 CPPUNIT_ASSERT(nWidth > 4000);
760 DECLARE_OOXMLEXPORT_TEST(testTdf116801, "tdf116801.docx")
762 uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
763 uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(),
764 uno::UNO_QUERY);
765 // This raised a lang::IndexOutOfBoundsException, table was missing from
766 // the import result.
767 uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
768 uno::Reference<text::XTextRange> xCell(xTable->getCellByName("D1"), uno::UNO_QUERY);
769 CPPUNIT_ASSERT_EQUAL(OUString("D1"), xCell->getString());
772 DECLARE_OOXMLEXPORT_TEST(testTdf107969, "tdf107969.docx")
774 // A VML object in a footnote's tracked changes caused write past end of document.xml at export to docx.
775 // After that, importing after export failed with
776 // SAXParseException: '[word/document.xml line 2]: Extra content at the end of the document', Stream 'word/document.xml'.
779 DECLARE_OOXMLEXPORT_TEST(testOpenDocumentAsReadOnly, "open-as-read-only.docx")
781 SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
782 CPPUNIT_ASSERT(pTextDoc);
783 CPPUNIT_ASSERT(pTextDoc->GetDocShell()->IsSecurityOptOpenReadOnly());
786 DECLARE_OOXMLEXPORT_TEST(testNoDefault, "noDefault.docx")
788 uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
789 uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
790 uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
791 uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY);
792 uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xCell->getText(), uno::UNO_QUERY);
793 uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
794 uno::Reference<text::XTextRange> xPara(xParaEnum->nextElement(), uno::UNO_QUERY);
796 // Row 1: color directly applied to the paragraph, overrides table and style colors
797 CPPUNIT_ASSERT_EQUAL(Color(0x2E74B5), getProperty<Color>(getRun(xPara,1), "CharColor"));
799 // Row2: (still part of firstRow table-style) ought to use the Normal style color, not the table-style color(5B9BD5)
800 //xCell.set(xTable->getCellByName("A2"), uno::UNO_QUERY);
801 //xParaEnumAccess.set(xCell->getText(), uno::UNO_QUERY);
802 //xParaEnum = xParaEnumAccess->createEnumeration();
803 //xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
804 //CPPUNIT_ASSERT_EQUAL(sal_Int32(COL_LIGHTMAGENTA), getProperty<sal_Int32>(getRun(xPara,1), "CharColor"));
806 // Row 3+: Normal style still applied, even if nothing is specified with w:default="1"
807 xCell.set(xTable->getCellByName("A3"), uno::UNO_QUERY);
808 xParaEnumAccess.set(xCell->getText(), uno::UNO_QUERY);
809 xParaEnum = xParaEnumAccess->createEnumeration();
810 xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
811 CPPUNIT_ASSERT_EQUAL(sal_Int32(COL_LIGHTMAGENTA), getProperty<sal_Int32>(getRun(xPara,1), "CharColor"));
814 DECLARE_OOXMLEXPORT_TEST(testMarginsFromStyle, "margins_from_style.docx")
816 // tdf#118521 paragraphs with direct formatting of top or bottom margins have
817 // lost the other margin comes from paragraph style, getting a bad
818 // margin from the default style
820 // from direct formatting
821 CPPUNIT_ASSERT_EQUAL(sal_Int32(35), getProperty<sal_Int32>(getParagraph(1), "ParaTopMargin"));
822 // from paragraph style
823 CPPUNIT_ASSERT_EQUAL(sal_Int32(106), getProperty<sal_Int32>(getParagraph(1), "ParaBottomMargin"));
825 // from paragraph style
826 CPPUNIT_ASSERT_EQUAL(sal_Int32(388), getProperty<sal_Int32>(getParagraph(3), "ParaTopMargin"));
827 // from direct formatting
828 CPPUNIT_ASSERT_EQUAL(sal_Int32(600), getProperty<sal_Int32>(getParagraph(3), "ParaBottomMargin"));
831 DECLARE_OOXMLEXPORT_TEST(testTdf134784, "tdf134784.docx")
833 uno::Reference<text::XText> textbox(getShape(1), uno::UNO_QUERY);
834 CPPUNIT_ASSERT_EQUAL(3, getParagraphs(textbox));
835 uno::Reference<text::XTextRange> xParagraph = getParagraphOfText(1, textbox);
836 CPPUNIT_ASSERT_EQUAL(sal_Int32(212), getProperty<sal_Int32>(xParagraph, "ParaBottomMargin"));
838 // This wasn't zero (it was inherited from style of the previous paragraph in the main text)
839 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xParagraph, "ParaTopMargin"));
842 DECLARE_OOXMLEXPORT_TEST(testTdf136955, "tdf134784.docx")
844 uno::Reference<text::XText> textbox(getShape(1), uno::UNO_QUERY);
845 CPPUNIT_ASSERT_EQUAL(3, getParagraphs(textbox));
846 uno::Reference<text::XTextRange> xParagraph = getParagraphOfText(2, textbox);
848 // These weren't zero (values inherited from style of the previous paragraph in the main text)
849 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xParagraph, "ParaBottomMargin"));
850 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xParagraph, "ParaTopMargin"));
853 DECLARE_OOXMLEXPORT_TEST(testTdf104348_contextMargin, "tdf104348_contextMargin.docx")
855 // tdf#104348 shows that ContextMargin belongs with Top/Bottom handling
857 uno::Reference<beans::XPropertySet> xMyStyle(getStyles("ParagraphStyles")->getByName("MyStyle"), uno::UNO_QUERY);
858 // from paragraph style - this is what direct formatting should equal
859 sal_Int32 nMargin = getProperty<sal_Int32>(xMyStyle, "ParaBottomMargin");
860 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nMargin);
861 // from direct formatting
862 CPPUNIT_ASSERT_EQUAL(nMargin, getProperty<sal_Int32>(getParagraph(2), "ParaBottomMargin"));
865 DECLARE_OOXMLEXPORT_TEST(testTdf152310, "ColorOverwritten.docx")
867 uno::Reference<text::XText> xShape(getShape(1), uno::UNO_QUERY);
869 CPPUNIT_ASSERT_EQUAL(Color(0xFF0000),
870 getProperty<Color>(getParagraphOfText(1, xShape), "CharColor"));
871 CPPUNIT_ASSERT_EQUAL(Color(0x00b050),
872 getProperty<Color>(getParagraphOfText(2, xShape), "CharColor"));
875 DECLARE_OOXMLEXPORT_TEST(testTdf149996, "lorem_hyperlink.fodt")
877 // Without the accompanying fix in place, this test would have crashed,
878 // because the exported file was corrupted.
881 DECLARE_OOXMLEXPORT_TEST(testGroupedShapeLink, "grouped_link.docx")
883 // tdf#145147 Hyperlink in grouped shape not imported
884 // tdf#154469 Hyperlink in grouped shape not exported
885 uno::Reference<drawing::XShapes> xGroupShape(getShape(1), uno::UNO_QUERY);
886 CPPUNIT_ASSERT_EQUAL(OUString("https://www.libreoffice.org"),
887 getProperty<OUString>(xGroupShape->getByIndex(0), "Hyperlink"));
888 CPPUNIT_ASSERT_EQUAL(OUString("https://www.documentfoundation.org"),
889 getProperty<OUString>(xGroupShape->getByIndex(1), "Hyperlink"));
892 DECLARE_OOXMLEXPORT_TEST(testTdf147810, "tdf147810.odt")
894 // Without the accompanying fix in place, this test would have crashed,
895 // because the exported file was corrupted.
898 CPPUNIT_PLUGIN_IMPLEMENT();
900 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */