tdf#124754 sw docx import: do not override text color with -1 (auto) color
[LibreOffice.git] / sw / qa / extras / ooxmlimport / ooxmlimport2.cxx
blob1c7282623b003686b9717eb5dd657d0dddda2557
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 #ifdef MACOSX
11 #define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0
12 #include <premac.h>
13 #include <AppKit/AppKit.h>
14 #include <postmac.h>
15 #endif
17 #include <swmodeltestbase.hxx>
18 #include <wrtsh.hxx>
19 #include <com/sun/star/document/XEmbeddedObjectSupplier2.hpp>
20 #include <com/sun/star/embed/Aspects.hpp>
22 class Test : public SwModelTestBase
24 public:
25 Test()
26 : SwModelTestBase("/sw/qa/extras/ooxmlimport/data/", "Office Open XML Text")
31 DECLARE_OOXMLIMPORT_TEST(testTdf108545_embeddedDocxIcon, "tdf108545_embeddedDocxIcon.docx")
33 uno::Reference<document::XEmbeddedObjectSupplier2> xSupplier(getShape(1), uno::UNO_QUERY);
34 CPPUNIT_ASSERT_EQUAL(embed::Aspects::MSOLE_ICON, xSupplier->getAspect());
37 DECLARE_OOXMLIMPORT_TEST(testTdf121203, "tdf121203.docx")
39 // Make sure that the date SDT's content is imported as plain text, as it
40 // has no ISO date, so we have no idea how to represent that with our date
41 // control.
42 CPPUNIT_ASSERT_EQUAL(OUString("17-Oct-2018 09:00"), getRun(getParagraph(1), 1)->getString());
45 DECLARE_OOXMLIMPORT_TEST(testTdf109053, "tdf109053.docx")
47 // Table was imported into a text frame which led to a one page document
48 // Originally the table takes two pages, so Writer should import it accordingly.
49 CPPUNIT_ASSERT_EQUAL(2, getPages());
52 DECLARE_OOXMLIMPORT_TEST(testTdf121664, "tdf121664.docx")
54 uno::Reference<text::XLineNumberingProperties> xLineNumbering(mxComponent, uno::UNO_QUERY);
55 CPPUNIT_ASSERT(xLineNumbering.is());
56 // Without the accompanying fix in place, numbering did not restart on the
57 // second page.
58 CPPUNIT_ASSERT(
59 getProperty<bool>(xLineNumbering->getLineNumberingProperties(), "RestartAtEachPage"));
62 DECLARE_OOXMLIMPORT_TEST(testTdf108849, "tdf108849.docx")
64 // sectPr element that is child element of body must be the last child. However, Word accepts it
65 // in wrong places, and we should do the same (bug-to-bug compatibility) without creating extra sections.
66 CPPUNIT_ASSERT_EQUAL(2, getParagraphs());
67 CPPUNIT_ASSERT_EQUAL_MESSAGE("Misplaced body-level sectPr's create extra sections!", 2,
68 getPages());
71 DECLARE_OOXMLIMPORT_TEST(testTdf109524, "tdf109524.docx")
73 uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
74 uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(),
75 uno::UNO_QUERY);
76 // The table should have a small width (just to hold the short text in its single cell).
77 // Until it's correctly implemented, we assign it 100% relative width.
78 // Previously, the table (without explicitly set width) had huge actual width
79 // and extended far outside of page's right border.
80 CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xTables->getByIndex(0), "IsWidthRelative"));
81 CPPUNIT_ASSERT_EQUAL(sal_Int16(100),
82 getProperty<sal_Int16>(xTables->getByIndex(0), "RelativeWidth"));
85 DECLARE_OOXMLIMPORT_TEST(testGroupShapeFontName, "groupshape-fontname.docx")
87 // Font names inside a group shape were not imported
88 uno::Reference<container::XIndexAccess> xGroup(getShape(1), uno::UNO_QUERY);
89 uno::Reference<text::XText> xText
90 = uno::Reference<text::XTextRange>(xGroup->getByIndex(1), uno::UNO_QUERY_THROW)->getText();
92 CPPUNIT_ASSERT_EQUAL(
93 OUString("Calibri"),
94 getProperty<OUString>(getRun(getParagraphOfText(1, xText), 1), "CharFontName"));
95 CPPUNIT_ASSERT_EQUAL(
96 OUString("Calibri"),
97 getProperty<OUString>(getRun(getParagraphOfText(1, xText), 1), "CharFontNameComplex"));
98 CPPUNIT_ASSERT_EQUAL(
99 OUString(""),
100 getProperty<OUString>(getRun(getParagraphOfText(1, xText), 1), "CharFontNameAsian"));
103 DECLARE_OOXMLIMPORT_TEST(testTdf120548, "tdf120548.docx")
105 // Without the accompanying fix in place, this test would have failed with 'Expected: 00ff0000;
106 // Actual: ffffffff', i.e. the numbering portion was black, not red.
107 CPPUNIT_ASSERT_EQUAL(OUString("00ff0000"),
108 parseDump("//Special[@nType='PortionType::Number']/SwFont", "color"));
111 DECLARE_OOXMLIMPORT_TEST(test120551, "tdf120551.docx")
113 auto nHoriOrientPosition = getProperty<sal_Int32>(getShape(1), "HoriOrientPosition");
114 // Without the accompanying fix in place, this test would have failed with
115 // 'Expected: 436, Actual : -2542'.
116 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(436), nHoriOrientPosition);
119 DECLARE_OOXMLIMPORT_TEST(testTdf111550, "tdf111550.docx")
121 // The test document has following ill-formed structure:
123 // <w:tbl>
124 // ...
125 // <w:tr>
126 // <w:tc>
127 // <w:p>
128 // <w:r>
129 // <w:t>[outer:A2]</w:t>
130 // <w:br w:type="textWrapping"/>
131 // </w:r>
132 // <w:tbl>
133 // <w:tr>
134 // <w:tc>
135 // <w:p>
136 // <w:r>
137 // <w:t>[inner:A1]</w:t>
138 // </w:r>
139 // </w:p>
140 // </w:tc>
141 // </w:tr>
142 // </w:tbl>
143 // </w:p>
144 // </w:tc>
145 // </w:tr>
146 // </w:tbl>
148 // i.e., a <w:tbl> as direct child of <w:p> inside another table.
149 // Word accepts that illegal OOXML, and treats it as equal to
151 // <w:tbl>
152 // ...
153 // <w:tr>
154 // <w:tc>
155 // <w:tbl>
156 // <w:tr>
157 // <w:tc>
158 // <w:p>
159 // <w:r>
160 // <w:t>[outer:A2]</w:t>
161 // <w:br w:type="textWrapping"/>
162 // </w:r>
163 // <w:r>
164 // <w:t>[inner:A1]</w:t>
165 // </w:r>
166 // </w:p>
167 // </w:tc>
168 // </w:tr>
169 // </w:tbl>
170 // </w:tc>
171 // </w:tr>
172 // </w:tbl>
174 // i.e., moves all contents of the outer paragraph into the inner table's first paragraph.
176 CPPUNIT_ASSERT_EQUAL(2, getParagraphs());
178 uno::Reference<text::XTextContent> outerTable = getParagraphOrTable(1);
179 getCell(outerTable, "A1", "[outer:A1]");
180 uno::Reference<text::XText> cellA2(getCell(outerTable, "A2"), uno::UNO_QUERY_THROW);
181 uno::Reference<text::XTextContent> innerTable = getParagraphOrTable(1, cellA2);
182 getCell(innerTable, "A1", "[outer:A2]\n[inner:A1]");
185 DECLARE_OOXMLIMPORT_TEST(testTdf117843, "tdf117843.docx")
187 uno::Reference<container::XNameAccess> xPageStyles = getStyles("PageStyles");
188 uno::Reference<style::XStyle> xPageStyle(xPageStyles->getByName("Standard"), uno::UNO_QUERY);
189 uno::Reference<text::XText> xHeaderText
190 = getProperty<uno::Reference<text::XText>>(xPageStyle, "HeaderText");
191 // This was 4025, increased top paragraph margin was unexpected.
192 CPPUNIT_ASSERT_EQUAL(
193 static_cast<sal_Int32>(0),
194 getProperty<sal_Int32>(getParagraphOfText(1, xHeaderText), "ParaTopMargin"));
197 // related tdf#124754
198 DECLARE_OOXMLIMPORT_TEST(testTdf43017, "tdf43017.docx")
200 uno::Reference<text::XTextRange> xParagraph = getParagraph(1);
201 uno::Reference<text::XTextRange> xText = getRun(xParagraph, 2, "kick the bucket");
203 // Ensure that hyperlink text color is not blue (0x0000ff), but default (-1)
204 CPPUNIT_ASSERT_EQUAL_MESSAGE("Hyperlink color should be black!", sal_Int32(-1),
205 getProperty<sal_Int32>(xText, "CharColor"));
208 // related tdf#43017
209 DECLARE_OOXMLIMPORT_TEST(testTdf124754, "tdf124754.docx")
211 uno::Reference<text::XText> textbox(getShape(1), uno::UNO_QUERY);
212 CPPUNIT_ASSERT_EQUAL(1, getParagraphs(textbox));
214 uno::Reference<text::XTextRange> xParagraph = getParagraphOfText(1, textbox);
215 uno::Reference<text::XTextRange> xText = getRun(xParagraph, 2);
217 // Ensure that hyperlink text color is not black
218 CPPUNIT_ASSERT_EQUAL_MESSAGE("Hyperlink color should be not black!", sal_Int32(353217),
219 getProperty<sal_Int32>(xText, "CharColor"));
222 DECLARE_OOXMLIMPORT_TEST(testTdf112443, "tdf112443.docx")
224 // the position of the flying text frame should be off page
225 // 30624 below its anchor
226 OUString aTop = parseDump("//fly[1]/infos/bounds", "top");
227 CPPUNIT_ASSERT_EQUAL(OUString("30624"), aTop);
230 // DOCX: Textbox wrap differs in MSO and LO
231 // Both should layout text regardless of existing text box
232 // and as result only one page should be generated.
233 DECLARE_OOXMLIMPORT_TEST(testTdf113182, "tdf113182.docx") { CPPUNIT_ASSERT_EQUAL(1, getPages()); }
235 DECLARE_OOXMLIMPORT_TEST(testTdf124398, "tdf124398.docx")
237 uno::Reference<container::XIndexAccess> xGroup(getShape(1), uno::UNO_QUERY);
238 CPPUNIT_ASSERT(xGroup.is());
239 // Without the accompanying fix in place, this test would have failed with 'Expected: 2; Actual:
240 // 1', i.e. the chart children of the group shape was lost.
241 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xGroup->getCount());
243 uno::Reference<drawing::XShapeDescriptor> xShape(xGroup->getByIndex(1), uno::UNO_QUERY);
244 CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.drawing.OLE2Shape"), xShape->getShapeType());
247 DECLARE_OOXMLIMPORT_TEST(testTdf113946, "tdf113946.docx")
249 OUString aTop = parseDump("/root/page/body/txt/anchored/SwAnchoredDrawObject/bounds", "top");
250 // tdf#106792 Checked loading of tdf113946.docx. Before the change, the expected
251 // value of this test was "1696". Opening the file shows a single short line anchored
252 // at the doc start. Only diff is that in 'old' version it is slightly rotated, in 'new'
253 // version line is strict horizontal. Checked against MSWord2013, there the line
254 // is also not rotated -> the change is to the better, correct the expected result here.
255 CPPUNIT_ASSERT_EQUAL(OUString("1695"), aTop);
258 DECLARE_OOXMLIMPORT_TEST(testTdf121804, "tdf121804.docx")
260 uno::Reference<container::XIndexAccess> xGroup(getShape(1), uno::UNO_QUERY);
261 uno::Reference<text::XTextRange> xShape(xGroup->getByIndex(0), uno::UNO_QUERY);
262 uno::Reference<text::XTextRange> xFirstPara = getParagraphOfText(1, xShape->getText());
263 uno::Reference<text::XTextRange> xFirstRun = getRun(xFirstPara, 1);
264 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0),
265 getProperty<sal_Int32>(xFirstRun, "CharEscapement"));
266 // This failed with a NoSuchElementException, super/subscript property was
267 // lost on import, so the whole paragraph was a single run.
268 uno::Reference<text::XTextRange> xSecondRun = getRun(xFirstPara, 2);
269 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(30),
270 getProperty<sal_Int32>(xSecondRun, "CharEscapement"));
271 uno::Reference<text::XTextRange> xThirdRun = getRun(xFirstPara, 3);
272 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-25),
273 getProperty<sal_Int32>(xThirdRun, "CharEscapement"));
276 DECLARE_OOXMLIMPORT_TEST(testTdf114217, "tdf114217.docx")
278 uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
279 uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
280 // This was 1, multi-page table was imported as a floating one.
281 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), xDrawPage->getCount());
284 DECLARE_OOXMLIMPORT_TEST(testTdf116486, "tdf116486.docx")
286 OUString aTop = parseDump("/root/page/body/txt/Special", "nHeight");
287 CPPUNIT_ASSERT_EQUAL(OUString("4006"), aTop);
290 DECLARE_OOXMLIMPORT_TEST(testTdf119200, "tdf119200.docx")
292 auto xPara = getParagraph(1);
293 // Check that we import MathType functional symbols as symbols, not functions with missing args
294 CPPUNIT_ASSERT_EQUAL(OUString(u" size 12{ func \u2208 } {}"), getFormula(getRun(xPara, 1)));
295 CPPUNIT_ASSERT_EQUAL(OUString(u" size 12{ func \u2209 } {}"), getFormula(getRun(xPara, 2)));
296 CPPUNIT_ASSERT_EQUAL(OUString(u" size 12{ func \u2282 } {}"), getFormula(getRun(xPara, 3)));
297 CPPUNIT_ASSERT_EQUAL(OUString(u" size 12{ func \u2283 } {}"), getFormula(getRun(xPara, 4)));
298 CPPUNIT_ASSERT_EQUAL(OUString(u" size 12{ func \u2284 } {}"), getFormula(getRun(xPara, 5)));
299 CPPUNIT_ASSERT_EQUAL(OUString(u" size 12{ func \u2286 } {}"), getFormula(getRun(xPara, 6)));
300 CPPUNIT_ASSERT_EQUAL(OUString(u" size 12{ func \u2287 } {}"), getFormula(getRun(xPara, 7)));
303 DECLARE_OOXMLIMPORT_TEST(testTdf115094, "tdf115094.docx")
305 // anchor of graphic has to be the text in the text frame
306 // xray ThisComponent.DrawPage(1).Anchor.Text
307 uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
308 uno::Reference<container::XIndexAccess> xDrawPage(xDrawPageSupplier->getDrawPage(),
309 uno::UNO_QUERY);
310 uno::Reference<text::XTextContent> xShape(xDrawPage->getByIndex(1), uno::UNO_QUERY);
311 uno::Reference<text::XTextRange> xText1(xShape->getAnchor()->getText(), uno::UNO_QUERY);
313 // xray ThisComponent.TextTables(0).getCellByName("A1")
314 uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
315 uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(),
316 uno::UNO_QUERY);
317 uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
318 uno::Reference<text::XTextRange> xText2(xTable->getCellByName("A1"), uno::UNO_QUERY);
320 CPPUNIT_ASSERT_EQUAL(xText1.get(), xText2.get());
323 DECLARE_OOXMLIMPORT_TEST(testTdf115094v2, "tdf115094v2.docx")
325 // Introduce new attribute "layoutInCell"
327 CPPUNIT_ASSERT(getProperty<bool>(getShapeByName("Grafik 18"), "IsLayoutInCell"));
328 CPPUNIT_ASSERT(getProperty<bool>(getShapeByName("Grafik 19"), "IsLayoutInCell"));
331 DECLARE_OOXMLIMPORT_TEST(testTdf122224, "tdf122224.docx")
333 uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
334 uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(),
335 uno::UNO_QUERY);
336 uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
337 uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A2"), uno::UNO_QUERY_THROW);
338 // This was "** Expression is faulty **", because of the unnecessary DOCX number format string
339 CPPUNIT_ASSERT_EQUAL(OUString("2000"), xCell->getString());
342 DECLARE_OOXMLIMPORT_TEST(testTdf121440, "tdf121440.docx")
344 // Insert some text in front of footnote
345 SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
346 CPPUNIT_ASSERT(pTextDoc);
347 SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
348 SwRootFrame* pLayout(pWrtShell->GetLayout());
349 CPPUNIT_ASSERT(!pLayout->IsHideRedlines());
350 pWrtShell->Insert("test");
352 // Ensure that inserted text is not superscripted
353 CPPUNIT_ASSERT_EQUAL_MESSAGE(
354 "Inserted text should be not a superscript!", static_cast<sal_Int32>(0),
355 getProperty<sal_Int32>(getRun(getParagraph(1), 1), "CharEscapement"));
358 DECLARE_OOXMLIMPORT_TEST(testTdf124670, "tdf124670.docx")
360 CPPUNIT_ASSERT_EQUAL(1, getParagraphs());
361 // We need to take xml:space attribute into account, even in w:document element
362 uno::Reference<text::XTextRange> paragraph = getParagraph(1);
363 CPPUNIT_ASSERT_EQUAL(
364 OUString("You won't believe, but that's how it was in markup of original bugdoc!"),
365 paragraph->getString());
368 // tests should only be added to ooxmlIMPORT *if* they fail round-tripping in ooxmlEXPORT
370 CPPUNIT_PLUGIN_IMPLEMENT();
372 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */