android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / qa / extras / rtfexport / rtfexport7.cxx
blobad9249bedeb806e1a3535dee75fc1db3d893aca7
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/document/XDocumentPropertiesSupplier.hpp>
13 #include <com/sun/star/drawing/FillStyle.hpp>
14 #include <com/sun/star/drawing/PointSequenceSequence.hpp>
15 #include <com/sun/star/style/PageStyleLayout.hpp>
16 #include <com/sun/star/text/FontEmphasis.hpp>
17 #include <com/sun/star/text/TableColumnSeparator.hpp>
18 #include <com/sun/star/text/XPageCursor.hpp>
19 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
20 #include <com/sun/star/text/WritingMode2.hpp>
21 #include <com/sun/star/text/XTextColumns.hpp>
22 #include <com/sun/star/text/HoriOrientation.hpp>
23 #include <com/sun/star/text/XTextTable.hpp>
24 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
25 #include <com/sun/star/text/XTextTablesSupplier.hpp>
26 #include <com/sun/star/text/XBookmarksSupplier.hpp>
28 #include <comphelper/sequenceashashmap.hxx>
29 #include <tools/UnitConversion.hxx>
31 using namespace css;
33 class Test : public SwModelTestBase
35 public:
36 Test()
37 : SwModelTestBase("/sw/qa/extras/rtfexport/data/", "Rich Text Format")
42 DECLARE_RTFEXPORT_TEST(testPictureWrapPolygon, "picture-wrap-polygon.rtf")
44 // The problem was that the wrap polygon was ignored during import.
45 drawing::PointSequenceSequence aSeqSeq
46 = getProperty<drawing::PointSequenceSequence>(getShape(1), "ContourPolyPolygon");
47 // This was 0: the polygon list was empty.
48 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aSeqSeq.getLength());
50 drawing::PointSequence aSeq = aSeqSeq[0];
51 CPPUNIT_ASSERT_EQUAL(sal_Int32(11), aSeq.getLength());
53 // The shape also didn't have negative top / left coordinates.
54 CPPUNIT_ASSERT_EQUAL(sal_Int32(convertTwipToMm100(-1177)),
55 getProperty<sal_Int32>(getShape(1), "HoriOrientPosition"));
56 CPPUNIT_ASSERT_EQUAL(sal_Int32(convertTwipToMm100(-67)),
57 getProperty<sal_Int32>(getShape(1), "VertOrientPosition"));
60 DECLARE_RTFEXPORT_TEST(testTdf113408, "tdf113408.rtf")
62 // This was 0, left margin was not inherited from style properly.
63 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1270),
64 getProperty<sal_Int32>(getParagraph(1), "ParaLeftMargin"));
67 CPPUNIT_TEST_FIXTURE(Test, testAbi10039)
69 loadAndReload("abi10039.odt");
70 CPPUNIT_ASSERT_EQUAL(1, getShapes());
71 CPPUNIT_ASSERT_EQUAL(1, getPages());
72 // Make sure we don't just crash on export, and additionally the shape should not be inline (as it's at-page anchored originally).
73 CPPUNIT_ASSERT(text::TextContentAnchorType_AS_CHARACTER
74 != getProperty<text::TextContentAnchorType>(getShape(1), "AnchorType"));
77 CPPUNIT_TEST_FIXTURE(Test, testAbi10076)
79 loadAndReload("abi10076.odt");
80 CPPUNIT_ASSERT_EQUAL(2, getPages());
81 // Just make sure that we don't crash after exporting a fully calculated layout.
84 DECLARE_RTFEXPORT_TEST(testEm, "em.rtf")
86 // Test all possible \acc* control words.
87 CPPUNIT_ASSERT_EQUAL(text::FontEmphasis::NONE,
88 getProperty<sal_Int16>(getRun(getParagraph(1), 1), "CharEmphasis"));
89 CPPUNIT_ASSERT_EQUAL(text::FontEmphasis::DOT_ABOVE,
90 getProperty<sal_Int16>(getRun(getParagraph(1), 2), "CharEmphasis"));
91 CPPUNIT_ASSERT_EQUAL(text::FontEmphasis::ACCENT_ABOVE,
92 getProperty<sal_Int16>(getRun(getParagraph(1), 3), "CharEmphasis"));
93 // This was missing.
94 CPPUNIT_ASSERT_EQUAL(text::FontEmphasis::CIRCLE_ABOVE,
95 getProperty<sal_Int16>(getRun(getParagraph(1), 4), "CharEmphasis"));
96 // This one, too.
97 CPPUNIT_ASSERT_EQUAL(text::FontEmphasis::DOT_BELOW,
98 getProperty<sal_Int16>(getRun(getParagraph(1), 5), "CharEmphasis"));
101 DECLARE_RTFEXPORT_TEST(testNumberingFont, "numbering-font.rtf")
103 uno::Reference<beans::XPropertySet> xStyle(
104 getStyles("CharacterStyles")->getByName("ListLabel 1"), uno::UNO_QUERY);
105 // This was Liberation Serif, i.e. custom font of the numbering itself ("1.\t") was lost on import.
106 CPPUNIT_ASSERT_EQUAL(OUString("Impact"), getProperty<OUString>(xStyle, "CharFontName"));
107 CPPUNIT_ASSERT_EQUAL(72.f, getProperty<float>(xStyle, "CharHeight"));
110 CPPUNIT_TEST_FIXTURE(Test, testFdo82860)
112 loadAndReload("fdo82860.odt");
113 CPPUNIT_ASSERT_EQUAL(1, getShapes());
114 CPPUNIT_ASSERT_EQUAL(1, getPages());
115 // The problem was that:
116 // 1) The import tried to use fieldmarks for SHAPE fields
117 // 2) The exporter did not handle "shape with textbox" text.
118 uno::Reference<text::XTextRange> xTextRange(getShape(1), uno::UNO_QUERY);
119 uno::Reference<text::XText> xText = xTextRange->getText();
120 CPPUNIT_ASSERT_EQUAL(OUString("hello"), getParagraphOfText(1, xText)->getString());
123 CPPUNIT_TEST_FIXTURE(Test, testFdo82858)
125 loadAndReload("fdo82858.docx");
126 // This was table::BorderLineStyle::SOLID, exporter failed to write explicit no line when line color was written.
127 CPPUNIT_ASSERT_EQUAL(table::BorderLineStyle::NONE,
128 getProperty<table::BorderLine2>(getShape(1), "TopBorder").LineStyle);
131 DECLARE_RTFEXPORT_TEST(testTdf104936, "tdf104936.rtf")
133 uno::Reference<text::XTextRange> xShape1(getShape(1), uno::UNO_QUERY);
134 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), getProperty<sal_Int32>(xShape1, "ZOrder"));
135 // This failed, the shape without text covered the shape with text.
136 CPPUNIT_ASSERT(xShape1->getString().isEmpty());
137 uno::Reference<text::XTextRange> xShape2(getShape(2), uno::UNO_QUERY);
138 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), getProperty<sal_Int32>(xShape2, "ZOrder"));
139 CPPUNIT_ASSERT_EQUAL(OUString("Hello"), xShape2->getString());
142 DECLARE_RTFEXPORT_TEST(testTableRtl, "table-rtl.rtf")
144 uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
145 uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(),
146 uno::UNO_QUERY);
147 uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
148 // This was text::WritingMode2::LR_TB, i.e. direction of the table was ignored.
149 CPPUNIT_ASSERT_EQUAL(text::WritingMode2::RL_TB, getProperty<sal_Int16>(xTable, "WritingMode"));
152 DECLARE_RTFEXPORT_TEST(testNumOverrideStart, "num-override-start.rtf")
154 // The numbering on the second level was "3.1", not "1.3".
155 uno::Reference<container::XIndexAccess> xRules
156 = getProperty<uno::Reference<container::XIndexAccess>>(
157 getStyles("NumberingStyles")->getByName("WWNum1"), "NumberingRules");
158 CPPUNIT_ASSERT_EQUAL(
159 sal_Int16(1),
160 comphelper::SequenceAsHashMap(xRules->getByIndex(0))["StartWith"].get<sal_Int16>());
161 CPPUNIT_ASSERT_EQUAL(
162 sal_Int16(3),
163 comphelper::SequenceAsHashMap(xRules->getByIndex(1))["StartWith"].get<sal_Int16>());
166 DECLARE_RTFEXPORT_TEST(testFdo82006, "fdo82006.rtf")
168 // These were 176 (100 twips), as \sbauto and \sbbefore were ignored.
169 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(getParagraph(1), "ParaTopMargin"));
170 CPPUNIT_ASSERT_EQUAL(sal_Int32(convertTwipToMm100(280)),
171 getProperty<sal_Int32>(getParagraph(1), "ParaBottomMargin"));
172 CPPUNIT_ASSERT_EQUAL(sal_Int32(convertTwipToMm100(280)),
173 getProperty<sal_Int32>(getParagraph(2), "ParaTopMargin"));
174 CPPUNIT_ASSERT_EQUAL(sal_Int32(convertTwipToMm100(280)),
175 getProperty<sal_Int32>(getParagraph(2), "ParaBottomMargin"));
178 DECLARE_RTFEXPORT_TEST(testTdf104081, "tdf104081.rtf")
180 // These were 494 (280 twips), as \htmautsp was ignored.
181 CPPUNIT_ASSERT_EQUAL(sal_Int32(convertTwipToMm100(100)),
182 getProperty<sal_Int32>(getParagraph(1), "ParaTopMargin"));
183 CPPUNIT_ASSERT_EQUAL(sal_Int32(convertTwipToMm100(100)),
184 getProperty<sal_Int32>(getParagraph(1), "ParaBottomMargin"));
187 CPPUNIT_TEST_FIXTURE(Test, testTdf88583)
189 loadAndReload("tdf88583.odt");
190 CPPUNIT_ASSERT_EQUAL(1, getPages());
191 // This was FillStyle_NONE, as background color was missing from the color table during export.
192 CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_SOLID,
193 getProperty<drawing::FillStyle>(getParagraph(1), "FillStyle"));
194 CPPUNIT_ASSERT_EQUAL(Color(0x00cc00), getProperty<Color>(getParagraph(1), "FillColor"));
197 DECLARE_RTFEXPORT_TEST(testMargmirror, "margmirror.rtf")
199 // \margmirror was not handled, this was PageStyleLayout_ALL.
200 uno::Reference<beans::XPropertySet> xPageStyle(getStyles("PageStyles")->getByName("Standard"),
201 uno::UNO_QUERY);
202 CPPUNIT_ASSERT_EQUAL(style::PageStyleLayout_MIRRORED,
203 getProperty<style::PageStyleLayout>(xPageStyle, "PageStyleLayout"));
206 DECLARE_RTFEXPORT_TEST(testSautoupd, "sautoupd.rtf")
208 // \sautoupd was ignored during import and export.
209 uno::Reference<beans::XPropertySet> xHeading1(
210 getStyles("ParagraphStyles")->getByName("Heading 1"), uno::UNO_QUERY);
211 CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xHeading1, "IsAutoUpdate"));
212 uno::Reference<beans::XPropertySet> xHeading2(
213 getStyles("ParagraphStyles")->getByName("Heading 2"), uno::UNO_QUERY);
214 CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(xHeading2, "IsAutoUpdate"));
217 DECLARE_RTFEXPORT_TEST(testHyphauto, "hyphauto.rtf")
219 CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(getParagraph(1), "ParaIsHyphenation"));
222 DECLARE_RTFEXPORT_TEST(testHyphpar, "hyphpar.rtf")
224 // Hyphenation was enabled for all 3 paragraphs, but it should be disabled for the 2nd one.
225 CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(getParagraph(2), "ParaIsHyphenation"));
228 DECLARE_RTFEXPORT_TEST(testTdf108955, "tdf108955.rtf")
230 CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_SOLID,
231 getProperty<drawing::FillStyle>(getParagraph(1), "FillStyle"));
232 // This was 0xffffff, i.e. non-white background was overwritten from the paragraph style.
233 CPPUNIT_ASSERT_EQUAL(Color(0xffff99), getProperty<Color>(getParagraph(1), "FillColor"));
236 DECLARE_RTFEXPORT_TEST(testTdf80708, "tdf80708.rtf")
238 uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
239 uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(),
240 uno::UNO_QUERY);
241 uno::Reference<text::XTextTable> xTable(xTables->getByIndex(1), uno::UNO_QUERY);
242 uno::Reference<table::XTableRows> xTableRows = xTable->getRows();
243 // This was 2, i.e. the second table had 3 cols, now 2 as expected.
244 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1),
245 getProperty<uno::Sequence<text::TableColumnSeparator>>(
246 xTableRows->getByIndex(0), "TableColumnSeparators")
247 .getLength());
250 CPPUNIT_TEST_FIXTURE(Test, testHyperlinkWithoutURL)
252 createSwDoc("tdf90421.fodt");
253 // Change the hyperlink, so its URL is empty.
254 uno::Reference<beans::XPropertySet> xRun(getRun(getParagraph(1), 2), uno::UNO_QUERY);
255 xRun->setPropertyValue("HyperLinkURL", uno::Any(OUString()));
256 saveAndReload("Rich Text Format");
257 SvMemoryStream aMemoryStream;
258 SvFileStream aStream(maTempFile.GetURL(), StreamMode::READ);
259 aStream.ReadStream(aMemoryStream);
260 OString aData(static_cast<const char*>(aMemoryStream.GetData()), aMemoryStream.GetSize());
261 // This was some positive number, i.e. we exported a hyperlink with an empty URL.
262 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-1), aData.indexOf("HYPERLINK"));
265 CPPUNIT_TEST_FIXTURE(Test, testTdf92521)
267 loadAndReload("tdf92521.odt");
268 // There should be a page break that's in the middle of the document: right after the table.
269 // But there wasn't, so this was 1.
270 CPPUNIT_ASSERT_EQUAL(2, getPages());
273 DECLARE_RTFEXPORT_TEST(testTdf114309, "tdf114309.rtf")
275 // Without the fix in place, this test would have failed with
276 // - the property is of unexpected type or void: TextSection
277 auto xTextSection
278 = getProperty<uno::Reference<beans::XPropertySet>>(getParagraph(1), "TextSection");
279 auto xTextColumns
280 = getProperty<uno::Reference<text::XTextColumns>>(xTextSection, "TextColumns");
281 CPPUNIT_ASSERT_EQUAL(sal_Int16(2), xTextColumns->getColumnCount());
284 DECLARE_RTFEXPORT_TEST(testTdf94043, "tdf94043.rtf")
286 auto xTextSection
287 = getProperty<uno::Reference<beans::XPropertySet>>(getParagraph(2), "TextSection");
288 auto xTextColumns
289 = getProperty<uno::Reference<text::XTextColumns>>(xTextSection, "TextColumns");
290 // This was 0, the separator line was not visible due to 0 width.
291 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2),
292 getProperty<sal_Int32>(xTextColumns, "SeparatorLineWidth"));
294 CPPUNIT_ASSERT_EQUAL(7, getParagraphs());
297 DECLARE_RTFEXPORT_TEST(testTdf94377, "tdf94377.rtf")
299 uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
300 uno::Reference<container::XEnumerationAccess> xFieldsAccess(
301 xTextFieldsSupplier->getTextFields());
302 uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
303 uno::Reference<beans::XPropertySet> xPropertySet(xFields->nextElement(), uno::UNO_QUERY);
304 auto xText = getProperty<uno::Reference<text::XText>>(xPropertySet, "TextRange");
305 // This failed, as:
306 // 1) multiple paragraphs were not exported, so the text was "Asdf10asdf12".
307 // 2) direct formatting of runs were not exported, so this was 12 (the document default).
308 CPPUNIT_ASSERT_EQUAL(
309 10.f, getProperty<float>(getRun(getParagraphOfText(1, xText, "Asdf10"), 1), "CharHeight"));
310 CPPUNIT_ASSERT_EQUAL(
311 12.f, getProperty<float>(getRun(getParagraphOfText(2, xText, "asdf12"), 1), "CharHeight"));
314 DECLARE_RTFEXPORT_TEST(testTdf104079, "tdf104079.rtf")
316 bool bFound = false;
317 int nIndex = 0;
318 while (!bFound)
320 uno::Reference<text::XTextRange> xParagraph = getParagraph(++nIndex);
321 if (!xParagraph->getString().startsWith("toc3"))
322 continue;
324 bFound = true;
325 // This was 0, 3rd paragraph of ToC lost its bottom paragraph margin.
326 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(212),
327 getProperty<sal_Int32>(xParagraph, "ParaBottomMargin"));
331 DECLARE_RTFEXPORT_TEST(testPageBackground, "page-background.rtf")
333 // The problem was that \background was ignored.
334 uno::Reference<beans::XPropertySet> xPageStyle(getStyles("PageStyles")->getByName("Standard"),
335 uno::UNO_QUERY);
336 CPPUNIT_ASSERT_EQUAL(Color(0x92D050), getProperty<Color>(xPageStyle, "BackColor"));
339 DECLARE_RTFEXPORT_TEST(testTdf96175, "tdf96175.rtf")
341 // The problem that a user defined property named "Company" was lost on export.
342 uno::Reference<document::XDocumentPropertiesSupplier> xDocumentPropertiesSupplier(
343 mxComponent, uno::UNO_QUERY);
344 uno::Reference<document::XDocumentProperties> xDocumentProperties
345 = xDocumentPropertiesSupplier->getDocumentProperties();
346 uno::Reference<beans::XPropertyContainer> xUserDefinedProperties
347 = xDocumentProperties->getUserDefinedProperties();
348 // This resulted in a beans::UnknownPropertyException.
349 CPPUNIT_ASSERT_EQUAL(OUString("foobar"),
350 getProperty<OUString>(xUserDefinedProperties, "Company"));
353 DECLARE_RTFEXPORT_TEST(testRedline, "redline.rtf")
355 CPPUNIT_ASSERT_EQUAL(OUString("Rebecca Lopez"),
356 getProperty<OUString>(getRun(getParagraph(1), 2), "RedlineAuthor"));
357 CPPUNIT_ASSERT_EQUAL(OUString("Dorothy Jones"),
358 getProperty<OUString>(getRun(getParagraph(2), 2), "RedlineAuthor"));
361 DECLARE_RTFEXPORT_TEST(testCustomDocProps, "custom-doc-props.rtf")
363 // Custom document properties were not improved, this resulted in a beans::UnknownPropertyException.
364 uno::Reference<document::XDocumentPropertiesSupplier> xDocumentPropertiesSupplier(
365 mxComponent, uno::UNO_QUERY);
366 uno::Reference<document::XDocumentProperties> xDocumentProperties
367 = xDocumentPropertiesSupplier->getDocumentProperties();
368 uno::Reference<beans::XPropertyContainer> xUserDefinedProperties
369 = xDocumentProperties->getUserDefinedProperties();
370 CPPUNIT_ASSERT_EQUAL(
371 OUString("2016-03-08T10:55:18,531376147"),
372 getProperty<OUString>(xUserDefinedProperties,
373 "urn:bails:IntellectualProperty:Authorization:StartValidity"));
374 CPPUNIT_ASSERT_EQUAL(
375 OUString("None"),
376 getProperty<OUString>(xUserDefinedProperties,
377 "urn:bails:IntellectualProperty:Authorization:StopValidity"));
378 // Test roundtrip of numbers. This failed as getProperty() did not find "n".
379 CPPUNIT_ASSERT_EQUAL(42.0, getProperty<double>(xUserDefinedProperties, "n"));
380 // Test boolean "yes".
381 CPPUNIT_ASSERT(getProperty<bool>(xUserDefinedProperties, "by"));
382 // Test boolean "no".
383 CPPUNIT_ASSERT(!getProperty<bool>(xUserDefinedProperties, "bn"));
385 // Test roundtrip of date in general, and year/month/day in particular.
386 util::DateTime aDate = getProperty<util::DateTime>(xUserDefinedProperties, "d");
387 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(2016), aDate.Year);
388 CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(1), aDate.Month);
389 CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(30), aDate.Day);
391 // Test real number.
392 CPPUNIT_ASSERT_EQUAL(3.14, getProperty<double>(xUserDefinedProperties, "pi"));
395 DECLARE_RTFEXPORT_TEST(testTdf65642, "tdf65642.rtf")
397 uno::Reference<container::XNameAccess> xPageStyles = getStyles("PageStyles");
398 uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
399 uno::Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier(
400 xModel->getCurrentController(), uno::UNO_QUERY);
401 uno::Reference<text::XPageCursor> xCursor(xTextViewCursorSupplier->getViewCursor(),
402 uno::UNO_QUERY);
403 xCursor->jumpToLastPage();
404 OUString pageStyleName = getProperty<OUString>(xCursor, "PageStyleName");
405 // The second page's numbering type: this was style::NumberingType::ARABIC.
406 CPPUNIT_ASSERT_EQUAL(
407 style::NumberingType::CHARS_UPPER_LETTER_N,
408 getProperty<sal_Int16>(xPageStyles->getByName(pageStyleName), "NumberingType"));
409 // The second page's restart value: this was 0.
410 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1),
411 getProperty<sal_Int32>(getParagraph(2), "PageNumberOffset"));
414 DECLARE_RTFEXPORT_TEST(testPgnlcltr, "pgnlcltr.rtf")
416 uno::Reference<container::XNameAccess> xPageStyles = getStyles("PageStyles");
417 uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
418 uno::Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier(
419 xModel->getCurrentController(), uno::UNO_QUERY);
420 uno::Reference<text::XPageCursor> xCursor(xTextViewCursorSupplier->getViewCursor(),
421 uno::UNO_QUERY);
422 xCursor->jumpToLastPage();
423 OUString pageStyleName = getProperty<OUString>(xCursor, "PageStyleName");
424 // The second page's numbering type: this was style::NumberingType::ARABIC.
425 CPPUNIT_ASSERT_EQUAL(
426 style::NumberingType::CHARS_LOWER_LETTER_N,
427 getProperty<sal_Int16>(xPageStyles->getByName(pageStyleName), "NumberingType"));
430 DECLARE_RTFEXPORT_TEST(testPgnucrm, "pgnucrm.rtf")
432 uno::Reference<container::XNameAccess> xPageStyles = getStyles("PageStyles");
433 uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
434 uno::Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier(
435 xModel->getCurrentController(), uno::UNO_QUERY);
436 uno::Reference<text::XPageCursor> xCursor(xTextViewCursorSupplier->getViewCursor(),
437 uno::UNO_QUERY);
438 xCursor->jumpToLastPage();
439 OUString pageStyleName = getProperty<OUString>(xCursor, "PageStyleName");
440 // The second page's numbering type: this was style::NumberingType::ARABIC.
441 CPPUNIT_ASSERT_EQUAL(
442 style::NumberingType::ROMAN_UPPER,
443 getProperty<sal_Int16>(xPageStyles->getByName(pageStyleName), "NumberingType"));
446 DECLARE_RTFEXPORT_TEST(testPgnlcrm, "pgnlcrm.rtf")
448 uno::Reference<container::XNameAccess> xPageStyles = getStyles("PageStyles");
449 uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
450 uno::Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier(
451 xModel->getCurrentController(), uno::UNO_QUERY);
452 uno::Reference<text::XPageCursor> xCursor(xTextViewCursorSupplier->getViewCursor(),
453 uno::UNO_QUERY);
454 xCursor->jumpToLastPage();
455 OUString pageStyleName = getProperty<OUString>(xCursor, "PageStyleName");
456 // The second page's numbering type: this was style::NumberingType::ARABIC.
457 CPPUNIT_ASSERT_EQUAL(
458 style::NumberingType::ROMAN_LOWER,
459 getProperty<sal_Int16>(xPageStyles->getByName(pageStyleName), "NumberingType"));
462 DECLARE_RTFEXPORT_TEST(testPgndec, "pgndec.rtf")
464 uno::Reference<container::XNameAccess> xPageStyles = getStyles("PageStyles");
465 uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
466 uno::Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier(
467 xModel->getCurrentController(), uno::UNO_QUERY);
468 uno::Reference<text::XPageCursor> xCursor(xTextViewCursorSupplier->getViewCursor(),
469 uno::UNO_QUERY);
470 xCursor->jumpToLastPage();
471 OUString pageStyleName = getProperty<OUString>(xCursor, "PageStyleName");
472 // The second page's numbering type: this was style::NumberingType::ROMAN_LOWER.
473 CPPUNIT_ASSERT_EQUAL(
474 style::NumberingType::ARABIC,
475 getProperty<sal_Int16>(xPageStyles->getByName(pageStyleName), "NumberingType"));
477 // tdf#82111 ensure a paragraph exists before a section break.
478 // This was only two paragraphs, and both page number fields were in one para on page 2 ("11").
479 getParagraph(2, "1");
480 CPPUNIT_ASSERT_EQUAL(3, getParagraphs());
483 DECLARE_RTFEXPORT_TEST(testTdf98806, "tdf98806.rtf")
485 uno::Reference<text::XBookmarksSupplier> xBookmarksSupplier(mxComponent, uno::UNO_QUERY);
486 uno::Reference<text::XTextContent> xBookmark(
487 xBookmarksSupplier->getBookmarks()->getByName("bookmark"), uno::UNO_QUERY);
488 // This was empty, bookmark in table wasn't imported correctly.
489 CPPUNIT_ASSERT_EQUAL(OUString("BBB"), xBookmark->getAnchor()->getString());
492 DECLARE_RTFEXPORT_TEST(testTdf61901, "tdf61901.rtf")
494 // Test the file directly, as current RTF import gives the correct font name with and without the fix.
495 if (isExported())
497 SvStream* pStream = maTempFile.GetStream(StreamMode::READ);
498 OString sLine;
499 while (pStream->ReadLine(sLine))
501 sal_Int32 nIndex = sLine.indexOf("\\loch\\loch");
502 if (nIndex != -1)
504 // Make sure that \hich is always written after a \loch\loch.
505 OString sRemaining = sLine.copy(nIndex);
506 CPPUNIT_ASSERT(sRemaining.indexOf("\\hich") != -1);
512 DECLARE_RTFEXPORT_TEST(testTdf103925, "tdf103925.rtf")
514 // This was true, \animtext0 resulted in setting the blinking font effect.
515 CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(getRun(getParagraph(1), 1), "CharFlash"));
518 DECLARE_RTFEXPORT_TEST(testTdf104228, "tdf104228.rtf")
520 uno::Reference<text::XTextTable> xTable(getParagraphOrTable(2), uno::UNO_QUERY);
521 uno::Reference<text::XTextRange> xCell(xTable->getCellByName("C1"), uno::UNO_QUERY);
522 uno::Reference<text::XTextRange> xParagraph = getParagraphOfText(1, xCell->getText());
523 // This was 2103, implicit 0 as direct formatting was ignored on the
524 // paragraph (and the style had this larger value).
525 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0),
526 getProperty<sal_Int32>(xParagraph, "ParaLeftMargin"));
529 DECLARE_RTFEXPORT_TEST(testTdf104085, "tdf104085.rtf")
531 uno::Reference<text::XTextRange> xPara(getParagraph(1));
532 uno::Reference<beans::XPropertySet> properties(xPara, uno::UNO_QUERY);
533 uno::Reference<container::XIndexAccess> xLevels(properties->getPropertyValue("NumberingRules"),
534 uno::UNO_QUERY);
535 uno::Sequence<beans::PropertyValue> aProps;
536 xLevels->getByIndex(0) >>= aProps;
537 for (beans::PropertyValue const& prop : std::as_const(aProps))
539 if (prop.Name == "BulletChar")
540 return;
542 CPPUNIT_FAIL("no BulletChar property");
545 DECLARE_RTFEXPORT_TEST(testTdf113550, "tdf113550.rtf")
547 uno::Reference<text::XTextTable> xTable(getParagraphOrTable(1), uno::UNO_QUERY);
548 uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY);
549 uno::Reference<text::XTextRange> xParagraph = getParagraphOfText(1, xCell->getText());
550 // This was 2501, 0 as direct formatting was ignored on the paragraph (and
551 // the style had this larger value).
552 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0),
553 getProperty<sal_Int32>(xParagraph, "ParaLeftMargin"));
556 DECLARE_RTFEXPORT_TEST(testLeveljcCenter, "leveljc-center.rtf")
558 // Tests that \leveljc1 is mapped to Adjust=Center for a numbering rule.
559 uno::Reference<text::XTextRange> xPara(getParagraph(1));
560 uno::Reference<beans::XPropertySet> properties(xPara, uno::UNO_QUERY);
561 uno::Reference<container::XIndexAccess> xLevels(properties->getPropertyValue("NumberingRules"),
562 uno::UNO_QUERY);
563 uno::Sequence<beans::PropertyValue> aProps;
564 xLevels->getByIndex(0) >>= aProps;
565 for (beans::PropertyValue const& prop : std::as_const(aProps))
567 if (prop.Name == "Adjust")
569 sal_Int16 nValue = 0;
570 CPPUNIT_ASSERT(prop.Value >>= nValue);
571 CPPUNIT_ASSERT_EQUAL(text::HoriOrientation::CENTER, nValue);
572 return;
575 CPPUNIT_FAIL("no Adjust property");
578 DECLARE_RTFEXPORT_TEST(testHyperlinkTarget, "hyperlink-target.rtf")
580 // This was empty, hyperlink target was lost on import.
581 CPPUNIT_ASSERT_EQUAL(OUString("_blank"),
582 getProperty<OUString>(getRun(getParagraph(1), 1), "HyperLinkTarget"));
585 CPPUNIT_TEST_FIXTURE(Test, testTdf107620)
587 loadAndReload("tdf107620.docx");
588 // This failed, RTF export didn't write the \htmautsp compat flag, the
589 // original bugdoc resulting in 2 pages instead of 1.
590 uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY);
591 uno::Reference<beans::XPropertySet> xSettings(
592 xFactory->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY);
593 bool bAddParaTableSpacing = true;
594 xSettings->getPropertyValue("AddParaTableSpacing") >>= bAddParaTableSpacing;
595 CPPUNIT_ASSERT(!bAddParaTableSpacing);
598 DECLARE_RTFEXPORT_TEST(testTdf104937, "tdf104937.rtf")
600 uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
601 uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(),
602 uno::UNO_QUERY);
603 uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
604 uno::Reference<table::XTableRows> xTableRows = xTable->getRows();
605 auto aSeparators = getProperty<uno::Sequence<text::TableColumnSeparator>>(
606 xTableRows->getByIndex(1), "TableColumnSeparators");
607 // First table's second row had 9 cells (so 8 separators).
608 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(8), aSeparators.getLength());
609 // This was 3174, i.e. last cell was wider than expected, while others were
610 // narrower.
611 CPPUNIT_ASSERT_GREATER(static_cast<sal_Int16>(4500), aSeparators[7].Position);
614 DECLARE_RTFEXPORT_TEST(testTdf112507, "tdf112507.rtf")
616 uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
617 uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(),
618 uno::UNO_QUERY);
619 uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
620 uno::Reference<table::XTableRows> xTableRows = xTable->getRows();
621 auto aSeparators = getProperty<uno::Sequence<text::TableColumnSeparator>>(
622 xTableRows->getByIndex(1), "TableColumnSeparators");
623 // First table's second row had 3 cells (so 2 separators).
624 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), aSeparators.getLength());
625 // This was 3333, i.e. the B2 cell was too narrow and the text needed 2 lines.
626 CPPUNIT_ASSERT_GREATEREQUAL(5000, aSeparators[1].Position - aSeparators[0].Position);
629 DECLARE_RTFEXPORT_TEST(testTdf107480, "tdf107480.rtf")
631 // These were 176 (100 twips), as \htmautsp was parsed too late.
632 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(getParagraph(1), "ParaTopMargin"));
633 CPPUNIT_ASSERT_EQUAL(sal_Int32(convertTwipToMm100(280)),
634 getProperty<sal_Int32>(getParagraph(1), "ParaBottomMargin"));
635 CPPUNIT_ASSERT_EQUAL(sal_Int32(convertTwipToMm100(280)),
636 getProperty<sal_Int32>(getParagraph(2), "ParaTopMargin"));
637 CPPUNIT_ASSERT_EQUAL(sal_Int32(convertTwipToMm100(280)),
638 getProperty<sal_Int32>(getParagraph(2), "ParaBottomMargin"));
641 DECLARE_RTFEXPORT_TEST(testWatermark, "watermark.rtf")
643 uno::Reference<text::XTextRange> xShape(getShape(1), uno::UNO_QUERY);
644 CPPUNIT_ASSERT_EQUAL(OUString("WatermarkRTF"), xShape->getString());
646 uno::Reference<beans::XPropertySet> xPropertySet(xShape, uno::UNO_QUERY);
647 OUString aFont;
648 float nFontSize;
650 // Check transparency
651 CPPUNIT_ASSERT_EQUAL(sal_Int16(50), getProperty<sal_Int16>(xShape, "FillTransparence"));
653 // Check font family
654 CPPUNIT_ASSERT(xPropertySet->getPropertyValue("CharFontName") >>= aFont);
655 CPPUNIT_ASSERT_EQUAL(OUString("DejaVu Serif"), aFont);
657 // Check font size
658 CPPUNIT_ASSERT(xPropertySet->getPropertyValue("CharHeight") >>= nFontSize);
659 CPPUNIT_ASSERT_EQUAL(float(66), nFontSize);
662 DECLARE_RTFEXPORT_TEST(testTdf109790, "tdf109790.rtf")
664 uno::Reference<text::XTextTable> xTable(getParagraphOrTable(2), uno::UNO_QUERY);
665 uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY);
666 // Style information was reset, which caused character height to be 22.
667 CPPUNIT_ASSERT_EQUAL(
668 10.f, getProperty<float>(getRun(getParagraphOfText(1, xCell->getText()), 1), "CharHeight"));
671 DECLARE_RTFEXPORT_TEST(testTdf112211, "tdf112211.rtf")
673 // This was 0, \fi in a list level definition was not imported.
674 auto xRules = getProperty<uno::Reference<container::XIndexAccess>>(
675 getStyles("NumberingStyles")->getByName("WWNum1"), "NumberingRules");
676 comphelper::SequenceAsHashMap aRule(xRules->getByIndex(0));
677 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-635), aRule["FirstLineIndent"].get<sal_Int32>());
680 DECLARE_RTFEXPORT_TEST(testTdf113202, "tdf113202.rtf")
682 // This failed, contextual spacing in 4th paragraph was lost.
683 CPPUNIT_ASSERT(getProperty<bool>(getParagraph(4), "ParaContextMargin"));
686 DECLARE_RTFEXPORT_TEST(testTdf156030, "tdf156030.rtf")
688 uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
689 uno::Reference<container::XEnumerationAccess> xFieldsAccess(
690 xTextFieldsSupplier->getTextFields());
691 uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
693 // As usual, fields given by FieldsAccess are not in same order as in the document
694 std::vector<std::vector<OUString>> aExpectedValues = {
695 { "1 FORMULA 2", "true value 1", "false value 1" }, // #1, condition should be 1 = 2
696 { "", "", "" }, // #9, not enough field params
697 { "1 1 FORMULA 1 2 1 true value 8 fal", "se", "value 8" }, // #8, nonsense in field params
698 { "1 1 FORMULA 1 2 1 true value 7 false", "value", "7" }, // #7, another parse error
699 { "1 < 2", "true value 6", "false value 6" }, // #6
700 { "1 > 2", "true value 5", "false value 5" }, // #5
701 { "1 <> 2", "true value 4", "false value 4" }, // #4
702 { "1 != 2", "true value 3", "false value 3" }, // #3
703 { "1 FORMULA FORMULA 2", "true value 2", "false value 2" }, // #2, condition expected 1 == 2
705 uno::Reference<beans::XPropertySet> xPropertySet;
706 OUString sValue;
708 for (const auto& aValues : aExpectedValues)
710 xPropertySet.set(xFields->nextElement(), uno::UNO_QUERY_THROW);
711 CPPUNIT_ASSERT(xPropertySet.is());
712 CPPUNIT_ASSERT(xPropertySet->getPropertyValue("Condition") >>= sValue);
713 CPPUNIT_ASSERT_EQUAL(aValues[0], sValue);
714 CPPUNIT_ASSERT(xPropertySet->getPropertyValue("TrueContent") >>= sValue);
715 CPPUNIT_ASSERT_EQUAL(aValues[1], sValue);
716 CPPUNIT_ASSERT(xPropertySet->getPropertyValue("FalseContent") >>= sValue);
717 CPPUNIT_ASSERT_EQUAL(aValues[2], sValue);
720 // No more fields
721 CPPUNIT_ASSERT(!xFields->hasMoreElements());
724 DECLARE_RTFEXPORT_TEST(testTdf153195, "tdf153195.rtf")
726 uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
727 uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(),
728 uno::UNO_QUERY);
730 // Table margin test (cannot be set to exact value, it jumps between -1991 and -1983)
731 CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(-2182),
732 getProperty<sal_Int32>(xTables->getByIndex(0), "LeftMargin"), 10);
733 CPPUNIT_ASSERT_DOUBLES_EQUAL(sal_Int32(-2182),
734 getProperty<sal_Int32>(xTables->getByIndex(1), "LeftMargin"), 10);
737 CPPUNIT_PLUGIN_IMPLEMENT();
739 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */