sw/qa/extras/rtfexport/rtfexport3.cxx | 694 +++++++++++++++++++++------------- 1 file changed, 448 insertions(+), 246 deletions(-)
New commits: commit c53b3f08776cfc64f40b4508c44bbd8424769822 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Apr 17 08:32:48 2024 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Apr 17 12:18:19 2024 +0200 CppunitTest_sw_rtfexport3: avoid DECLARE_RTFEXPORT_TEST No need to go via Writer-specific macros here. Change-Id: I5cc93ca6ee7bfc2f14d90edfe837a14c182bc73c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166169 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/sw/qa/extras/rtfexport/rtfexport3.cxx b/sw/qa/extras/rtfexport/rtfexport3.cxx index 25dfdab95973..ac894d05212b 100644 --- a/sw/qa/extras/rtfexport/rtfexport3.cxx +++ b/sw/qa/extras/rtfexport/rtfexport3.cxx @@ -47,160 +47,244 @@ public: } }; -DECLARE_RTFEXPORT_TEST(testTdf100961_fixedDateTime, "tdf100961_fixedDateTime.rtf") +CPPUNIT_TEST_FIXTURE(Test, testTdf100961_fixedDateTime) { - // This should be a fixed date/time field, not the current time. - getParagraph(1, "05.01.19 04:06:08"); + auto verify = [this]() { + // This should be a fixed date/time field, not the current time. + getParagraph(1, "05.01.19 04:06:08"); - uno::Reference<text::XTextFieldsSupplier> xTFS(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XEnumeration> xFields(xTFS->getTextFields()->createEnumeration()); - CPPUNIT_ASSERT_MESSAGE("constant time", getProperty<bool>(xFields->nextElement(), "IsFixed")); + uno::Reference<text::XTextFieldsSupplier> xTFS(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xFields(xTFS->getTextFields()->createEnumeration()); + CPPUNIT_ASSERT_MESSAGE("constant time", + getProperty<bool>(xFields->nextElement(), "IsFixed")); + }; + createSwDoc("tdf100961_fixedDateTime.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testTdf108949, "tdf108949_footnoteCharFormat.odt") +CPPUNIT_TEST_FIXTURE(Test, testTdf108949) { - CPPUNIT_ASSERT_EQUAL(1, getPages()); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Paragraph Numbering style", OUString(), - getProperty<OUString>(getParagraph(2), "NumberingStyleName")); - - uno::Reference<text::XFootnotesSupplier> xFootnotesSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XIndexAccess> xFootnotes = xFootnotesSupplier->getFootnotes(); - - uno::Reference<text::XText> xFootnoteText; - xFootnotes->getByIndex(0) >>= xFootnoteText; - // This was green (0x00A800), the character property of the footnote character, not the footnote text - CPPUNIT_ASSERT_EQUAL_MESSAGE( - "Footnote Text color", COL_AUTO, - getProperty<Color>(getRun(getParagraphOfText(1, xFootnoteText), 1), "CharColor")); + auto verify = [this]() { + CPPUNIT_ASSERT_EQUAL(1, getPages()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Paragraph Numbering style", OUString(), + getProperty<OUString>(getParagraph(2), "NumberingStyleName")); + + uno::Reference<text::XFootnotesSupplier> xFootnotesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xFootnotes = xFootnotesSupplier->getFootnotes(); + + uno::Reference<text::XText> xFootnoteText; + xFootnotes->getByIndex(0) >>= xFootnoteText; + // This was green (0x00A800), the character property of the footnote character, not the footnote text + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Footnote Text color", COL_AUTO, + getProperty<Color>(getRun(getParagraphOfText(1, xFootnoteText), 1), "CharColor")); + }; + createSwDoc("tdf108949_footnoteCharFormat.odt"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testTdf141964_numId0, "tdf141964_numId0.rtf") +CPPUNIT_TEST_FIXTURE(Test, testTdf141964_numId0) { - // Unit test added where numId is zero - which is only possible in RTF. - uno::Reference<beans::XPropertySet> xPara(getParagraph(3, "Geschichte"), uno::UNO_QUERY); - // Pre-emptive test: ensure that paragraph 3 remains numbered and numId0 doesn't mean no numbering. - CPPUNIT_ASSERT(!getProperty<OUString>(xPara, "NumberingStyleName").isEmpty()); + auto verify = [this]() { + // Unit test added where numId is zero - which is only possible in RTF. + uno::Reference<beans::XPropertySet> xPara(getParagraph(3, "Geschichte"), uno::UNO_QUERY); + // Pre-emptive test: ensure that paragraph 3 remains numbered and numId0 doesn't mean no numbering. + CPPUNIT_ASSERT(!getProperty<OUString>(xPara, "NumberingStyleName").isEmpty()); + }; + createSwDoc("tdf141964_numId0.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testTdf108949_footnote, "tdf108949_footnote.rtf") +CPPUNIT_TEST_FIXTURE(Test, testTdf108949_footnote) { - CPPUNIT_ASSERT_EQUAL_MESSAGE("Paragraph Numbering style", OUString(), - getProperty<OUString>(getParagraph(2), "NumberingStyleName")); + auto verify = [this]() { + CPPUNIT_ASSERT_EQUAL_MESSAGE("Paragraph Numbering style", OUString(), + getProperty<OUString>(getParagraph(2), "NumberingStyleName")); - uno::Reference<text::XFootnotesSupplier> xFootnotesSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XIndexAccess> xFootnotes = xFootnotesSupplier->getFootnotes(); + uno::Reference<text::XFootnotesSupplier> xFootnotesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xFootnotes = xFootnotesSupplier->getFootnotes(); - uno::Reference<text::XFootnote> xFootnote; - xFootnotes->getByIndex(0) >>= xFootnote; - // The color of the footnote anchor was black (0x000000) - CPPUNIT_ASSERT_EQUAL_MESSAGE("Footnote Character color", COL_LIGHTRED, - getProperty<Color>(xFootnote->getAnchor(), "CharColor")); + uno::Reference<text::XFootnote> xFootnote; + xFootnotes->getByIndex(0) >>= xFootnote; + // The color of the footnote anchor was black (0x000000) + CPPUNIT_ASSERT_EQUAL_MESSAGE("Footnote Character color", COL_LIGHTRED, + getProperty<Color>(xFootnote->getAnchor(), "CharColor")); + }; + createSwDoc("tdf108949_footnote.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testTdf130817, "tdf130817.rtf") +CPPUNIT_TEST_FIXTURE(Test, testTdf130817) { - uno::Reference<text::XEndnotesSupplier> xEndnotesSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XIndexAccess> xEndnotes = xEndnotesSupplier->getEndnotes(); - - uno::Reference<text::XFootnote> xEndnote1; - xEndnotes->getByIndex(0) >>= xEndnote1; - uno::Reference<text::XText> xEndnoteText1; - xEndnotes->getByIndex(0) >>= xEndnoteText1; - CPPUNIT_ASSERT_EQUAL(OUString("Titolo 1"), xEndnoteText1->getString().trim()); - CPPUNIT_ASSERT_EQUAL(OUString("$"), xEndnote1->getAnchor()->getString()); - - uno::Reference<text::XFootnote> xEndnote2; - xEndnotes->getByIndex(1) >>= xEndnote2; - uno::Reference<text::XText> xEndnoteText2; - xEndnotes->getByIndex(1) >>= xEndnoteText2; - CPPUNIT_ASSERT_EQUAL(OUString("Titolo 2"), xEndnoteText2->getString().trim()); - CPPUNIT_ASSERT_EQUAL(OUString("$"), xEndnote1->getAnchor()->getString()); + auto verify = [this]() { + uno::Reference<text::XEndnotesSupplier> xEndnotesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xEndnotes = xEndnotesSupplier->getEndnotes(); + + uno::Reference<text::XFootnote> xEndnote1; + xEndnotes->getByIndex(0) >>= xEndnote1; + uno::Reference<text::XText> xEndnoteText1; + xEndnotes->getByIndex(0) >>= xEndnoteText1; + CPPUNIT_ASSERT_EQUAL(OUString("Titolo 1"), xEndnoteText1->getString().trim()); + CPPUNIT_ASSERT_EQUAL(OUString("$"), xEndnote1->getAnchor()->getString()); + + uno::Reference<text::XFootnote> xEndnote2; + xEndnotes->getByIndex(1) >>= xEndnote2; + uno::Reference<text::XText> xEndnoteText2; + xEndnotes->getByIndex(1) >>= xEndnoteText2; + CPPUNIT_ASSERT_EQUAL(OUString("Titolo 2"), xEndnoteText2->getString().trim()); + CPPUNIT_ASSERT_EQUAL(OUString("$"), xEndnote1->getAnchor()->getString()); + }; + createSwDoc("tdf130817.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testTdf154129_transparentFrame, "tdf154129_transparentFrame.rtf") +CPPUNIT_TEST_FIXTURE(Test, testTdf154129_transparentFrame) { - // Without the fix, this was zero, and the text frame with "Visible" just looks white. - CPPUNIT_ASSERT_EQUAL(sal_Int16(100), getProperty<sal_Int16>(getShape(1), "FillTransparence")); + auto verify = [this]() { + // Without the fix, this was zero, and the text frame with "Visible" just looks white. + CPPUNIT_ASSERT_EQUAL(sal_Int16(100), + getProperty<sal_Int16>(getShape(1), "FillTransparence")); + }; + createSwDoc("tdf154129_transparentFrame.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testTdf137683_charHighlightNone, "tdf137683_charHighlightNone.rtf") +CPPUNIT_TEST_FIXTURE(Test, testTdf137683_charHighlightNone) { - uno::Reference<beans::XPropertySet> xRun(getRun(getParagraph(1), 1), uno::UNO_QUERY_THROW); - // This test was failing with a brown charHighlight of 8421376 (0x808000), instead of COL_TRANSPARENT (0xFFFFFFFF) - CPPUNIT_ASSERT_EQUAL(COL_AUTO, getProperty<Color>(xRun, "CharHighlight")); + auto verify = [this]() { + uno::Reference<beans::XPropertySet> xRun(getRun(getParagraph(1), 1), uno::UNO_QUERY_THROW); + // This test was failing with a brown charHighlight of 8421376 (0x808000), instead of COL_TRANSPARENT (0xFFFFFFFF) + CPPUNIT_ASSERT_EQUAL(COL_AUTO, getProperty<Color>(xRun, "CharHighlight")); + }; + createSwDoc("tdf137683_charHighlightNone.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testTdf116436_tableBackground, "tdf116436_tableBackground.odt") +CPPUNIT_TEST_FIXTURE(Test, testTdf116436_tableBackground) { - CPPUNIT_ASSERT_EQUAL(1, getPages()); - uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), - uno::UNO_QUERY); - uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY); - uno::Reference<table::XCell> xCell = xTable->getCellByName("A1"); - if (isExported()) - CPPUNIT_ASSERT_EQUAL(Color(0xF8DF7C), getProperty<Color>(xCell, "BackColor")); - xCell.set(xTable->getCellByName("A6")); - CPPUNIT_ASSERT_EQUAL(Color(0x81D41A), getProperty<Color>(xCell, "BackColor")); - xCell.set(xTable->getCellByName("B6")); - if (isExported()) - CPPUNIT_ASSERT_EQUAL(Color(0xFFFBCC), getProperty<Color>(xCell, "BackColor")); + auto verify = [this]() { + CPPUNIT_ASSERT_EQUAL(1, getPages()); + uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), + uno::UNO_QUERY); + uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY); + uno::Reference<table::XCell> xCell = xTable->getCellByName("A1"); + if (isExported()) + CPPUNIT_ASSERT_EQUAL(Color(0xF8DF7C), getProperty<Color>(xCell, "BackColor")); + xCell.set(xTable->getCellByName("A6")); + CPPUNIT_ASSERT_EQUAL(Color(0x81D41A), getProperty<Color>(xCell, "BackColor")); + xCell.set(xTable->getCellByName("B6")); + if (isExported()) + CPPUNIT_ASSERT_EQUAL(Color(0xFFFBCC), getProperty<Color>(xCell, "BackColor")); + }; + createSwDoc("tdf116436_tableBackground.odt"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testTdf122589_firstSection, "tdf122589_firstSection.odt") +CPPUNIT_TEST_FIXTURE(Test, testTdf122589_firstSection) { - CPPUNIT_ASSERT_EQUAL(1, getPages()); - uno::Reference<beans::XPropertySet> xPageStyle(getStyles("PageStyles")->getByName("Standard"), - uno::UNO_QUERY); - uno::Reference<text::XTextRange> xHeaderText - = getProperty<uno::Reference<text::XTextRange>>(xPageStyle, "HeaderText"); - CPPUNIT_ASSERT_EQUAL(OUString("My header"), xHeaderText->getString()); + auto verify = [this]() { + CPPUNIT_ASSERT_EQUAL(1, getPages()); + uno::Reference<beans::XPropertySet> xPageStyle( + getStyles("PageStyles")->getByName("Standard"), uno::UNO_QUERY); + uno::Reference<text::XTextRange> xHeaderText + = getProperty<uno::Reference<text::XTextRange>>(xPageStyle, "HeaderText"); + CPPUNIT_ASSERT_EQUAL(OUString("My header"), xHeaderText->getString()); - CPPUNIT_ASSERT_EQUAL_MESSAGE("# of paragraphs", 2, getParagraphs()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("# of paragraphs", 2, getParagraphs()); + }; + createSwDoc("tdf122589_firstSection.odt"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testTdf104035, "tdf104035.rtf") +CPPUNIT_TEST_FIXTURE(Test, testTdf104035) { - auto aTabStops = getProperty<uno::Sequence<style::TabStop>>(getParagraph(1), "ParaTabStops"); - CPPUNIT_ASSERT(aTabStops.hasElements()); - // This was 3330 twips instead, as tabs were assumed to be relative. - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(convertTwipToMm100(450)), aTabStops[0].Position); + auto verify = [this]() { + auto aTabStops + = getProperty<uno::Sequence<style::TabStop>>(getParagraph(1), "ParaTabStops"); + CPPUNIT_ASSERT(aTabStops.hasElements()); + // This was 3330 twips instead, as tabs were assumed to be relative. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(convertTwipToMm100(450)), + aTabStops[0].Position); + }; + createSwDoc("tdf104035.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testGraphicObjectFliph, "graphic-object-fliph.rtf") +CPPUNIT_TEST_FIXTURE(Test, testGraphicObjectFliph) { - CPPUNIT_ASSERT(getProperty<bool>(getShape(1), "HoriMirroredOnEvenPages")); - CPPUNIT_ASSERT(getProperty<bool>(getShape(1), "HoriMirroredOnOddPages")); + auto verify = [this]() { + CPPUNIT_ASSERT(getProperty<bool>(getShape(1), "HoriMirroredOnEvenPages")); + CPPUNIT_ASSERT(getProperty<bool>(getShape(1), "HoriMirroredOnOddPages")); + }; + createSwDoc("graphic-object-fliph.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testTdf114333, "tdf114333.rtf") +CPPUNIT_TEST_FIXTURE(Test, testTdf114333) { - uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), - uno::UNO_QUERY); - uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY); - // Check the distance from left - CPPUNIT_ASSERT_EQUAL(sal_Int32(8502), getProperty<sal_Int32>(xTable, "LeftMargin")); - // This was 17000 = 8502 + 8498 on import, 15240 on export and following import - CPPUNIT_ASSERT_EQUAL(sal_Int32(8498), getProperty<sal_Int32>(xTable, "Width")); + auto verify = [this]() { + uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), + uno::UNO_QUERY); + uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY); + // Check the distance from left + CPPUNIT_ASSERT_EQUAL(sal_Int32(8502), getProperty<sal_Int32>(xTable, "LeftMargin")); + // This was 17000 = 8502 + 8498 on import, 15240 on export and following import + CPPUNIT_ASSERT_EQUAL(sal_Int32(8498), getProperty<sal_Int32>(xTable, "Width")); + }; + createSwDoc("tdf114333.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testTdf115180, "tdf115180.docx") +CPPUNIT_TEST_FIXTURE(Test, testTdf115180) { - // On export to RTF, column separator positions were written without taking base width - // into account and then arrived huge, ~64000, which resulted in wrong table and cell widths - - sal_Int32 rowWidth - = parseDump("/root/page/body/tab/row/infos/bounds"_ostr, "width"_ostr).toInt32(); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Row width", sal_Int32(9360), rowWidth); - sal_Int32 cell1Width - = parseDump("/root/page/body/tab/row/cell[1]/infos/bounds"_ostr, "width"_ostr).toInt32(); - CPPUNIT_ASSERT_MESSAGE("First cell width", cell1Width >= 9140); - CPPUNIT_ASSERT_MESSAGE("First cell width", cell1Width <= 9142); - sal_Int32 cell2Width - = parseDump("/root/page/body/tab/row/cell[2]/infos/bounds"_ostr, "width"_ostr).toInt32(); - CPPUNIT_ASSERT_MESSAGE("Second cell width", cell2Width >= 218); - CPPUNIT_ASSERT_MESSAGE("Second cell width", cell2Width <= 220); + auto verify = [this]() { + // On export to RTF, column separator positions were written without taking base width + // into account and then arrived huge, ~64000, which resulted in wrong table and cell widths + + sal_Int32 rowWidth + = parseDump("/root/page/body/tab/row/infos/bounds"_ostr, "width"_ostr).toInt32(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Row width", sal_Int32(9360), rowWidth); + sal_Int32 cell1Width + = parseDump("/root/page/body/tab/row/cell[1]/infos/bounds"_ostr, "width"_ostr) + .toInt32(); + CPPUNIT_ASSERT_MESSAGE("First cell width", cell1Width >= 9140); + CPPUNIT_ASSERT_MESSAGE("First cell width", cell1Width <= 9142); + sal_Int32 cell2Width + = parseDump("/root/page/body/tab/row/cell[2]/infos/bounds"_ostr, "width"_ostr) + .toInt32(); + CPPUNIT_ASSERT_MESSAGE("Second cell width", cell2Width >= 218); + CPPUNIT_ASSERT_MESSAGE("Second cell width", cell2Width <= 220); + }; + createSwDoc("tdf115180.docx"); + verify(); + saveAndReload(mpFilter); + verify(); } DECLARE_ODFEXPORT_TEST(testArabicZeroNumbering, "arabic-zero-numbering.rtf") @@ -216,48 +300,62 @@ DECLARE_ODFEXPORT_TEST(testArabicZeroNumbering, "arabic-zero-numbering.rtf") aMap["NumberingType"].get<sal_uInt16>()); } -DECLARE_RTFEXPORT_TEST(testTdf116841, "tdf116841.rtf") +CPPUNIT_TEST_FIXTURE(Test, testTdf116841) { - // This was 0, left margin was ignored as we assumed the default is already - // fine for us. - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1270), - getProperty<sal_Int32>(getParagraph(1), "ParaLeftMargin")); + auto verify = [this]() { + // This was 0, left margin was ignored as we assumed the default is already + // fine for us. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1270), + getProperty<sal_Int32>(getParagraph(1), "ParaLeftMargin")); + }; + createSwDoc("tdf116841.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testTdf117268, "tdf117268.rtf") +CPPUNIT_TEST_FIXTURE(Test, testTdf117268) { - // Here we check that we correctly mimic Word's treatment of erroneous \itap0 inside tables. - // Previously, the first table was import as text, and second top-level one only imported - // last row with nested table (first row was also imported as text). - uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY_THROW); - uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), - uno::UNO_QUERY_THROW); - - // First (simple) table - uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY_THROW); - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount()); - uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY_THROW); - CPPUNIT_ASSERT_EQUAL(OUString("Text 1"), xCell->getString()); - - // Nested table - xTable.set(xTables->getByIndex(1), uno::UNO_QUERY_THROW); - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount()); - xCell.set(xTable->getCellByName("A1"), uno::UNO_QUERY_THROW); - CPPUNIT_ASSERT_EQUAL(OUString("Text 3"), xCell->getString()); - uno::Reference<beans::XPropertySet> xNestedAnchor(xTable->getAnchor(), uno::UNO_QUERY_THROW); - uno::Reference<text::XTextRange> xAnchorCell(xNestedAnchor->getPropertyValue("Cell"), - uno::UNO_QUERY_THROW); - - // Outer table - xTable.set(xTables->getByIndex(2), uno::UNO_QUERY_THROW); - CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getRows()->getCount()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount()); - xCell.set(xTable->getCellByName("A1"), uno::UNO_QUERY_THROW); - CPPUNIT_ASSERT_EQUAL(OUString("Text 2"), xCell->getString()); - xCell.set(xTable->getCellByName("A2"), uno::UNO_QUERY_THROW); - CPPUNIT_ASSERT_EQUAL(xCell, xAnchorCell); + auto verify = [this]() { + // Here we check that we correctly mimic Word's treatment of erroneous \itap0 inside tables. + // Previously, the first table was import as text, and second top-level one only imported + // last row with nested table (first row was also imported as text). + uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, + uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), + uno::UNO_QUERY_THROW); + + // First (simple) table + uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount()); + uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_EQUAL(OUString("Text 1"), xCell->getString()); + + // Nested table + xTable.set(xTables->getByIndex(1), uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount()); + xCell.set(xTable->getCellByName("A1"), uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_EQUAL(OUString("Text 3"), xCell->getString()); + uno::Reference<beans::XPropertySet> xNestedAnchor(xTable->getAnchor(), + uno::UNO_QUERY_THROW); + uno::Reference<text::XTextRange> xAnchorCell(xNestedAnchor->getPropertyValue("Cell"), + uno::UNO_QUERY_THROW); + + // Outer table + xTable.set(xTables->getByIndex(2), uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getRows()->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumns()->getCount()); + xCell.set(xTable->getCellByName("A1"), uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_EQUAL(OUString("Text 2"), xCell->getString()); + xCell.set(xTable->getCellByName("A2"), uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_EQUAL(xCell, xAnchorCell); + }; + createSwDoc("tdf117268.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } CPPUNIT_TEST_FIXTURE(Test, testTdf117505) @@ -288,10 +386,10 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf117505) } } -DECLARE_RTFEXPORT_TEST(testTdf112520, "tdf112520.docx") +CPPUNIT_TEST_FIXTURE(Test, testTdf112520) { - if (!isExported()) - return; + createSwDoc("tdf112520.docx"); + saveAndReload(mpFilter); // Assert that the white shape is on top of the yellow one. CPPUNIT_ASSERT_EQUAL(COL_YELLOW, getProperty<Color>(getShape(2), "FillColor")); @@ -351,106 +449,185 @@ CPPUNIT_TEST_FIXTURE(Test, testNestedHyperlink) getProperty<OUString>(xFootnotePortion, "HyperLinkURL")); } -DECLARE_RTFEXPORT_TEST(testTdf121623, "tdf121623.rtf") +CPPUNIT_TEST_FIXTURE(Test, testTdf121623) { - // This was 2, multicolumn section was ignored at the table. - CPPUNIT_ASSERT_EQUAL(1, getPages()); + auto verify = [this]() { + // This was 2, multicolumn section was ignored at the table. + CPPUNIT_ASSERT_EQUAL(1, getPages()); + }; + createSwDoc("tdf121623.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testTdf66543, "tdf66543.rtf") +CPPUNIT_TEST_FIXTURE(Test, testTdf66543) { - // Without the accompanying fix in place, this test would have failed with - // 'Expected: 2; Actual : 3' after import (off-by-one), then with - // 'Expected: 2; Actual : 0' (export not implemented). - CPPUNIT_ASSERT_EQUAL(sal_Int32(2), - getProperty<sal_Int32>(getParagraph(1), "ParaLineNumberStartValue")); + auto verify = [this]() { + // Without the accompanying fix in place, this test would have failed with + // 'Expected: 2; Actual : 3' after import (off-by-one), then with + // 'Expected: 2; Actual : 0' (export not implemented). + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), + getProperty<sal_Int32>(getParagraph(1), "ParaLineNumberStartValue")); + }; + createSwDoc("tdf66543.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testUlw, "ulw.rtf") +CPPUNIT_TEST_FIXTURE(Test, testUlw) { - // Test underlying in individual words mode. - CPPUNIT_ASSERT(getProperty<bool>(getRun(getParagraph(1), 1), "CharWordMode")); + auto verify = [this]() { + // Test underlying in individual words mode. + CPPUNIT_ASSERT(getProperty<bool>(getRun(getParagraph(1), 1), "CharWordMode")); + }; + createSwDoc("ulw.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testTdf122455, "tdf122455.rtf") +CPPUNIT_TEST_FIXTURE(Test, testTdf122455) { - // Without the accompanying fix in place, this test would have failed with - // 'Expected: 16; Actual : 32', the font size from a list definition - // leaked into the first run's character properties. - CPPUNIT_ASSERT_EQUAL(16.0, getProperty<double>(getRun(getParagraph(1), 1), "CharHeight")); + auto verify = [this]() { + // Without the accompanying fix in place, this test would have failed with + // 'Expected: 16; Actual : 32', the font size from a list definition + // leaked into the first run's character properties. + CPPUNIT_ASSERT_EQUAL(16.0, getProperty<double>(getRun(getParagraph(1), 1), "CharHeight")); + }; + createSwDoc("tdf122455.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testTdf125719_case_1, "tdf125719_case_1.rtf") +CPPUNIT_TEST_FIXTURE(Test, testTdf125719_case_1) { - CPPUNIT_ASSERT_EQUAL(awt::FontWeight::NORMAL, - getProperty<float>(getRun(getParagraph(1), 1), "CharWeight")); - CPPUNIT_ASSERT_EQUAL(awt::FontWeight::NORMAL, - getProperty<float>(getRun(getParagraph(3), 1), "CharWeight")); + auto verify = [this]() { + CPPUNIT_ASSERT_EQUAL(awt::FontWeight::NORMAL, + getProperty<float>(getRun(getParagraph(1), 1), "CharWeight")); + CPPUNIT_ASSERT_EQUAL(awt::FontWeight::NORMAL, + getProperty<float>(getRun(getParagraph(3), 1), "CharWeight")); + }; + createSwDoc("tdf125719_case_1.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testTdf125719_case_2, "tdf125719_case_2.rtf") +CPPUNIT_TEST_FIXTURE(Test, testTdf125719_case_2) { - CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD, - getProperty<float>(getRun(getParagraph(1), 1), "CharWeight")); - CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD, - getProperty<float>(getRun(getParagraph(3), 1), "CharWeight")); - CPPUNIT_ASSERT_EQUAL(awt::FontWeight::NORMAL, - getProperty<float>(getRun(getParagraph(5), 1), "CharWeight")); + auto verify = [this]() { + CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD, + getProperty<float>(getRun(getParagraph(1), 1), "CharWeight")); + CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD, + getProperty<float>(getRun(getParagraph(3), 1), "CharWeight")); + CPPUNIT_ASSERT_EQUAL(awt::FontWeight::NORMAL, + getProperty<float>(getRun(getParagraph(5), 1), "CharWeight")); + }; + createSwDoc("tdf125719_case_2.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testTabs, "tabs.rtf") +CPPUNIT_TEST_FIXTURE(Test, testTabs) { - // Test tab alignment in decimal mode. - auto aTabStops = getProperty<uno::Sequence<style::TabStop>>(getParagraph(1), "ParaTabStops"); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), aTabStops.getLength()); - const style::TabStop& rTabStop = aTabStops[0]; - CPPUNIT_ASSERT_EQUAL(style::TabAlign_DECIMAL, rTabStop.Alignment); + auto verify = [this]() { + // Test tab alignment in decimal mode. + auto aTabStops + = getProperty<uno::Sequence<style::TabStop>>(getParagraph(1), "ParaTabStops"); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), aTabStops.getLength()); + const style::TabStop& rTabStop = aTabStops[0]; + CPPUNIT_ASSERT_EQUAL(style::TabAlign_DECIMAL, rTabStop.Alignment); + }; + createSwDoc("tabs.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testTdf123703, "tdf123703.rtf") +CPPUNIT_TEST_FIXTURE(Test, testTdf123703) { + auto verify = [this]() { #if !defined(MACOSX) - // This was 1, because of normal space character width in consecutive spaces - CPPUNIT_ASSERT_EQUAL(2, getPages()); + // This was 1, because of normal space character width in consecutive spaces + CPPUNIT_ASSERT_EQUAL(2, getPages()); #else - // still 1 here - CPPUNIT_ASSERT_EQUAL(1, getPages()); + // still 1 here + CPPUNIT_ASSERT_EQUAL(1, getPages()); #endif + }; + createSwDoc("tdf123703.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testTdf123703_stshfdbch, "tdf123703_stshfdbch.rtf") +CPPUNIT_TEST_FIXTURE(Test, testTdf123703_stshfdbch) { - // still 1 here - CPPUNIT_ASSERT_EQUAL(1, getPages()); + auto verify = [this]() { + // still 1 here + CPPUNIT_ASSERT_EQUAL(1, getPages()); + }; + createSwDoc("tdf123703_stshfdbch.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testTdf123703_compatible, "tdf123703_compatible.rtf") +CPPUNIT_TEST_FIXTURE(Test, testTdf123703_compatible) { + auto verify = [this]() { #if !defined(MACOSX) - // in the case of compatibility font id 31505 - CPPUNIT_ASSERT_EQUAL(2, getPages()); + // in the case of compatibility font id 31505 + CPPUNIT_ASSERT_EQUAL(2, getPages()); #else - // still 1 here - CPPUNIT_ASSERT_EQUAL(1, getPages()); + // still 1 here + CPPUNIT_ASSERT_EQUAL(1, getPages()); #endif + }; + createSwDoc("tdf123703_compatible.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testTdf128428_monospaced, "tdf128428_monospaced.rtf") +CPPUNIT_TEST_FIXTURE(Test, testTdf128428_monospaced) { - // still 1 here - CPPUNIT_ASSERT_EQUAL(1, getPages()); + auto verify = [this]() { + // still 1 here + CPPUNIT_ASSERT_EQUAL(1, getPages()); + }; + createSwDoc("tdf128428_monospaced.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testTdf128428_compatible_monospaced, "tdf128428_compatible_monospaced.rtf") +CPPUNIT_TEST_FIXTURE(Test, testTdf128428_compatible_monospaced) { - // still 1 here - CPPUNIT_ASSERT_EQUAL(1, getPages()); + auto verify = [this]() { + // still 1 here + CPPUNIT_ASSERT_EQUAL(1, getPages()); + }; + createSwDoc("tdf128428_compatible_monospaced.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testTdf128428_dntblnsbdb, "tdf128428_dntblnsbdb.rtf") +CPPUNIT_TEST_FIXTURE(Test, testTdf128428_dntblnsbdb) { - // still 1 here - CPPUNIT_ASSERT_EQUAL(1, getPages()); + auto verify = [this]() { + // still 1 here + CPPUNIT_ASSERT_EQUAL(1, getPages()); + }; + createSwDoc("tdf128428_dntblnsbdb.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } CPPUNIT_TEST_FIXTURE(Test, testDontBreakWrappedTables) @@ -566,43 +743,62 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf127806) CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(635), aSize.Width); } -DECLARE_RTFEXPORT_TEST(testTdf148578, "tdf148578.rtf") +CPPUNIT_TEST_FIXTURE(Test, testTdf148578) { - // rgaph567 should affect only table cell margins (~1cm), - // but do not shift table, since rleft is not provided - uno::Reference<text::XTextTable> xTable(getParagraphOrTable(1), uno::UNO_QUERY); - - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), getProperty<sal_Int32>(xTable, "LeftMargin")); - - uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1000), - getProperty<sal_Int32>(xCell, "LeftBorderDistance")); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1000), - getProperty<sal_Int32>(xCell, "RightBorderDistance")); - - xCell.set(xTable->getCellByName("B1"), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1000), - getProperty<sal_Int32>(xCell, "LeftBorderDistance")); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1000), - getProperty<sal_Int32>(xCell, "RightBorderDistance")); + auto verify = [this]() { + // rgaph567 should affect only table cell margins (~1cm), + // but do not shift table, since rleft is not provided + uno::Reference<text::XTextTable> xTable(getParagraphOrTable(1), uno::UNO_QUERY); + + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), + getProperty<sal_Int32>(xTable, "LeftMargin")); + + uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1000), + getProperty<sal_Int32>(xCell, "LeftBorderDistance")); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1000), + getProperty<sal_Int32>(xCell, "RightBorderDistance")); + + xCell.set(xTable->getCellByName("B1"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1000), + getProperty<sal_Int32>(xCell, "LeftBorderDistance")); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1000), + getProperty<sal_Int32>(xCell, "RightBorderDistance")); + }; + createSwDoc("tdf148578.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testInvalidParagraphStyle, "invalidParagraphStyle.rtf") +CPPUNIT_TEST_FIXTURE(Test, testInvalidParagraphStyle) { - // Given test has character style #30, but referred as paragraph style #30 - // This was causing exception in finishParagraph(), so numbering and other - // properties were not applied. Ensure numbering is still here - sal_Int16 numFormat = getNumberingTypeOfParagraph(1); - CPPUNIT_ASSERT_EQUAL(style::NumberingType::ARABIC, numFormat); + auto verify = [this]() { + // Given test has character style #30, but referred as paragraph style #30 + // This was causing exception in finishParagraph(), so numbering and other + // properties were not applied. Ensure numbering is still here + sal_Int16 numFormat = getNumberingTypeOfParagraph(1); + CPPUNIT_ASSERT_EQUAL(style::NumberingType::ARABIC, numFormat); + }; + createSwDoc("invalidParagraphStyle.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } -DECLARE_RTFEXPORT_TEST(testTdf152784_1, "tdf152784_1.rtf") +CPPUNIT_TEST_FIXTURE(Test, testTdf152784_1) { - // Ensure that paragraph having style with numbering does not have numbering - // since it is not explicitly defined in paragraph properties - uno::Reference<beans::XPropertySet> xPara(getParagraph(1, "Here should be no numbering!"), - uno::UNO_QUERY); - CPPUNIT_ASSERT(getProperty<OUString>(xPara, "NumberingStyleName").isEmpty()); + auto verify = [this]() { + // Ensure that paragraph having style with numbering does not have numbering + // since it is not explicitly defined in paragraph properties + uno::Reference<beans::XPropertySet> xPara(getParagraph(1, "Here should be no numbering!"), + uno::UNO_QUERY); + CPPUNIT_ASSERT(getProperty<OUString>(xPara, "NumberingStyleName").isEmpty()); + }; + createSwDoc("tdf152784_1.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } CPPUNIT_TEST_FIXTURE(Test, testFloatingTableExport) @@ -709,13 +905,19 @@ CPPUNIT_TEST_FIXTURE(Test, testFloattableOverlapNeverRTFExport) CPPUNIT_ASSERT(!pFly->GetAttrSet().GetWrapInfluenceOnObjPos().GetAllowOverlap()); } -DECLARE_RTFEXPORT_TEST(testTdf158409, "tdf158409.rtf") +CPPUNIT_TEST_FIXTURE(Test, testTdf158409) { - uno::Reference<text::XTextRange> xRun = getRun(getParagraph(1), 1, "DocTitle"); - CPPUNIT_ASSERT_EQUAL(8.0, getProperty<double>(xRun, "CharHeight")); + auto verify = [this]() { + uno::Reference<text::XTextRange> xRun = getRun(getParagraph(1), 1, "DocTitle"); + CPPUNIT_ASSERT_EQUAL(8.0, getProperty<double>(xRun, "CharHeight")); - xRun = getRun(getParagraph(2), 1, "DocTitle"); - CPPUNIT_ASSERT_EQUAL(8.0, getProperty<double>(xRun, "CharHeight")); + xRun = getRun(getParagraph(2), 1, "DocTitle"); + CPPUNIT_ASSERT_EQUAL(8.0, getProperty<double>(xRun, "CharHeight")); + }; + createSwDoc("tdf158409.rtf"); + verify(); + saveAndReload(mpFilter); + verify(); } CPPUNIT_TEST_FIXTURE(Test, testLegalNumbering)