Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / qa / extras / rtfexport / rtfexport5.cxx
blobc8b9ac0dc2069b0acec6fe3942b215230d893d23
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/awt/FontWeight.hpp>
13 #include <com/sun/star/style/LineSpacing.hpp>
14 #include <com/sun/star/style/LineSpacingMode.hpp>
15 #include <com/sun/star/style/ParagraphAdjust.hpp>
16 #include <com/sun/star/style/TabStop.hpp>
17 #include <com/sun/star/text/RelOrientation.hpp>
18 #include <com/sun/star/text/TableColumnSeparator.hpp>
19 #include <com/sun/star/text/XFootnotesSupplier.hpp>
20 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
21 #include <com/sun/star/text/XTextTablesSupplier.hpp>
22 #include <com/sun/star/text/XTextTable.hpp>
23 #include <com/sun/star/text/XTextDocument.hpp>
24 #include <com/sun/star/beans/XPropertyState.hpp>
25 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
27 #include <tools/UnitConversion.hxx>
28 #include <comphelper/sequenceashashmap.hxx>
30 using namespace css;
32 class Test : public SwModelTestBase
34 public:
35 Test()
36 : SwModelTestBase("/sw/qa/extras/rtfexport/data/", "Rich Text Format")
41 DECLARE_RTFEXPORT_TEST(testFdo63023, "fdo63023.rtf")
43 uno::Reference<text::XText> xHeaderText = getProperty<uno::Reference<text::XText>>(
44 getStyles("PageStyles")->getByName("Standard"), "HeaderText");
45 // Back color was black (0) in the header, due to missing color table in the substream.
46 CPPUNIT_ASSERT_EQUAL(
47 Color(0xFFFF99),
48 getProperty<Color>(getRun(getParagraphOfText(1, xHeaderText), 1), "CharBackColor"));
51 DECLARE_RTFEXPORT_TEST(testFdo42109, "fdo42109.rtf")
53 uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
54 uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(),
55 uno::UNO_QUERY);
56 uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
57 uno::Reference<text::XTextRange> xCell(xTable->getCellByName("B1"), uno::UNO_QUERY);
58 // Make sure the page number is imported as a field in the B1 cell.
59 CPPUNIT_ASSERT_EQUAL(OUString("TextField"),
60 getProperty<OUString>(getRun(getParagraphOfText(1, xCell->getText()), 1),
61 "TextPortionType"));
64 DECLARE_RTFEXPORT_TEST(testFdo62977, "fdo62977.rtf")
66 // The middle character was imported as '?' instead of the proper unicode value.
67 getRun(getParagraph(1), 1, OUString(u"\u5E74\uFF14\u6708"));
70 DECLARE_RTFEXPORT_TEST(testN818997, "n818997.rtf")
72 // \page was ignored between two \shp tokens.
73 CPPUNIT_ASSERT_EQUAL(2, getPages());
76 DECLARE_RTFEXPORT_TEST(testN818997B, "n818997B.rtf")
78 // \page was ignored between two \shp tokens - this time not IsFirstParagraphInSection.
79 CPPUNIT_ASSERT_EQUAL(2, getPages());
82 DECLARE_RTFEXPORT_TEST(testTdf153613_anchoredAfterPgBreak, "tdf153613_anchoredAfterPgBreak.rtf")
84 // An anchored TO character image (followed by nothing) anchors before the page break, no split.
85 CPPUNIT_ASSERT_EQUAL(2, getPages());
86 CPPUNIT_ASSERT_EQUAL(3, getParagraphs());
88 const auto& pLayout = parseLayoutDump();
89 assertXPath(pLayout, "//page[1]//anchored", 1);
92 DECLARE_RTFEXPORT_TEST(testTdf153613_anchoredAfterPgBreak2, "tdf153613_anchoredAfterPgBreak2.rtf")
94 // An anchored TO character image, followed by more characters moves to the following page
95 CPPUNIT_ASSERT_EQUAL(2, getPages());
96 CPPUNIT_ASSERT_EQUAL(3, getParagraphs());
98 const auto& pLayout = parseLayoutDump();
99 assertXPath(pLayout, "//page[2]//anchored", 1);
102 DECLARE_RTFEXPORT_TEST(testTdf153613_anchoredAfterPgBreak4, "tdf153613_anchoredAfterPgBreak4.rtf")
104 // An anchored TO character image (followed by nothing) anchors before the page break, no split.
105 // This differs from #1 only in that it has a preceding character run before the page break.
106 CPPUNIT_ASSERT_EQUAL(2, getPages());
107 CPPUNIT_ASSERT_MESSAGE("YOU FIXED ME!", 3 != getParagraphs());
109 const auto& pLayout = parseLayoutDump();
110 assertXPath(pLayout, "//page[2]//anchored", 1); // DID YOU FIX ME? This should be page[1]
113 DECLARE_RTFEXPORT_TEST(testTdf153613_anchoredAfterPgBreak5, "tdf153613_anchoredAfterPgBreak5.rtf")
115 // Two anchored TO character images (followed by nothing) splits & anchors after the page break
116 // This differs from #1 only in that it has two anchored images.
117 CPPUNIT_ASSERT_EQUAL(2, getPages());
118 CPPUNIT_ASSERT_EQUAL(3, getParagraphs());
120 const auto& pLayout = parseLayoutDump();
121 assertXPath(pLayout, "//page[1]//anchored", 1);
124 DECLARE_RTFEXPORT_TEST(testTdf153613_inlineAfterPgBreak, "tdf153613_inlineAfterPgBreak.rtf")
126 // An inline AS character image moves to the following page when after the page break.
127 CPPUNIT_ASSERT_EQUAL(2, getPages());
128 CPPUNIT_ASSERT_EQUAL(3, getParagraphs());
130 const auto& pLayout = parseLayoutDump();
131 assertXPath(pLayout, "//page[2]//anchored", 1);
134 DECLARE_RTFEXPORT_TEST(testTdf153613_inlineAfterPgBreak2, "tdf153613_inlineAfterPgBreak2.rtf")
136 // An inline AS character image moves to the following page when after the page break.
137 // The difference from the previous test is that it is not the first character run
138 CPPUNIT_ASSERT_EQUAL(2, getPages());
139 CPPUNIT_ASSERT_EQUAL(4, getParagraphs());
141 const auto& pLayout = parseLayoutDump();
142 CPPUNIT_ASSERT_EQUAL(OUString("x"), getXPathContent(pLayout, "//page[1]/body/txt[2]"));
143 assertXPath(pLayout, "//page[2]//anchored", 1);
146 DECLARE_RTFEXPORT_TEST(testFdo64671, "fdo64671.rtf")
148 // Additional '}' was inserted before the special character.
149 getRun(getParagraph(1), 1, OUString(u"\u017D"));
152 CPPUNIT_TEST_FIXTURE(Test, testFdo62044)
154 createSwDoc("fdo62044.rtf");
155 // The problem was that RTF import during copy&paste did not ignore existing paragraph styles.
156 uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
157 uno::Reference<text::XTextRange> xText = xTextDocument->getText();
158 uno::Reference<text::XTextRange> xEnd = xText->getEnd();
159 paste(u"rtfexport/data/fdo62044-paste.rtf", "com.sun.star.comp.Writer.RtfFilter", xEnd);
161 uno::Reference<beans::XPropertySet> xPropertySet(
162 getStyles("ParagraphStyles")->getByName("Heading 1"), uno::UNO_QUERY);
163 CPPUNIT_ASSERT_EQUAL(
164 10.f, getProperty<float>(xPropertySet,
165 "CharHeight")); // Was 18, i.e. reset back to original value.
168 DECLARE_RTFEXPORT_TEST(testFdo70578, "fdo70578.rtf")
170 // Style without explicit \s0 was not imported as the default style
171 uno::Reference<beans::XPropertySet> xPropertySet(
172 getStyles("ParagraphStyles")->getByName("Subtitle"), uno::UNO_QUERY);
173 uno::Reference<style::XStyle> xStyle(xPropertySet, uno::UNO_QUERY);
174 CPPUNIT_ASSERT_EQUAL(OUString("Standard"), xStyle->getParentStyle());
175 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xPropertySet, "ParaTopMargin"));
176 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xPropertySet, "ParaBottomMargin"));
179 DECLARE_RTFEXPORT_TEST(testN825305, "n825305.rtf")
181 // The problem was that the textbox wasn't transparent, due to unimplemented fFilled == 0.
182 uno::Reference<beans::XPropertyState> xPropertyState(getShape(2), uno::UNO_QUERY);
183 CPPUNIT_ASSERT_EQUAL(Color(0x000064), getProperty<Color>(getShape(2), "BackColorTransparency"));
184 beans::PropertyState ePropertyState = xPropertyState->getPropertyState("BackColorTransparency");
185 // Was beans::PropertyState_DEFAULT_VALUE.
186 CPPUNIT_ASSERT_EQUAL(beans::PropertyState_DIRECT_VALUE, ePropertyState);
189 DECLARE_RTFEXPORT_TEST(testTdf106953, "tdf106953.rtf")
191 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1270),
192 getProperty<sal_Int32>(getParagraph(1), "ParaLeftMargin"));
193 auto xRules = getProperty<uno::Reference<container::XIndexAccess>>(
194 getStyles("NumberingStyles")->getByName("WWNum1"), "NumberingRules");
195 comphelper::SequenceAsHashMap aRule(xRules->getByIndex(0));
196 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), aRule["FirstLineIndent"].get<sal_Int32>());
199 DECLARE_RTFEXPORT_TEST(testTdf112208, "tdf112208_hangingIndent.rtf")
201 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-2000),
202 getProperty<sal_Int32>(getParagraph(1), "ParaFirstLineIndent"));
203 CPPUNIT_ASSERT_EQUAL(1, getPages());
206 DECLARE_RTFEXPORT_TEST(testParaBottomMargin, "para-bottom-margin.rtf")
208 uno::Reference<beans::XPropertySet> xPropertySet(
209 getStyles("ParagraphStyles")->getByName("Standard"), uno::UNO_QUERY);
210 CPPUNIT_ASSERT_EQUAL(sal_Int32(353), getProperty<sal_Int32>(xPropertySet, "ParaBottomMargin"));
212 // This was 353, i.e. bottom margin of the paragraph was 0.35cm instead of 0.
213 // The reason why this is 0 despite the default style containing \sa200
214 // is that Word will actually interpret \sN (or \pard which apparently
215 // implies \s0) as "set style N and for every attribute of that style,
216 // set an attribute with default value on the paragraph"
217 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(getParagraph(1), "ParaBottomMargin"));
218 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), getProperty<sal_Int32>(getParagraph(1), "ParaTopMargin"));
221 CPPUNIT_TEST_FIXTURE(Test, testParaStyleBottomMargin2)
223 createSwDoc("para-style-bottom-margin-2.rtf");
224 uno::Reference<beans::XPropertySet> xPropertySet(
225 getStyles("ParagraphStyles")->getByName("Standard"), uno::UNO_QUERY);
226 CPPUNIT_ASSERT_EQUAL(sal_Int32(353), getProperty<sal_Int32>(xPropertySet, "ParaBottomMargin"));
227 CPPUNIT_ASSERT_EQUAL(style::LineSpacingMode::PROP,
228 getProperty<style::LineSpacing>(xPropertySet, "ParaLineSpacing").Mode);
229 CPPUNIT_ASSERT_EQUAL(sal_Int16(115),
230 getProperty<style::LineSpacing>(xPropertySet, "ParaLineSpacing").Height);
232 // the derived style contains \sa200, as does its parent
233 uno::Reference<beans::XPropertySet> xPropertySet1(
234 getStyles("ParagraphStyles")->getByName("List Paragraph"), uno::UNO_QUERY);
235 CPPUNIT_ASSERT_EQUAL(sal_Int32(353), getProperty<sal_Int32>(xPropertySet1, "ParaBottomMargin"));
236 CPPUNIT_ASSERT_EQUAL(style::LineSpacingMode::PROP,
237 getProperty<style::LineSpacing>(xPropertySet1, "ParaLineSpacing").Mode);
238 CPPUNIT_ASSERT_EQUAL(sal_Int16(115),
239 getProperty<style::LineSpacing>(xPropertySet1, "ParaLineSpacing").Height);
240 // for the paragraph there is no \saN, so it should default to 0
241 auto const xPara(getParagraph(1));
242 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xPara, "ParaBottomMargin"));
243 CPPUNIT_ASSERT_EQUAL(style::LineSpacingMode::PROP,
244 getProperty<style::LineSpacing>(xPara, "ParaLineSpacing").Mode);
245 CPPUNIT_ASSERT_EQUAL(sal_Int16(115),
246 getProperty<style::LineSpacing>(xPara, "ParaLineSpacing").Height);
249 DECLARE_RTFEXPORT_TEST(testFdo66040, "fdo66040.rtf")
251 // This was 0 (no shapes were imported), we want two textframes.
252 CPPUNIT_ASSERT_EQUAL(2, getShapes());
254 // The second paragraph of the first shape should be actually a table, with "A" in its A1 cell.
255 uno::Reference<text::XTextRange> xTextRange(getShape(1), uno::UNO_QUERY);
256 uno::Reference<text::XText> xText = xTextRange->getText();
257 uno::Reference<text::XTextTable> xTable(getParagraphOrTable(2, xText), uno::UNO_QUERY);
258 CPPUNIT_ASSERT_EQUAL(OUString("A"), uno::Reference<text::XTextRange>(
259 xTable->getCellByName("A1"), uno::UNO_QUERY_THROW)
260 ->getString());
262 // Make sure the second shape has the correct position and size.
263 uno::Reference<drawing::XShape> xShape(getShape(2), uno::UNO_QUERY);
264 CPPUNIT_ASSERT_EQUAL(sal_Int32(14420), getProperty<sal_Int32>(xShape, "HoriOrientPosition"));
265 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1032), getProperty<sal_Int32>(xShape, "VertOrientPosition"));
266 CPPUNIT_ASSERT_EQUAL(sal_Int32(14000), xShape->getSize().Width);
267 CPPUNIT_ASSERT_EQUAL(sal_Int32(21001), xShape->getSize().Height);
270 DECLARE_RTFEXPORT_TEST(testFdo77996, "fdo77996.rtf")
272 // all styles were imported as name "0"
273 uno::Reference<container::XNameAccess> xChars(getStyles("CharacterStyles"));
274 CPPUNIT_ASSERT(!xChars->hasByName("0"));
275 CPPUNIT_ASSERT(xChars->hasByName("strong"));
276 CPPUNIT_ASSERT(xChars->hasByName("author"));
277 uno::Reference<container::XNameAccess> xParas(getStyles("ParagraphStyles"));
278 CPPUNIT_ASSERT(!xParas->hasByName("0"));
279 CPPUNIT_ASSERT(xParas->hasByName("extract2"));
280 // some document properties were lost
281 uno::Reference<document::XDocumentPropertiesSupplier> xDocumentPropertiesSupplier(
282 mxComponent, uno::UNO_QUERY);
283 uno::Reference<document::XDocumentProperties> xProps(
284 xDocumentPropertiesSupplier->getDocumentProperties());
285 CPPUNIT_ASSERT_EQUAL(OUString("Aln Lin (Bei Jing)"), xProps->getAuthor());
286 OUString aTitle(u"\u53A6\u95E8\u94A8\u4E1A\u80A1\u4EFD\u6709\u9650\u516C\u53F8");
287 CPPUNIT_ASSERT_EQUAL(aTitle, xProps->getTitle());
288 uno::Reference<beans::XPropertySet> xUDProps(xProps->getUserDefinedProperties(),
289 uno::UNO_QUERY);
290 CPPUNIT_ASSERT_EQUAL(OUString("jay"), getProperty<OUString>(xUDProps, "Operator"));
292 // fdo#80486 also check that the ftnsep doesn't insert paragraph breaks
293 getParagraph(1, aTitle);
296 DECLARE_RTFEXPORT_TEST(testFdo47802, "fdo47802.rtf")
298 // Shape inside table was ignored.
299 CPPUNIT_ASSERT_EQUAL(1, getShapes());
302 DECLARE_RTFEXPORT_TEST(testFdo39001, "fdo39001.rtf")
304 // Document was of 4 pages, \sect at the end of the doc wasn't ignored.
305 CPPUNIT_ASSERT_EQUAL(3, getPages());
308 DECLARE_RTFEXPORT_TEST(testFdo54900, "fdo54900.rtf")
310 uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
311 uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(),
312 uno::UNO_QUERY);
313 uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
314 uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY);
315 // Paragraph was aligned to left, should be center.
316 CPPUNIT_ASSERT_EQUAL(style::ParagraphAdjust_CENTER,
317 static_cast<style::ParagraphAdjust>(getProperty<sal_Int16>(
318 getParagraphOfText(1, xCell->getText()), "ParaAdjust")));
321 DECLARE_RTFEXPORT_TEST(testFdo64637, "fdo64637.rtf")
323 // The problem was that the custom "Company" property was added twice, the second invocation resulted in an exception.
324 uno::Reference<document::XDocumentPropertiesSupplier> xDocumentPropertiesSupplier(
325 mxComponent, uno::UNO_QUERY);
326 uno::Reference<beans::XPropertySet> xPropertySet(
327 xDocumentPropertiesSupplier->getDocumentProperties()->getUserDefinedProperties(),
328 uno::UNO_QUERY);
329 CPPUNIT_ASSERT_EQUAL(OUString("bbb"), getProperty<OUString>(xPropertySet, "Company"));
332 DECLARE_RTFEXPORT_TEST(testN820504, "n820504.rtf")
334 // The shape was anchored at-page instead of at-character (that's incorrect as Word only supports at-character and as-character).
335 CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AT_CHARACTER,
336 getProperty<text::TextContentAnchorType>(getShape(1), "AnchorType"));
339 DECLARE_RTFEXPORT_TEST(testFdo67498, "fdo67498.rtf")
341 // Left margin of the default page style wasn't set (was 2000).
342 CPPUNIT_ASSERT_EQUAL(
343 sal_Int32(convertTwipToMm100(5954)),
344 getProperty<sal_Int32>(getStyles("PageStyles")->getByName("Standard"), "LeftMargin"));
347 DECLARE_RTFEXPORT_TEST(testFdo44715, "fdo44715.rtf")
349 uno::Reference<text::XTextTable> xTable(getParagraphOrTable(1), uno::UNO_QUERY);
350 uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY);
351 // Style information wasn't reset, which caused character height to be 16.
352 CPPUNIT_ASSERT_EQUAL(12.f,
353 getProperty<float>(getParagraphOfText(2, xCell->getText()), "CharHeight"));
356 DECLARE_RTFEXPORT_TEST(testFdo68076, "fdo68076.rtf")
358 // Encoding of the last char was wrong (more 'o' than 'y').
359 getParagraph(1, u"\u041E\u0431\u044A\u0435\u043A\u0442 \u2013 \u0443");
362 DECLARE_RTFEXPORT_TEST(testFdo70221, "fdo70221.rtf")
364 // The picture was imported twice.
365 CPPUNIT_ASSERT_EQUAL(1, getShapes());
368 DECLARE_RTFEXPORT_TEST(testCp1000018, "cp1000018.rtf")
370 // The problem was that the empty paragraph at the end of the footnote got
371 // lost during import.
372 uno::Reference<text::XFootnotesSupplier> xFootnotesSupplier(mxComponent, uno::UNO_QUERY);
373 uno::Reference<container::XIndexAccess> xFootnotes = xFootnotesSupplier->getFootnotes();
374 uno::Reference<text::XTextRange> xTextRange(xFootnotes->getByIndex(0), uno::UNO_QUERY);
376 OUString const aActual = xTextRange->getString();
378 CPPUNIT_ASSERT_EQUAL(OUString("Footnote first line." SAL_NEWLINE_STRING), aActual);
381 DECLARE_RTFEXPORT_TEST(testFdo94835, "fdo94835.rtf")
383 // The picture was imported twice.
384 CPPUNIT_ASSERT_EQUAL(19, getShapes());
386 DECLARE_RTFEXPORT_TEST(testNestedTable, "rhbz1065629.rtf")
388 // nested table in second cell was missing
389 uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
390 uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(),
391 uno::UNO_QUERY);
392 uno::Reference<text::XTextTable> xTable(xTables->getByIndex(1), uno::UNO_QUERY);
393 uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY);
394 uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xCell->getText(), uno::UNO_QUERY);
395 uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
396 uno::Reference<text::XTextRange> xPara(xParaEnum->nextElement(), uno::UNO_QUERY);
397 CPPUNIT_ASSERT_EQUAL(OUString("Responsable Commercial:"), xPara->getString());
398 xCell.set(xTable->getCellByName("A2"), uno::UNO_QUERY);
399 xParaEnumAccess.set(xCell->getText(), uno::UNO_QUERY);
400 xParaEnum = xParaEnumAccess->createEnumeration();
401 xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
402 xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
403 CPPUNIT_ASSERT_EQUAL(OUString("Nom: John Doe"), xPara->getString());
405 // outer table: background color, borders for B1/B2 cell
406 xTable.set(xTables->getByIndex(2), uno::UNO_QUERY);
407 xCell.set(xTable->getCellByName("A1"), uno::UNO_QUERY);
408 CPPUNIT_ASSERT(xCell.is());
409 table::BorderLine2 fullPtSolid(sal_Int32(COL_BLACK), 0, 35, 0, table::BorderLineStyle::SOLID,
410 35);
411 CPPUNIT_ASSERT_BORDER_EQUAL(fullPtSolid, getProperty<table::BorderLine2>(xCell, "LeftBorder"));
412 CPPUNIT_ASSERT_BORDER_EQUAL(fullPtSolid, getProperty<table::BorderLine2>(xCell, "RightBorder"));
413 CPPUNIT_ASSERT_BORDER_EQUAL(fullPtSolid, getProperty<table::BorderLine2>(xCell, "TopBorder"));
414 CPPUNIT_ASSERT_BORDER_EQUAL(fullPtSolid,
415 getProperty<table::BorderLine2>(xCell, "BottomBorder"));
416 CPPUNIT_ASSERT_EQUAL(Color(0xCC0000), getProperty<Color>(xCell, "BackColor"));
417 xCell.set(xTable->getCellByName("A2"), uno::UNO_QUERY);
418 CPPUNIT_ASSERT(xCell.is());
419 table::BorderLine2 halfPtSolid(sal_Int32(COL_BLACK), 0, 18, 0, table::BorderLineStyle::SOLID,
420 18);
421 CPPUNIT_ASSERT_BORDER_EQUAL(halfPtSolid, getProperty<table::BorderLine2>(xCell, "LeftBorder"));
422 CPPUNIT_ASSERT_EQUAL(COL_TRANSPARENT, getProperty<Color>(xCell, "BackColor"));
423 xCell.set(xTable->getCellByName("B2"), uno::UNO_QUERY);
424 CPPUNIT_ASSERT(xCell.is());
425 CPPUNIT_ASSERT_BORDER_EQUAL(halfPtSolid, getProperty<table::BorderLine2>(xCell, "LeftBorder"));
426 CPPUNIT_ASSERT_BORDER_EQUAL(halfPtSolid, getProperty<table::BorderLine2>(xCell, "RightBorder"));
427 CPPUNIT_ASSERT_EQUAL(COL_TRANSPARENT, getProperty<Color>(xCell, "BackColor"));
429 // \sect at the end resulted in spurious page break
430 CPPUNIT_ASSERT_EQUAL(1, getPages());
433 DECLARE_RTFEXPORT_TEST(testFooterPara, "footer-para.rtf")
435 // check that paragraph properties in footer are imported
436 uno::Reference<text::XText> xFooterText = getProperty<uno::Reference<text::XText>>(
437 getStyles("PageStyles")->getByName("First Page"), "FooterText");
438 uno::Reference<text::XTextContent> xParagraph = getParagraphOrTable(1, xFooterText);
439 CPPUNIT_ASSERT_EQUAL(
440 OUString("All Rights Reserved."),
441 uno::Reference<text::XTextRange>(xParagraph, uno::UNO_QUERY_THROW)->getString());
442 CPPUNIT_ASSERT_EQUAL(
443 sal_Int16(style::ParagraphAdjust_CENTER),
444 getProperty</*style::ParagraphAdjust*/ sal_Int16>(xParagraph, "ParaAdjust"));
447 DECLARE_RTFEXPORT_TEST(testTdf107413, "tdf107413.rtf")
449 CPPUNIT_ASSERT_EQUAL(1, getPages());
451 xmlDocUniquePtr pDump = parseLayoutDump();
452 const double nLeftFooter
453 = getXPath(pDump, "/root/page[1]/footer/infos/bounds", "left").toDouble();
454 const double nRightFooter
455 = getXPath(pDump, "/root/page[1]/footer/infos/bounds", "right").toDouble();
456 const double nTopFooter
457 = getXPath(pDump, "/root/page[1]/footer/infos/bounds", "top").toDouble();
458 const double nBottomFooter
459 = getXPath(pDump, "/root/page[1]/footer/infos/bounds", "bottom").toDouble();
461 // Without the fix in place, this test would have failed with
462 // - Expected: 1
463 // - Actual : 0
464 // - In <>, XPath '/root/page[1]/footer/txt/anchored/fly/infos/bounds' number of nodes is incorrect
465 const double nLeftFly
466 = getXPath(pDump, "/root/page[1]/footer/txt/anchored/fly/infos/bounds", "left").toDouble();
467 const double nRightFly
468 = getXPath(pDump, "/root/page[1]/footer/txt/anchored/fly/infos/bounds", "right").toDouble();
469 const double nTopFly
470 = getXPath(pDump, "/root/page[1]/footer/txt/anchored/fly/infos/bounds", "top").toDouble();
471 const double nBottomFly
472 = getXPath(pDump, "/root/page[1]/footer/txt/anchored/fly/infos/bounds", "bottom")
473 .toDouble();
475 CPPUNIT_ASSERT_EQUAL(nLeftFooter, nLeftFly);
476 CPPUNIT_ASSERT_EQUAL(nRightFooter, nRightFly);
477 CPPUNIT_ASSERT_EQUAL(nBottomFooter, nBottomFly);
478 CPPUNIT_ASSERT_EQUAL(nTopFooter + 1056.0, nTopFly);
481 DECLARE_RTFEXPORT_TEST(testCp1000016, "hello.rtf")
483 // The single-line document had a second fake empty para on Windows.
484 CPPUNIT_ASSERT_EQUAL(1, getParagraphs());
487 DECLARE_RTFEXPORT_TEST(testFdo65090, "fdo65090.rtf")
489 uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
490 uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(),
491 uno::UNO_QUERY);
492 uno::Reference<text::XTextTable> xTextTable(xTables->getByIndex(0), uno::UNO_QUERY);
493 uno::Reference<table::XTableRows> xTableRows = xTextTable->getRows();
494 // The first row had 3 cells, instead of a horizontally merged one and a normal one (2 -> 1 separator).
495 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getProperty<uno::Sequence<text::TableColumnSeparator>>(
496 xTableRows->getByIndex(0), "TableColumnSeparators")
497 .getLength());
500 DECLARE_RTFEXPORT_TEST(testTableBorderDefaults, "fdo68779.rtf")
502 // table borders without \brdrw were not imported
503 uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
504 uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(),
505 uno::UNO_QUERY);
506 uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
507 uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY);
508 CPPUNIT_ASSERT(xCell.is());
509 table::BorderLine2 solid(sal_Int32(COL_BLACK), 0, 26, 0, table::BorderLineStyle::SOLID, 26);
510 CPPUNIT_ASSERT_BORDER_EQUAL(solid, getProperty<table::BorderLine2>(xCell, "LeftBorder"));
511 CPPUNIT_ASSERT_BORDER_EQUAL(solid, getProperty<table::BorderLine2>(xCell, "RightBorder"));
512 CPPUNIT_ASSERT_BORDER_EQUAL(solid, getProperty<table::BorderLine2>(xCell, "TopBorder"));
513 CPPUNIT_ASSERT_BORDER_EQUAL(solid, getProperty<table::BorderLine2>(xCell, "BottomBorder"));
515 xTable.set(xTables->getByIndex(1), uno::UNO_QUERY);
516 xCell.set(xTable->getCellByName("A1"), uno::UNO_QUERY);
517 CPPUNIT_ASSERT(xCell.is());
518 table::BorderLine2 dotted(sal_Int32(COL_BLACK), 0, 26, 0, table::BorderLineStyle::DOTTED, 26);
519 CPPUNIT_ASSERT_BORDER_EQUAL(dotted, getProperty<table::BorderLine2>(xCell, "LeftBorder"));
520 CPPUNIT_ASSERT_BORDER_EQUAL(dotted, getProperty<table::BorderLine2>(xCell, "RightBorder"));
521 CPPUNIT_ASSERT_BORDER_EQUAL(dotted, getProperty<table::BorderLine2>(xCell, "TopBorder"));
522 CPPUNIT_ASSERT_BORDER_EQUAL(dotted, getProperty<table::BorderLine2>(xCell, "BottomBorder"));
524 xTable.set(xTables->getByIndex(2), uno::UNO_QUERY);
525 xCell.set(xTable->getCellByName("A1"), uno::UNO_QUERY);
526 CPPUNIT_ASSERT(xCell.is());
527 table::BorderLine2 doubled(sal_Int32(COL_BLACK), 26, 26, 26, table::BorderLineStyle::DOUBLE,
528 79);
529 CPPUNIT_ASSERT_BORDER_EQUAL(doubled, getProperty<table::BorderLine2>(xCell, "LeftBorder"));
530 CPPUNIT_ASSERT_BORDER_EQUAL(doubled, getProperty<table::BorderLine2>(xCell, "RightBorder"));
531 CPPUNIT_ASSERT_BORDER_EQUAL(doubled, getProperty<table::BorderLine2>(xCell, "TopBorder"));
532 CPPUNIT_ASSERT_BORDER_EQUAL(doubled, getProperty<table::BorderLine2>(xCell, "BottomBorder"));
534 xTable.set(xTables->getByIndex(3), uno::UNO_QUERY);
535 xCell.set(xTable->getCellByName("A1"), uno::UNO_QUERY);
536 CPPUNIT_ASSERT(xCell.is());
537 table::BorderLine2 thinThickMG(sal_Int32(COL_BLACK), 14, 26, 14,
538 table::BorderLineStyle::THINTHICK_MEDIUMGAP, 53);
539 CPPUNIT_ASSERT_BORDER_EQUAL(thinThickMG, getProperty<table::BorderLine2>(xCell, "LeftBorder"));
540 CPPUNIT_ASSERT_BORDER_EQUAL(thinThickMG, getProperty<table::BorderLine2>(xCell, "RightBorder"));
541 CPPUNIT_ASSERT_BORDER_EQUAL(thinThickMG, getProperty<table::BorderLine2>(xCell, "TopBorder"));
542 CPPUNIT_ASSERT_BORDER_EQUAL(thinThickMG,
543 getProperty<table::BorderLine2>(xCell, "BottomBorder"));
546 DECLARE_RTFEXPORT_TEST(testShpzDhgt, "shpz-dhgt.rtf")
548 // Test that shpz has priority over dhgt and not the other way around.
549 // Drawpage is sorted by ZOrder, so first should be red (back).
550 CPPUNIT_ASSERT_EQUAL(Color(0xff0000), getProperty<Color>(getShape(1), "FillColor"));
551 // Second (front) should be green.
552 CPPUNIT_ASSERT_EQUAL(Color(0x00ff00), getProperty<Color>(getShape(2), "FillColor"));
555 DECLARE_RTFEXPORT_TEST(testLevelfollow, "levelfollow.rtf")
557 uno::Reference<container::XIndexAccess> xNum1Levels
558 = getProperty<uno::Reference<container::XIndexAccess>>(
559 getStyles("NumberingStyles")->getByName("WWNum1"), "NumberingRules");
560 CPPUNIT_ASSERT_EQUAL(
561 sal_Int16(SvxNumberFormat::LISTTAB),
562 comphelper::SequenceAsHashMap(xNum1Levels->getByIndex(0))["LabelFollowedBy"]
563 .get<sal_Int16>()); // first level, tab
565 uno::Reference<container::XIndexAccess> xNum2Levels
566 = getProperty<uno::Reference<container::XIndexAccess>>(
567 getStyles("NumberingStyles")->getByName("WWNum2"), "NumberingRules");
568 CPPUNIT_ASSERT_EQUAL(
569 sal_Int16(SvxNumberFormat::SPACE),
570 comphelper::SequenceAsHashMap(xNum2Levels->getByIndex(0))["LabelFollowedBy"]
571 .get<sal_Int16>()); // first level, space
573 uno::Reference<container::XIndexAccess> xNum3Levels
574 = getProperty<uno::Reference<container::XIndexAccess>>(
575 getStyles("NumberingStyles")->getByName("WWNum3"), "NumberingRules");
576 CPPUNIT_ASSERT_EQUAL(
577 sal_Int16(SvxNumberFormat::NOTHING),
578 comphelper::SequenceAsHashMap(xNum3Levels->getByIndex(0))["LabelFollowedBy"]
579 .get<sal_Int16>()); // first level, nothing
582 DECLARE_RTFEXPORT_TEST(testCharColor, "char-color.rtf")
584 // This was -1: character color wasn't set.
585 CPPUNIT_ASSERT_EQUAL(Color(0x365F91), getProperty<Color>(getParagraph(1), "CharColor"));
588 DECLARE_RTFEXPORT_TEST(testFdo69289, "fdo69289.rtf")
590 uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
591 uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(),
592 uno::UNO_QUERY);
593 uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
594 uno::Reference<table::XTableRows> xTableRows = xTable->getRows();
595 // There were only 2 cells (1 separators) in the table, should be 3 (2 separators).
596 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), getProperty<uno::Sequence<text::TableColumnSeparator>>(
597 xTableRows->getByIndex(0), "TableColumnSeparators")
598 .getLength());
601 DECLARE_RTFEXPORT_TEST(testDptxbxRelation, "dptxbx-relation.rtf")
603 // This was FRAME, not PAGE_FRAME, even if dobxpage is in the document.
604 CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME,
605 getProperty<sal_Int16>(getShape(1), "HoriOrientRelation"));
608 DECLARE_RTFEXPORT_TEST(testDprectAnchor, "dprect-anchor.rtf")
610 // This was at-page, which is not something Word supports, so clearly an import error.
611 CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AT_CHARACTER,
612 getProperty<text::TextContentAnchorType>(getShape(1), "AnchorType"));
615 DECLARE_RTFEXPORT_TEST(testFdo76628, "fdo76628.rtf")
617 // Should be 'SAMPLE' in Russian, was garbage.
618 getParagraph(1, u"\u041E\u0411\u0420\u0410\u0417\u0415\u0426");
620 uno::Reference<text::XText> xHeaderText = getProperty<uno::Reference<text::XText>>(
621 getStyles("PageStyles")->getByName("Standard"), "HeaderText");
622 // Should be 'prepared' in Russian, was garbage.
623 getParagraphOfText(1, xHeaderText,
624 u"\u041F\u043E\u0434\u0433\u043E\u0442\u043E\u0432\u043B\u0435\u043D\u043E");
627 DECLARE_RTFEXPORT_TEST(testFdo77267, "fdo77267.rtf")
629 // Paragraph was aligned to left, should be center.
630 CPPUNIT_ASSERT_EQUAL(
631 style::ParagraphAdjust_CENTER,
632 static_cast<style::ParagraphAdjust>(getProperty<sal_Int16>(getParagraph(1), "ParaAdjust")));
635 DECLARE_RTFEXPORT_TEST(testFdo75735, "fdo75735.rtf")
637 // Number of tabstops in the second paragraph should be 3, was 6.
638 CPPUNIT_ASSERT_EQUAL(
639 sal_Int32(3),
640 getProperty<uno::Sequence<style::TabStop>>(getParagraph(2), "ParaTabStops").getLength());
643 DECLARE_RTFEXPORT_TEST(testFontOverride, "font-override.rtf")
645 // This was "Times New Roman".
646 CPPUNIT_ASSERT_EQUAL(OUString("Arial"),
647 getProperty<OUString>(getRun(getParagraph(1), 1), "CharFontName"));
650 DECLARE_RTFEXPORT_TEST(testFdo73241, "fdo73241.rtf")
652 // This was 2, page break in table wasn't ignored.
653 CPPUNIT_ASSERT_EQUAL(1, getPages());
656 DECLARE_RTFEXPORT_TEST(testFdo80905, "fdo80905.rtf")
658 uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
659 uno::Reference<container::XEnumerationAccess> xFieldsAccess(
660 xTextFieldsSupplier->getTextFields());
661 uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
662 xFields->nextElement();
663 // The problem was that there was only one field in the document, but there should be true.
664 CPPUNIT_ASSERT_EQUAL(true, static_cast<bool>(xFields->hasMoreElements()));
667 DECLARE_RTFEXPORT_TEST(testFdo82106, "fdo82106.rtf")
669 // Tab was missing after footnote not containing a tab.
670 getParagraph(2, "before\tafter");
673 DECLARE_RTFEXPORT_TEST(testFdo74229, "fdo74229.rtf")
675 uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
676 uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(),
677 uno::UNO_QUERY);
678 uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
679 uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY);
680 // This was 0, due to ignoring RTF_TRGAPH.
681 CPPUNIT_ASSERT_EQUAL(sal_Int32(convertTwipToMm100(67)),
682 getProperty<sal_Int32>(xCell, "RightBorderDistance"));
685 DECLARE_RTFEXPORT_TEST(testFdo79959, "fdo79959.rtf")
687 // This was false, as the style was imported as " Test", i.e. no whitespace stripping.
688 CPPUNIT_ASSERT_EQUAL(true, static_cast<bool>(getStyles("ParagraphStyles")->hasByName("Test")));
691 DECLARE_RTFEXPORT_TEST(testFdo82078, "fdo82078.rtf")
693 // This was awt::FontWeight::BOLD, i.e. the second run was bold, when it should be normal.
694 CPPUNIT_ASSERT_EQUAL(awt::FontWeight::NORMAL,
695 getProperty<float>(getRun(getParagraph(1), 2), "CharWeight"));
698 DECLARE_RTFEXPORT_TEST(testCsBold, "cs-bold.rtf")
700 // This was awt::FontWeight::NORMAL, i.e. the first run was bold, when it should be bold (applied character style without direct formatting).
701 CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD,
702 getProperty<float>(getRun(getParagraph(1), 1), "CharWeight"));
705 DECLARE_RTFEXPORT_TEST(testFdo84679, "fdo84679.rtf")
707 // The problem was that the paragraph in A1 had some bottom margin, but it should not.
708 uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
709 uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(),
710 uno::UNO_QUERY);
711 uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
712 uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY);
713 // This was 282.
714 CPPUNIT_ASSERT_EQUAL(
715 static_cast<sal_Int32>(0),
716 getProperty<sal_Int32>(getParagraphOfText(1, xCell->getText()), "ParaBottomMargin"));
719 DECLARE_RTFEXPORT_TEST(testTdf123393, "tdf123393.rtf")
721 uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
722 uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(),
723 uno::UNO_QUERY);
724 uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
725 uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY);
726 // Without the accompanying fix in place, this test would have failed with
727 // 'Expected: 7; Actual : 10', i.e. font size was too large.
728 CPPUNIT_ASSERT_EQUAL(
729 7.f, getProperty<float>(getRun(getParagraphOfText(1, xCell->getText()), 1), "CharHeight"));
732 DECLARE_RTFEXPORT_TEST(testFdo83464, "fdo83464.rtf")
734 // Problem was that the text in the textframe had wrong font.
735 uno::Reference<text::XTextRange> xFrameText(getShape(1), uno::UNO_QUERY);
736 CPPUNIT_ASSERT_EQUAL(OUString("Hello"), xFrameText->getString());
737 // This was Times New Roman.
738 CPPUNIT_ASSERT_EQUAL(
739 OUString("Verdana"),
740 getProperty<OUString>(getRun(getParagraphOfText(1, xFrameText->getText()), 1),
741 "CharFontName"));
744 DECLARE_RTFEXPORT_TEST(testFdo86761, "fdo86761.rtf")
746 // This was 26, even if the picture should have no border, due to fLine=0.
747 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(0),
748 getProperty<table::BorderLine2>(getShape(1), "TopBorder").LineWidth);
751 DECLARE_RTFEXPORT_TEST(testFdo82859, "fdo82859.rtf")
753 // This was 0: "0xffffff" was converted to 0, i.e. the background was black instead of the default.
754 CPPUNIT_ASSERT_EQUAL(COL_AUTO, getProperty<Color>(getShape(1), "BackColor"));
757 DECLARE_RTFEXPORT_TEST(testFdo82076, "fdo82076.rtf")
759 // Footnote position was wrong: should be at the end of the B1 cell.
760 uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
761 uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(),
762 uno::UNO_QUERY);
763 uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
764 uno::Reference<text::XTextRange> xCell(xTable->getCellByName("B1"), uno::UNO_QUERY);
765 // This resulted in container::NoSuchElementException: the footnote was at the start of the A1 cell.
766 CPPUNIT_ASSERT_EQUAL(OUString("Footnote"),
767 getProperty<OUString>(getRun(getParagraphOfText(1, xCell->getText()), 2),
768 "TextPortionType"));
771 DECLARE_RTFEXPORT_TEST(testFdo83204, "fdo83204.rtf")
773 // This was Standard, \sN was ignored after \bkmkstart and \pard.
774 CPPUNIT_ASSERT_EQUAL(OUString("Heading 1"),
775 getProperty<OUString>(getParagraph(1), "ParaStyleName"));
778 CPPUNIT_PLUGIN_IMPLEMENT();
780 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */