sw/qa/extras/ooxmlexport/ooxmlexport14.cxx | 60 +--- sw/qa/extras/ooxmlexport/ooxmlexport15.cxx | 288 ++++++++++--------- sw/qa/extras/ooxmlexport/ooxmlexport16.cxx | 84 +++-- sw/qa/extras/ooxmlexport/ooxmlexport19.cxx | 264 +++++++++-------- sw/qa/extras/ooxmlexport/ooxmlexport20.cxx | 87 ++--- sw/qa/extras/ooxmlexport/ooxmlexport21.cxx | 171 ++++++----- sw/qa/extras/ooxmlexport/ooxmlexport9.cxx | 201 +++++++------ sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx | 390 ++++++++++++++------------ 8 files changed, 829 insertions(+), 716 deletions(-)
New commits: commit d0ffbb841af2a3ca0c87b6d7275b33259a180892 Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Wed Oct 16 14:34:45 2024 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Wed Oct 16 16:02:50 2024 +0200 ooxmlexport: drop isExported (part 2) Change-Id: I253b5a10214f494b1a9a77b09241cf6cdaa4dc22 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175018 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> Tested-by: Jenkins diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx index 45c966c8ab64..b0a65122bafb 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport14.cxx @@ -539,13 +539,8 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf130610) } // check inline text properties - { - if (isExported()) - { - xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); - assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r/w:rPr/w:b"); - } - } + xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); + assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r/w:rPr/w:b"); } CPPUNIT_TEST_FIXTURE(Test, testTdf121045) @@ -781,24 +776,31 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf121661) CPPUNIT_ASSERT_GREATER( static_cast<sal_Int16>(0), getProperty<sal_Int16>(xStyle, u"ParaHyphenationZone"_ustr)); } -DECLARE_OOXMLEXPORT_TEST(testTdf149421, "tdf121661.docx") +CPPUNIT_TEST_FIXTURE(Test, testTdf149421) { - uno::Reference<beans::XPropertySet> xStyle(getStyles(u"ParagraphStyles"_ustr)->getByName(u"Standard"_ustr), uno::UNO_QUERY); - // This was false - CPPUNIT_ASSERT_GREATER( static_cast<sal_Int16>(0), getProperty<sal_Int16>(xStyle, u"ParaHyphenationZone"_ustr)); + auto verify = [this](bool bIsExport = false) { + uno::Reference<beans::XPropertySet> xStyle(getStyles(u"ParagraphStyles"_ustr)->getByName(u"Standard"_ustr), uno::UNO_QUERY); + // This was false + CPPUNIT_ASSERT_GREATER( static_cast<sal_Int16>(0), getProperty<sal_Int16>(xStyle, u"ParaHyphenationZone"_ustr)); - if (!isExported()) - { - CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int16>(851), getProperty<sal_Int16>(xStyle, u"ParaHyphenationZone"_ustr)); - // modify hyphenation zone (note: only hyphenation zone set in Standard paragraph style - // is exported, according to the document-level hyphenation settings of OOXML) - xStyle->setPropertyValue(u"ParaHyphenationZone"_ustr, uno::Any(static_cast<sal_Int16>(2000))); - } - else - { - // check the export of the modified hyphenation zone - CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int16>(2000), getProperty<sal_Int16>(xStyle, u"ParaHyphenationZone"_ustr)); - } + if (!bIsExport) + { + CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int16>(851), getProperty<sal_Int16>(xStyle, u"ParaHyphenationZone"_ustr)); + // modify hyphenation zone (note: only hyphenation zone set in Standard paragraph style + // is exported, according to the document-level hyphenation settings of OOXML) + xStyle->setPropertyValue(u"ParaHyphenationZone"_ustr, uno::Any(static_cast<sal_Int16>(2000))); + } + else + { + // check the export of the modified hyphenation zone + CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int16>(2000), getProperty<sal_Int16>(xStyle, u"ParaHyphenationZone"_ustr)); + } + }; + + createSwDoc("tdf121661.docx"); + verify(); + saveAndReload(mpFilter); + verify(/*bIsExport*/ true); } DECLARE_OOXMLEXPORT_TEST(testTdf149421_default, "tdf146171.docx") @@ -1689,8 +1691,6 @@ DECLARE_OOXMLEXPORT_TEST(testVmlShapeTextWordWrap, "tdf97618_testVmlShapeTextWor { // tdf#97618 The text wrapping of a shape was not handled in a canvas. // TODO: fix export too - if (isExported()) - return; xmlDocUniquePtr pXmlDoc = parseLayoutDump(); if (!pXmlDoc) return; @@ -1699,11 +1699,10 @@ DECLARE_OOXMLEXPORT_TEST(testVmlShapeTextWordWrap, "tdf97618_testVmlShapeTextWor } */ -DECLARE_OOXMLEXPORT_TEST(testVmlLineShapeMirroredX, "tdf97517_testVmlLineShapeMirroredX.docx") +CPPUNIT_TEST_FIXTURE(Test, testVmlLineShapeMirroredX) { // tdf#97517 The "flip:x" was not handled for VML line shapes. - if (!isExported()) - return; + loadAndSave("tdf97517_testVmlLineShapeMirroredX.docx"); xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); OUString sStyle = getXPath(pXmlDoc, "/w:document/w:body/w:p[3]/w:r/mc:AlternateContent/mc:Fallback/w:pict/v:line", @@ -1711,11 +1710,10 @@ DECLARE_OOXMLEXPORT_TEST(testVmlLineShapeMirroredX, "tdf97517_testVmlLineShapeMi CPPUNIT_ASSERT(sStyle.indexOf("flip:x") > 0); } -DECLARE_OOXMLEXPORT_TEST(testVmlLineShapeMirroredY, "tdf137678_testVmlLineShapeMirroredY.docx") +CPPUNIT_TEST_FIXTURE(Test, testVmlLineShapeMirroredY) { // tdf#137678 The "flip:y" was not handled for VML line shapes. - if (!isExported()) - return; + loadAndSave("tdf137678_testVmlLineShapeMirroredY.docx"); xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); OUString sStyle = getXPath(pXmlDoc, "/w:document/w:body/w:p[3]/w:r/mc:AlternateContent/mc:Fallback/w:pict/v:line", diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx index d606b5e209f6..4ea70d6ab4db 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx @@ -48,38 +48,43 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf131540) getProperty<sal_Int16>(getShape(2), u"HoriOrientRelation"_ustr)); } -DECLARE_OOXMLEXPORT_TEST(testTdf131801, "tdf131801.docx") -{ - CPPUNIT_ASSERT_EQUAL(1, getPages()); +CPPUNIT_TEST_FIXTURE(Test, testTdf131801) +{ + auto verify = [this]() { + CPPUNIT_ASSERT_EQUAL(1, getPages()); + + xmlDocUniquePtr pDump = parseLayoutDump(); + // "1." is red + assertXPath(pDump, "//page[1]/body/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion", "expand", u"1."); + assertXPath(pDump, "//page[1]/body/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion/SwFont", "color", u"00ff0000"); + // "2." is red + assertXPath(pDump, "//page[1]/body/txt[2]/SwParaPortion/SwLineLayout/SwFieldPortion", "expand", u"2."); + assertXPath(pDump, "//page[1]/body/txt[2]/SwParaPortion/SwLineLayout/SwFieldPortion/SwFont", "color", u"00ff0000"); + // "3." is black + assertXPath(pDump, "//page[1]/body/txt[3]/SwParaPortion/SwLineLayout/SwFieldPortion", "expand", u"3."); + assertXPath(pDump, "//page[1]/body/txt[3]/SwParaPortion/SwLineLayout/SwFieldPortion/SwFont", "color", u"ffffffff"); + // "4." is black + assertXPath(pDump, "//page[1]/body/txt[4]/SwParaPortion/SwLineLayout/SwFieldPortion", "expand", u"4."); + assertXPath(pDump, "//page[1]/body/txt[4]/SwParaPortion/SwLineLayout/SwFieldPortion/SwFont", "color", u"ffffffff"); + // "5." is red + assertXPath(pDump, "//page[1]/body/txt[5]/SwParaPortion/SwLineLayout/SwFieldPortion", "expand", u"5."); + assertXPath(pDump, "//page[1]/body/txt[5]/SwParaPortion/SwLineLayout/SwFieldPortion/SwFont", "color", u"00ff0000"); + // "6." is red + assertXPath(pDump, "//page[1]/body/txt[6]/SwParaPortion/SwLineLayout/SwFieldPortion", "expand", u"6."); + assertXPath(pDump, "//page[1]/body/txt[6]/SwParaPortion/SwLineLayout/SwFieldPortion/SwFont", "color", u"00ff0000"); + // "7." is black + assertXPath(pDump, "//page[1]/body/txt[7]/SwParaPortion/SwLineLayout/SwFieldPortion", "expand", u"7."); + assertXPath(pDump, "//page[1]/body/txt[7]/SwParaPortion/SwLineLayout/SwFieldPortion/SwFont", "color", u"ffffffff"); + // "8." is black + assertXPath(pDump, "//page[1]/body/txt[8]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", u"8."); + assertXPath(pDump, "//page[1]/body/txt[8]/SwParaPortion/SwLineLayout/SwFieldPortion[1]/SwFont", "color", u"ffffffff"); + }; + + createSwDoc("tdf131801.docx"); + verify(); + saveAndReload(mpFilter); + verify(); - xmlDocUniquePtr pDump = parseLayoutDump(); - // "1." is red - assertXPath(pDump, "//page[1]/body/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion", "expand", u"1."); - assertXPath(pDump, "//page[1]/body/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion/SwFont", "color", u"00ff0000"); - // "2." is red - assertXPath(pDump, "//page[1]/body/txt[2]/SwParaPortion/SwLineLayout/SwFieldPortion", "expand", u"2."); - assertXPath(pDump, "//page[1]/body/txt[2]/SwParaPortion/SwLineLayout/SwFieldPortion/SwFont", "color", u"00ff0000"); - // "3." is black - assertXPath(pDump, "//page[1]/body/txt[3]/SwParaPortion/SwLineLayout/SwFieldPortion", "expand", u"3."); - assertXPath(pDump, "//page[1]/body/txt[3]/SwParaPortion/SwLineLayout/SwFieldPortion/SwFont", "color", u"ffffffff"); - // "4." is black - assertXPath(pDump, "//page[1]/body/txt[4]/SwParaPortion/SwLineLayout/SwFieldPortion", "expand", u"4."); - assertXPath(pDump, "//page[1]/body/txt[4]/SwParaPortion/SwLineLayout/SwFieldPortion/SwFont", "color", u"ffffffff"); - // "5." is red - assertXPath(pDump, "//page[1]/body/txt[5]/SwParaPortion/SwLineLayout/SwFieldPortion", "expand", u"5."); - assertXPath(pDump, "//page[1]/body/txt[5]/SwParaPortion/SwLineLayout/SwFieldPortion/SwFont", "color", u"00ff0000"); - // "6." is red - assertXPath(pDump, "//page[1]/body/txt[6]/SwParaPortion/SwLineLayout/SwFieldPortion", "expand", u"6."); - assertXPath(pDump, "//page[1]/body/txt[6]/SwParaPortion/SwLineLayout/SwFieldPortion/SwFont", "color", u"00ff0000"); - // "7." is black - assertXPath(pDump, "//page[1]/body/txt[7]/SwParaPortion/SwLineLayout/SwFieldPortion", "expand", u"7."); - assertXPath(pDump, "//page[1]/body/txt[7]/SwParaPortion/SwLineLayout/SwFieldPortion/SwFont", "color", u"ffffffff"); - // "8." is black - assertXPath(pDump, "//page[1]/body/txt[8]/SwParaPortion/SwLineLayout/SwFieldPortion[1]", "expand", u"8."); - assertXPath(pDump, "//page[1]/body/txt[8]/SwParaPortion/SwLineLayout/SwFieldPortion[1]/SwFont", "color", u"ffffffff"); - - if (!isExported()) - return; xmlDocUniquePtr pXmlDocument = parseExport(u"word/document.xml"_ustr); assertXPath(pXmlDocument, "/w:document/w:body/w:p[1]/w:pPr/w:rPr/w:rStyle", @@ -194,21 +199,25 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf123401) assertXPathContent(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[4]/w:tc/w:p/w:r[2]/w:instrText", u" =AVERAGE(A1:A3)"); } -DECLARE_OOXMLEXPORT_TEST(testTdf116394, "tdf116394.docx") +CPPUNIT_TEST_FIXTURE(Test, testTdf116394) { - uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); - uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); + auto verify = [this]() { + uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); - uno::Reference<text::XTextField> xEnumerationAccess(xFields->nextElement(), uno::UNO_QUERY); + uno::Reference<text::XTextField> xEnumerationAccess(xFields->nextElement(), uno::UNO_QUERY); - // Without the fix in place, this test would have failed with - // - Expected: ab=cd.. - // - Actual : abcd.. - CPPUNIT_ASSERT_EQUAL(u"ab=cd.."_ustr, xEnumerationAccess->getPresentation(true).trim()); + // Without the fix in place, this test would have failed with + // - Expected: ab=cd.. + // - Actual : abcd.. + CPPUNIT_ASSERT_EQUAL(u"ab=cd.."_ustr, xEnumerationAccess->getPresentation(true).trim()); + }; - if (!isExported()) - return; + createSwDoc("tdf116394.docx"); + verify(); + saveAndReload(mpFilter); + verify(); xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r[2]/w:instrText", u" MERGEFIELD ab=cd "); } @@ -325,42 +334,47 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf123354) CPPUNIT_ASSERT_EQUAL(u"0"_ustr, xEnumerationAccess3->getPresentation(false).trim()); } -DECLARE_OOXMLEXPORT_TEST(testTdf123355, "tdf123355.docx") +CPPUNIT_TEST_FIXTURE(Test, testTdf123355) { - uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); - uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); + auto verify = [this]() { + uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); - // Tests conversion of range IDs ABOVE, BELOW, LEFT and RIGHT - uno::Reference<text::XTextField> xEnumerationAccess1(xFields->nextElement(), uno::UNO_QUERY); - // Note: range ends at B4 here, which is a cell with text content - CPPUNIT_ASSERT_EQUAL(u"average( <B2:B3> )"_ustr, xEnumerationAccess1->getPresentation(true).trim()); - CPPUNIT_ASSERT_EQUAL(u"5,5"_ustr, xEnumerationAccess1->getPresentation(false).trim()); + // Tests conversion of range IDs ABOVE, BELOW, LEFT and RIGHT + uno::Reference<text::XTextField> xEnumerationAccess1(xFields->nextElement(), uno::UNO_QUERY); + // Note: range ends at B4 here, which is a cell with text content + CPPUNIT_ASSERT_EQUAL(u"average( <B2:B3> )"_ustr, xEnumerationAccess1->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(u"5,5"_ustr, xEnumerationAccess1->getPresentation(false).trim()); - // range ends at the end of the empty cells - uno::Reference<text::XTextField> xEnumerationAccess6(xFields->nextElement(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(u"SUM(<C6:A6>)"_ustr, xEnumerationAccess6->getPresentation(true).trim()); - CPPUNIT_ASSERT_EQUAL(u"0"_ustr, xEnumerationAccess6->getPresentation(false).trim()); + // range ends at the end of the empty cells + uno::Reference<text::XTextField> xEnumerationAccess6(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(u"SUM(<C6:A6>)"_ustr, xEnumerationAccess6->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(u"0"_ustr, xEnumerationAccess6->getPresentation(false).trim()); - // range starts at the first cell above D5 - uno::Reference<text::XTextField> xEnumerationAccess2(xFields->nextElement(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(u"AVERAGE(<D4:D1>)"_ustr, xEnumerationAccess2->getPresentation(true).trim()); - CPPUNIT_ASSERT_EQUAL(u"5,33"_ustr, xEnumerationAccess2->getPresentation(false).trim()); + // range starts at the first cell above D5 + uno::Reference<text::XTextField> xEnumerationAccess2(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(u"AVERAGE(<D4:D1>)"_ustr, xEnumerationAccess2->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(u"5,33"_ustr, xEnumerationAccess2->getPresentation(false).trim()); - uno::Reference<text::XTextField> xEnumerationAccess3(xFields->nextElement(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(u"AVERAGE(<C2:C1>)"_ustr, xEnumerationAccess3->getPresentation(true).trim()); - CPPUNIT_ASSERT_EQUAL(u"3,5"_ustr, xEnumerationAccess3->getPresentation(false).trim()); + uno::Reference<text::XTextField> xEnumerationAccess3(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(u"AVERAGE(<C2:C1>)"_ustr, xEnumerationAccess3->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(u"3,5"_ustr, xEnumerationAccess3->getPresentation(false).trim()); - uno::Reference<text::XTextField> xEnumerationAccess4(xFields->nextElement(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(u"AVERAGE(<D2:D2>)"_ustr, xEnumerationAccess4->getPresentation(true).trim()); - CPPUNIT_ASSERT_EQUAL(u"5"_ustr, xEnumerationAccess4->getPresentation(false).trim()); + uno::Reference<text::XTextField> xEnumerationAccess4(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(u"AVERAGE(<D2:D2>)"_ustr, xEnumerationAccess4->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(u"5"_ustr, xEnumerationAccess4->getPresentation(false).trim()); - uno::Reference<text::XTextField> xEnumerationAccess5(xFields->nextElement(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(u"AVERAGE(<A2:A2>)"_ustr, xEnumerationAccess5->getPresentation(true).trim()); - CPPUNIT_ASSERT_EQUAL(u"4"_ustr, xEnumerationAccess5->getPresentation(false).trim()); + uno::Reference<text::XTextField> xEnumerationAccess5(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(u"AVERAGE(<A2:A2>)"_ustr, xEnumerationAccess5->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(u"4"_ustr, xEnumerationAccess5->getPresentation(false).trim()); + }; + + createSwDoc("tdf123355.docx"); + verify(); + saveAndReload(mpFilter); + verify(); - if (!isExported()) - return; xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); // keep original formula IDs @@ -372,46 +386,51 @@ DECLARE_OOXMLEXPORT_TEST(testTdf123355, "tdf123355.docx") assertXPathContent(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[6]/w:tc[4]/w:p/w:r[2]/w:instrText", u" =SUM(LEFT)"); } -DECLARE_OOXMLEXPORT_TEST(testTdf123382, "tdf123382.docx") +CPPUNIT_TEST_FIXTURE(Test, testTdf123382) { - uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); - uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); + auto verify = [this]() { + uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); - // Tests conversion of range IDs ABOVE, BELOW, LEFT and RIGHT - uno::Reference<text::XTextField> xEnumerationAccess1(xFields->nextElement(), uno::UNO_QUERY); - // Note: range ends at B4 here, which is a cell with text content - CPPUNIT_ASSERT_EQUAL(u"MAX(<B1:D1>)"_ustr, xEnumerationAccess1->getPresentation(true).trim()); - CPPUNIT_ASSERT_EQUAL(u"12"_ustr, xEnumerationAccess1->getPresentation(false).trim()); + // Tests conversion of range IDs ABOVE, BELOW, LEFT and RIGHT + uno::Reference<text::XTextField> xEnumerationAccess1(xFields->nextElement(), uno::UNO_QUERY); + // Note: range ends at B4 here, which is a cell with text content + CPPUNIT_ASSERT_EQUAL(u"MAX(<B1:D1>)"_ustr, xEnumerationAccess1->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(u"12"_ustr, xEnumerationAccess1->getPresentation(false).trim()); - // range ends at the end of the empty cells - uno::Reference<text::XTextField> xEnumerationAccess6(xFields->nextElement(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(u"MAX(<C4:D4>)"_ustr, xEnumerationAccess6->getPresentation(true).trim()); - CPPUNIT_ASSERT_EQUAL(u"9"_ustr, xEnumerationAccess6->getPresentation(false).trim()); + // range ends at the end of the empty cells + uno::Reference<text::XTextField> xEnumerationAccess6(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(u"MAX(<C4:D4>)"_ustr, xEnumerationAccess6->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(u"9"_ustr, xEnumerationAccess6->getPresentation(false).trim()); - // range starts at the first cell above D5 - uno::Reference<text::XTextField> xEnumerationAccess2(xFields->nextElement(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(u"SUM(<B3:D3>)"_ustr, xEnumerationAccess2->getPresentation(true).trim()); - CPPUNIT_ASSERT_EQUAL(u"30"_ustr, xEnumerationAccess2->getPresentation(false).trim()); + // range starts at the first cell above D5 + uno::Reference<text::XTextField> xEnumerationAccess2(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(u"SUM(<B3:D3>)"_ustr, xEnumerationAccess2->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(u"30"_ustr, xEnumerationAccess2->getPresentation(false).trim()); - uno::Reference<text::XTextField> xEnumerationAccess3(xFields->nextElement(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(u"MAX(<C2:A2>)"_ustr, xEnumerationAccess3->getPresentation(true).trim()); - CPPUNIT_ASSERT_EQUAL(u"7"_ustr, xEnumerationAccess3->getPresentation(false).trim()); + uno::Reference<text::XTextField> xEnumerationAccess3(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(u"MAX(<C2:A2>)"_ustr, xEnumerationAccess3->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(u"7"_ustr, xEnumerationAccess3->getPresentation(false).trim()); - uno::Reference<text::XTextField> xEnumerationAccess4(xFields->nextElement(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(u"MAX(<B2:D2>)"_ustr, xEnumerationAccess4->getPresentation(true).trim()); - CPPUNIT_ASSERT_EQUAL(u"7"_ustr, xEnumerationAccess4->getPresentation(false).trim()); + uno::Reference<text::XTextField> xEnumerationAccess4(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(u"MAX(<B2:D2>)"_ustr, xEnumerationAccess4->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(u"7"_ustr, xEnumerationAccess4->getPresentation(false).trim()); - uno::Reference<text::XTextField> xEnumerationAccess5(xFields->nextElement(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(u"MAX(<D2:D4>)"_ustr, xEnumerationAccess5->getPresentation(true).trim()); - CPPUNIT_ASSERT_EQUAL(u"12"_ustr, xEnumerationAccess5->getPresentation(false).trim()); + uno::Reference<text::XTextField> xEnumerationAccess5(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(u"MAX(<D2:D4>)"_ustr, xEnumerationAccess5->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(u"12"_ustr, xEnumerationAccess5->getPresentation(false).trim()); - uno::Reference<text::XTextField> xEnumerationAccess7(xFields->nextElement(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(u"MAX(<B2:B4>)"_ustr, xEnumerationAccess7->getPresentation(true).trim()); - CPPUNIT_ASSERT_EQUAL(u"10"_ustr, xEnumerationAccess7->getPresentation(false).trim()); + uno::Reference<text::XTextField> xEnumerationAccess7(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(u"MAX(<B2:B4>)"_ustr, xEnumerationAccess7->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(u"10"_ustr, xEnumerationAccess7->getPresentation(false).trim()); + }; + + createSwDoc("tdf123382.docx"); + verify(); + saveAndReload(mpFilter); + verify(); - if (!isExported()) - return; xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); // keep original formula IDs @@ -424,32 +443,37 @@ DECLARE_OOXMLEXPORT_TEST(testTdf123382, "tdf123382.docx") assertXPathContent(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[4]/w:p/w:r[2]/w:instrText", u" =MAX(LEFT)"); } -DECLARE_OOXMLEXPORT_TEST(testTdf122648, "tdf122648.docx") +CPPUNIT_TEST_FIXTURE(Test, testTdf122648) { - uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); - uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); + auto verify = [this]() { + uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); - // table formula conversion worked only in the first table - uno::Reference<text::XTextField> xEnumerationAccess1(xFields->nextElement(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(u"<A1>"_ustr, xEnumerationAccess1->getPresentation(true).trim()); - CPPUNIT_ASSERT_EQUAL(u"1"_ustr, xEnumerationAccess1->getPresentation(false).trim()); + // table formula conversion worked only in the first table + uno::Reference<text::XTextField> xEnumerationAccess1(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(u"<A1>"_ustr, xEnumerationAccess1->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(u"1"_ustr, xEnumerationAccess1->getPresentation(false).trim()); - uno::Reference<text::XTextField> xEnumerationAccess2(xFields->nextElement(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(u"SUM(<A1:B1>)"_ustr, xEnumerationAccess2->getPresentation(true).trim()); - CPPUNIT_ASSERT_EQUAL(u"2"_ustr, xEnumerationAccess2->getPresentation(false).trim()); + uno::Reference<text::XTextField> xEnumerationAccess2(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(u"SUM(<A1:B1>)"_ustr, xEnumerationAccess2->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(u"2"_ustr, xEnumerationAccess2->getPresentation(false).trim()); - // These were <?> and SUM(<?:?>) with zero values - uno::Reference<text::XTextField> xEnumerationAccess3(xFields->nextElement(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(u"<A1>"_ustr, xEnumerationAccess3->getPresentation(true).trim()); - CPPUNIT_ASSERT_EQUAL(u"1"_ustr, xEnumerationAccess3->getPresentation(false).trim()); + // These were <?> and SUM(<?:?>) with zero values + uno::Reference<text::XTextField> xEnumerationAccess3(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(u"<A1>"_ustr, xEnumerationAccess3->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(u"1"_ustr, xEnumerationAccess3->getPresentation(false).trim()); - uno::Reference<text::XTextField> xEnumerationAccess4(xFields->nextElement(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(u"SUM(<A1:B1>)"_ustr, xEnumerationAccess4->getPresentation(true).trim()); - CPPUNIT_ASSERT_EQUAL(u"2"_ustr, xEnumerationAccess4->getPresentation(false).trim()); + uno::Reference<text::XTextField> xEnumerationAccess4(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(u"SUM(<A1:B1>)"_ustr, xEnumerationAccess4->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(u"2"_ustr, xEnumerationAccess4->getPresentation(false).trim()); + }; + + createSwDoc("tdf122648.docx"); + verify(); + saveAndReload(mpFilter); + verify(); - if (!isExported()) - return; xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); assertXPathContent(pXmlDoc, "/w:document/w:body/w:tbl[1]/w:tr[1]/w:tc[2]/w:p/w:r[2]/w:instrText", u" =A1"); @@ -802,18 +826,22 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf136441_commentInFootnote) // (MS Word's UI doesn't allow adding comments to a footnote.) } -DECLARE_OOXMLEXPORT_TEST(testTdf137683_charHighlightTests, "tdf137683_charHighlightTests.docx") +CPPUNIT_TEST_FIXTURE(Test, testTdf137683_charHighlightTests) { + auto verify = [this]() { + uno::Reference<beans::XPropertySet> xRun(getRun(getParagraph(10), 2, u"no highlight"_ustr), uno::UNO_QUERY_THROW); + // This test was failing with a cyan charHighlight of 65535 (0x00FFFF), instead of COL_TRANSPARENT (0xFFFFFFFF) + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(COL_AUTO), getProperty<sal_Int32>(xRun, u"CharHighlight"_ustr)); + }; + // Don't export unnecessary w:highlight="none" (Unnecessary one intentionally hand-added to original .docx) - if (isExported()) - { - xmlDocUniquePtr pXmlStyles = parseExport(u"word/styles.xml"_ustr); - assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Normal']/w:rPr/w:highlight", 0); - } + createSwDoc("tdf137683_charHighlightTests.docx"); + verify(); + saveAndReload(mpFilter); + verify(); - uno::Reference<beans::XPropertySet> xRun(getRun(getParagraph(10), 2, u"no highlight"_ustr), uno::UNO_QUERY_THROW); - // This test was failing with a cyan charHighlight of 65535 (0x00FFFF), instead of COL_TRANSPARENT (0xFFFFFFFF) - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(COL_AUTO), getProperty<sal_Int32>(xRun, u"CharHighlight"_ustr)); + xmlDocUniquePtr pXmlStyles = parseExport(u"word/styles.xml"_ustr); + assertXPath(pXmlStyles, "/w:styles/w:style[@w:styleId='Normal']/w:rPr/w:highlight", 0); } DECLARE_OOXMLEXPORT_TEST(testTdf138345_charStyleHighlight, "tdf138345_charStyleHighlight.docx") diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx index 8fd7499625ff..67f6dccb51bb 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx @@ -461,13 +461,12 @@ CPPUNIT_TEST_FIXTURE(Test, testCustomShapePresetExport) CPPUNIT_ASSERT_EQUAL(17, nCount); } -DECLARE_OOXMLEXPORT_TEST(testTdf148671, "tdf148671.docx") +CPPUNIT_TEST_FIXTURE(Test, testTdf148671) { + loadAndSave("tdf148671.docx"); // Don't assert with 'pFieldMark' failed when document is opened CPPUNIT_ASSERT_EQUAL(1, getPages()); - if (!isExported()) - return; // Preserve tag on SDT blocks. (Before the fix, these were all lost) xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:tag", 3); @@ -934,47 +933,54 @@ DECLARE_OOXMLEXPORT_TEST(testTableWidth, "frame_size_export.docx") } -DECLARE_OOXMLEXPORT_TEST(testCommentDoneModel, "CommentDone.docx") +CPPUNIT_TEST_FIXTURE(Test, testCommentDoneModel) { - css::uno::Reference<css::text::XTextFieldsSupplier> xTextFieldsSupplier( - mxComponent, css::uno::UNO_QUERY_THROW); - auto xFields(xTextFieldsSupplier->getTextFields()->createEnumeration()); + auto verify = [this](bool bIsExport = false) { + css::uno::Reference<css::text::XTextFieldsSupplier> xTextFieldsSupplier( + mxComponent, css::uno::UNO_QUERY_THROW); + auto xFields(xTextFieldsSupplier->getTextFields()->createEnumeration()); - // First comment: initially resolved, toggled to unresolved on import, unresolved on roundtrip - CPPUNIT_ASSERT(xFields->hasMoreElements()); - css::uno::Any aComment = xFields->nextElement(); - css::uno::Reference<css::beans::XPropertySet> xComment(aComment, css::uno::UNO_QUERY_THROW); + // First comment: initially resolved, toggled to unresolved on import, unresolved on roundtrip + CPPUNIT_ASSERT(xFields->hasMoreElements()); + css::uno::Any aComment = xFields->nextElement(); + css::uno::Reference<css::beans::XPropertySet> xComment(aComment, css::uno::UNO_QUERY_THROW); - if (!isExported()) - { - // Check that it's resolved when initially read - CPPUNIT_ASSERT_EQUAL(true, xComment->getPropertyValue(u"Resolved"_ustr).get<bool>()); - // Set to unresolved - xComment->setPropertyValue(u"Resolved"_ustr, css::uno::Any(false)); - } - else - { - // After the roundtrip, it keeps the "unresolved" state set above - CPPUNIT_ASSERT_EQUAL(false, xComment->getPropertyValue(u"Resolved"_ustr).get<bool>()); - } + if (!bIsExport) + { + // Check that it's resolved when initially read + CPPUNIT_ASSERT_EQUAL(true, xComment->getPropertyValue(u"Resolved"_ustr).get<bool>()); + // Set to unresolved + xComment->setPropertyValue(u"Resolved"_ustr, css::uno::Any(false)); + } + else + { + // After the roundtrip, it keeps the "unresolved" state set above + CPPUNIT_ASSERT_EQUAL(false, xComment->getPropertyValue(u"Resolved"_ustr).get<bool>()); + } - // Second comment: initially unresolved, toggled to resolved on import, resolved on roundtrip - CPPUNIT_ASSERT(xFields->hasMoreElements()); - aComment = xFields->nextElement(); - xComment.set(aComment, css::uno::UNO_QUERY_THROW); + // Second comment: initially unresolved, toggled to resolved on import, resolved on roundtrip + CPPUNIT_ASSERT(xFields->hasMoreElements()); + aComment = xFields->nextElement(); + xComment.set(aComment, css::uno::UNO_QUERY_THROW); - if (!isExported()) - { - // Check that it's unresolved when initially read - CPPUNIT_ASSERT_EQUAL(false, xComment->getPropertyValue(u"Resolved"_ustr).get<bool>()); - // Set to resolved - xComment->setPropertyValue(u"Resolved"_ustr, css::uno::Any(true)); - } - else - { - // After the roundtrip, it keeps the "resolved" state set above - CPPUNIT_ASSERT_EQUAL(true, xComment->getPropertyValue(u"Resolved"_ustr).get<bool>()); - } + if (!bIsExport) + { + // Check that it's unresolved when initially read + CPPUNIT_ASSERT_EQUAL(false, xComment->getPropertyValue(u"Resolved"_ustr).get<bool>()); + // Set to resolved + xComment->setPropertyValue(u"Resolved"_ustr, css::uno::Any(true)); + } + else + { + // After the roundtrip, it keeps the "resolved" state set above + CPPUNIT_ASSERT_EQUAL(true, xComment->getPropertyValue(u"Resolved"_ustr).get<bool>()); + } + }; + + createSwDoc("CommentDone.docx"); + verify(); + saveAndReload(mpFilter); + verify(/*bIsExport*/ true); } CPPUNIT_TEST_FIXTURE(Test, Test_ShadowDirection) diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx index d46a7a1845d1..52d2e7c2b5e0 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx @@ -685,25 +685,27 @@ CPPUNIT_TEST_FIXTURE(Test, testTableMarginAdjustment) CPPUNIT_ASSERT_EQUAL(sal_Int16(100), getProperty<sal_Int16>(xTable, u"RelativeWidth"_ustr)); } -DECLARE_OOXMLEXPORT_TEST(testTdf119760_tableInTablePosition, "tdf119760_tableInTablePosition.docx") +CPPUNIT_TEST_FIXTURE(Test, testTdf119760_tableInTablePosition) { - if (isExported()) - { - xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); + auto verify = [this]() { + uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), + uno::UNO_QUERY); + uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY); + // For compatibilityMode 15: margin 0 means table border starts at 0, + // shifted to account for half of the thick border width, so 106, not 0. + CPPUNIT_ASSERT_EQUAL(sal_Int32(106), getProperty<sal_Int32>(xTable, u"LeftMargin"_ustr)); + }; + createSwDoc("tdf119760_tableInTablePosition.docx"); + verify(); + saveAndReload(mpFilter); + verify(); - assertXPath(pXmlDoc, "//w:tbl[1]/w:tr[1]/w:tc[1]/w:tbl[1]/w:tblPr[1]/w:tblInd[1]", "type", - u"dxa"); - assertXPath(pXmlDoc, "//w:tbl[1]/w:tr[1]/w:tc[1]/w:tbl[1]//w:tblPr[1]/w:tblInd[1]", "w", - u"0"); - } + xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); - uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), - uno::UNO_QUERY); - uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY); - // For compatibilityMode 15: margin 0 means table border starts at 0, - // shifted to account for half of the thick border width, so 106, not 0. - CPPUNIT_ASSERT_EQUAL(sal_Int32(106), getProperty<sal_Int32>(xTable, u"LeftMargin"_ustr)); + assertXPath(pXmlDoc, "//w:tbl[1]/w:tr[1]/w:tc[1]/w:tbl[1]/w:tblPr[1]/w:tblInd[1]", "type", + u"dxa"); + assertXPath(pXmlDoc, "//w:tbl[1]/w:tr[1]/w:tc[1]/w:tbl[1]//w:tblPr[1]/w:tblInd[1]", "w", u"0"); } DECLARE_OOXMLEXPORT_TEST(testTableCellMargin, "table-cell-margin.docx") @@ -868,14 +870,12 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf77236_MissingSolidFill) 1); } -DECLARE_OOXMLEXPORT_TEST(testTdf105875_VmlShapeRotationWithFlip, - "tdf105875_VmlShapeRotationWithFlip.docx") +CPPUNIT_TEST_FIXTURE(Test, testTdf105875_VmlShapeRotationWithFlip) { // tdf#105875: check whether the rotation of the VML bezier shape is ok (with flip too) // TODO: fix export too - if (isExported()) - return; + createSwDoc("tdf105875_VmlShapeRotationWithFlip.docx"); { uno::Reference<beans::XPropertySet> xPropertySet(getShape(1), uno::UNO_QUERY_THROW); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), @@ -922,57 +922,67 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf133363) u"0"); } -DECLARE_OOXMLEXPORT_TEST(testTdf138093, "tdf138093.docx") +CPPUNIT_TEST_FIXTURE(Test, testTdf138093) { - if (isExported()) - { - xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); - assertXPath(pXmlDoc, "//w:sdt", 3); - uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), - uno::UNO_QUERY); - uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY); - uno::Reference<table::XCell> xCell = xTable->getCellByName(u"B1"_ustr); - uno::Reference<container::XEnumerationAccess> xParagraphsAccess(xCell, uno::UNO_QUERY); - uno::Reference<container::XEnumeration> xParagraphs - = xParagraphsAccess->createEnumeration(); - uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphs->nextElement(), - uno::UNO_QUERY); - uno::Reference<container::XEnumeration> xPortions = xParagraph->createEnumeration(); - uno::Reference<beans::XPropertySet> xTextPortion(xPortions->nextElement(), uno::UNO_QUERY); - - OUString aPortionType; - xTextPortion->getPropertyValue(u"TextPortionType"_ustr) >>= aPortionType; - CPPUNIT_ASSERT_EQUAL(u"ContentControl"_ustr, aPortionType); - - uno::Reference<text::XTextContent> xContentControl; - xTextPortion->getPropertyValue(u"ContentControl"_ustr) >>= xContentControl; - uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY); - bool bDate{}; - xContentControlProps->getPropertyValue(u"Date"_ustr) >>= bDate; - CPPUNIT_ASSERT(bDate); - uno::Reference<container::XEnumerationAccess> xContentControlEnumAccess(xContentControl, - uno::UNO_QUERY); - uno::Reference<container::XEnumeration> xContentControlEnum - = xContentControlEnumAccess->createEnumeration(); - uno::Reference<text::XTextRange> xTextPortionRange(xContentControlEnum->nextElement(), - uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(u"2017"_ustr, xTextPortionRange->getString()); - } - else - { - SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); - CPPUNIT_ASSERT(pTextDoc); - SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc(); - IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess(); - CPPUNIT_ASSERT_EQUAL(sal_Int32(2), pMarkAccess->getAllMarksCount()); - - ::sw::mark::DateFieldmark* pFieldmark - = dynamic_cast<::sw::mark::DateFieldmark*>(*pMarkAccess->getAllMarksBegin()); - CPPUNIT_ASSERT(pFieldmark); - CPPUNIT_ASSERT_EQUAL(ODF_FORMDATE, pFieldmark->GetFieldname()); - CPPUNIT_ASSERT_EQUAL(u"2017"_ustr, pFieldmark->GetContent()); - } + auto verify = [this](bool bIsExport = false) { + if (bIsExport) + { + uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), + uno::UNO_QUERY); + uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY); + uno::Reference<table::XCell> xCell = xTable->getCellByName(u"B1"_ustr); + uno::Reference<container::XEnumerationAccess> xParagraphsAccess(xCell, uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xParagraphs + = xParagraphsAccess->createEnumeration(); + uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphs->nextElement(), + uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xPortions = xParagraph->createEnumeration(); + uno::Reference<beans::XPropertySet> xTextPortion(xPortions->nextElement(), + uno::UNO_QUERY); + + OUString aPortionType; + xTextPortion->getPropertyValue(u"TextPortionType"_ustr) >>= aPortionType; + CPPUNIT_ASSERT_EQUAL(u"ContentControl"_ustr, aPortionType); + + uno::Reference<text::XTextContent> xContentControl; + xTextPortion->getPropertyValue(u"ContentControl"_ustr) >>= xContentControl; + uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, + uno::UNO_QUERY); + bool bDate{}; + xContentControlProps->getPropertyValue(u"Date"_ustr) >>= bDate; + CPPUNIT_ASSERT(bDate); + uno::Reference<container::XEnumerationAccess> xContentControlEnumAccess(xContentControl, + uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xContentControlEnum + = xContentControlEnumAccess->createEnumeration(); + uno::Reference<text::XTextRange> xTextPortionRange(xContentControlEnum->nextElement(), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(u"2017"_ustr, xTextPortionRange->getString()); + } + else + { + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc(); + IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), pMarkAccess->getAllMarksCount()); + + ::sw::mark::DateFieldmark* pFieldmark + = dynamic_cast<::sw::mark::DateFieldmark*>(*pMarkAccess->getAllMarksBegin()); + CPPUNIT_ASSERT(pFieldmark); + CPPUNIT_ASSERT_EQUAL(ODF_FORMDATE, pFieldmark->GetFieldname()); + CPPUNIT_ASSERT_EQUAL(u"2017"_ustr, pFieldmark->GetContent()); + } + }; + + createSwDoc("tdf138093.docx"); + verify(); + saveAndReload(mpFilter); + verify(/*bIsExport*/ true); + + xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); + assertXPath(pXmlDoc, "//w:sdt", 3); } CPPUNIT_TEST_FIXTURE(Test, testTdf138093B) @@ -1012,61 +1022,71 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf138093B) CPPUNIT_ASSERT_EQUAL(u"2019"_ustr, xTextPortionRange->getString()); } -DECLARE_OOXMLEXPORT_TEST(testTdf131722, "tdf131722.docx") +CPPUNIT_TEST_FIXTURE(Test, testTdf131722) { - if (isExported()) - { - xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); - assertXPath(pXmlDoc, "//w:sdt", 4); - uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), - uno::UNO_QUERY); - uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY); - uno::Reference<table::XCell> xCell = xTable->getCellByName(u"A1"_ustr); - uno::Reference<container::XEnumerationAccess> xParagraphsAccess(xCell, uno::UNO_QUERY); - uno::Reference<container::XEnumeration> xParagraphs - = xParagraphsAccess->createEnumeration(); - uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphs->nextElement(), - uno::UNO_QUERY); - uno::Reference<container::XEnumeration> xPortions = xParagraph->createEnumeration(); - uno::Reference<beans::XPropertySet> xTextPortion(xPortions->nextElement(), uno::UNO_QUERY); - - OUString aPortionType; - xTextPortion->getPropertyValue(u"TextPortionType"_ustr) >>= aPortionType; - CPPUNIT_ASSERT_EQUAL(u"ContentControl"_ustr, aPortionType); - - uno::Reference<text::XTextContent> xContentControl; - xTextPortion->getPropertyValue(u"ContentControl"_ustr) >>= xContentControl; - uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY); - bool bDate{}; - xContentControlProps->getPropertyValue(u"Date"_ustr) >>= bDate; - CPPUNIT_ASSERT(bDate); - uno::Reference<container::XEnumerationAccess> xContentControlEnumAccess(xContentControl, - uno::UNO_QUERY); - uno::Reference<container::XEnumeration> xContentControlEnum - = xContentControlEnumAccess->createEnumeration(); - uno::Reference<text::XTextRange> xTextPortionRange(xContentControlEnum->nextElement(), - uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(u"Enter a date here!"_ustr, xTextPortionRange->getString()); - } - else - { - SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); - CPPUNIT_ASSERT(pTextDoc); - SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc(); - IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess(); - CPPUNIT_ASSERT_EQUAL(sal_Int32(2), pMarkAccess->getFieldmarksCount()); - - for (auto aIter = pMarkAccess->getFieldmarksBegin(); - aIter != pMarkAccess->getFieldmarksEnd(); ++aIter) + auto verify = [this](bool bIsExport = false) { + if (bIsExport) { - ::sw::mark::DateFieldmark* pFieldmark - = dynamic_cast<::sw::mark::DateFieldmark*>(*aIter); - CPPUNIT_ASSERT(pFieldmark); - CPPUNIT_ASSERT_EQUAL(ODF_FORMDATE, pFieldmark->GetFieldname()); - CPPUNIT_ASSERT_EQUAL(u"Enter a date here!"_ustr, pFieldmark->GetContent()); + uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), + uno::UNO_QUERY); + uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY); + uno::Reference<table::XCell> xCell = xTable->getCellByName(u"A1"_ustr); + uno::Reference<container::XEnumerationAccess> xParagraphsAccess(xCell, uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xParagraphs + = xParagraphsAccess->createEnumeration(); + uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphs->nextElement(), + uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xPortions = xParagraph->createEnumeration(); + uno::Reference<beans::XPropertySet> xTextPortion(xPortions->nextElement(), + uno::UNO_QUERY); + + OUString aPortionType; + xTextPortion->getPropertyValue(u"TextPortionType"_ustr) >>= aPortionType; + CPPUNIT_ASSERT_EQUAL(u"ContentControl"_ustr, aPortionType); + + uno::Reference<text::XTextContent> xContentControl; + xTextPortion->getPropertyValue(u"ContentControl"_ustr) >>= xContentControl; + uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, + uno::UNO_QUERY); + bool bDate{}; + xContentControlProps->getPropertyValue(u"Date"_ustr) >>= bDate; + CPPUNIT_ASSERT(bDate); + uno::Reference<container::XEnumerationAccess> xContentControlEnumAccess(xContentControl, + uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xContentControlEnum + = xContentControlEnumAccess->createEnumeration(); + uno::Reference<text::XTextRange> xTextPortionRange(xContentControlEnum->nextElement(), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(u"Enter a date here!"_ustr, xTextPortionRange->getString()); } - } + else + { + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc(); + IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), pMarkAccess->getFieldmarksCount()); + + for (auto aIter = pMarkAccess->getFieldmarksBegin(); + aIter != pMarkAccess->getFieldmarksEnd(); ++aIter) + { + ::sw::mark::DateFieldmark* pFieldmark + = dynamic_cast<::sw::mark::DateFieldmark*>(*aIter); + CPPUNIT_ASSERT(pFieldmark); + CPPUNIT_ASSERT_EQUAL(ODF_FORMDATE, pFieldmark->GetFieldname()); + CPPUNIT_ASSERT_EQUAL(u"Enter a date here!"_ustr, pFieldmark->GetContent()); + } + } + }; + + createSwDoc("tdf131722.docx"); + verify(); + saveAndReload(mpFilter); + verify(/*bIsExport*/ true); + + xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); + assertXPath(pXmlDoc, "//w:sdt", 4); } CPPUNIT_TEST_FIXTURE(Test, testTdf155945) diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport20.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport20.cxx index cce8ae49d7c1..f7b87a1fdb8a 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport20.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport20.cxx @@ -208,13 +208,9 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf128646) xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr/w:tc/w:p[7]/w:pPr/w:rPr/w:vanish", 1); - if (!isExported()) - // originally no <w:vanish> (the same as <w:vanish val="false">) - assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr/w:tc/w:p[7]/w:r/w:rPr/w:vanish", 0); - else - // This was hidden (<w:vanish/>) - assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr/w:tc/w:p[7]/w:r/w:rPr/w:vanish", "val", - u"false"); + // This was hidden (<w:vanish/>) + assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr/w:tc/w:p[7]/w:r/w:rPr/w:vanish", "val", + u"false"); // pre-emptive unit test - tdf#162211 // given a compat12 file with wrap-through DML shape anchored in cell as layoutInCell @@ -250,12 +246,8 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf119800) xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:pPr/w:rPr/w:vanish", 1); - if (!isExported()) - // originally no <w:vanish> (the same as <w:vanish val="false">) - assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r/w:rPr/w:vanish", 0); - else - // This was hidden (<w:vanish/>) - assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r/w:rPr/w:vanish", "val", u"false"); + // This was hidden (<w:vanish/>) + assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r/w:rPr/w:vanish", "val", u"false"); } CPPUNIT_TEST_FIXTURE(Test, testTdf131728) @@ -655,40 +647,43 @@ CPPUNIT_TEST_FIXTURE(Test, testSectionProtection2) getProperty<bool>(xSect, u"IsProtected"_ustr)); } -DECLARE_OOXMLEXPORT_TEST(tdf66398_permissions, "tdf66398_permissions.docx") -{ - // check document permission settings for the whole document - if (isExported()) - { - xmlDocUniquePtr pXmlSettings = parseExport(u"word/settings.xml"_ustr); - assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "edit", u"readOnly"); - assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "enforcement", u"1"); - assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "cryptProviderType", - u"rsaAES"); - assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "cryptAlgorithmClass", - u"hash"); - assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "cryptAlgorithmType", - u"typeAny"); - assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "cryptAlgorithmSid", u"14"); - assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "cryptSpinCount", u"100000"); - assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "hash", - u"A0/" - "Xy6KcXljJlZjP0TwJMPJuW2rc46UwXqn2ctxckc2nCECE5i89M85z2Noh3ZEA5NBQ9RJ5ycxiUH6nz" - "mJaKw=="); - assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "salt", - u"B8k6wb1pkjUs4Nv/8QBk/w=="); - } - - // get bookmark interface - uno::Reference<text::XBookmarksSupplier> xBookmarksSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XIndexAccess> xBookmarksByIdx(xBookmarksSupplier->getBookmarks(), - uno::UNO_QUERY); - uno::Reference<container::XNameAccess> xBookmarksByName = xBookmarksSupplier->getBookmarks(); +CPPUNIT_TEST_FIXTURE(Test, tdf66398_permissions) +{ + auto verify = [this]() { + // get bookmark interface + uno::Reference<text::XBookmarksSupplier> xBookmarksSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xBookmarksByIdx(xBookmarksSupplier->getBookmarks(), + uno::UNO_QUERY); + uno::Reference<container::XNameAccess> xBookmarksByName + = xBookmarksSupplier->getBookmarks(); + + // check: we have 2 bookmarks + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xBookmarksByIdx->getCount()); + CPPUNIT_ASSERT(xBookmarksByName->hasByName(u"_GoBack"_ustr)); + CPPUNIT_ASSERT( + xBookmarksByName->hasByName(u"permission-for-group:267014232:everyone"_ustr)); + }; + + createSwDoc("tdf66398_permissions.docx"); + verify(); + saveAndReload(mpFilter); + verify(); - // check: we have 2 bookmarks - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xBookmarksByIdx->getCount()); - CPPUNIT_ASSERT(xBookmarksByName->hasByName(u"_GoBack"_ustr)); - CPPUNIT_ASSERT(xBookmarksByName->hasByName(u"permission-for-group:267014232:everyone"_ustr)); + // check document permission settings for the whole document + xmlDocUniquePtr pXmlSettings = parseExport(u"word/settings.xml"_ustr); + assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "edit", u"readOnly"); + assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "enforcement", u"1"); + assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "cryptProviderType", u"rsaAES"); + assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "cryptAlgorithmClass", u"hash"); + assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "cryptAlgorithmType", u"typeAny"); + assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "cryptAlgorithmSid", u"14"); + assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "cryptSpinCount", u"100000"); + assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "hash", + u"A0/" + "Xy6KcXljJlZjP0TwJMPJuW2rc46UwXqn2ctxckc2nCECE5i89M85z2Noh3ZEA5NBQ9RJ5ycxiUH6nz" + "mJaKw=="); + assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "salt", + u"B8k6wb1pkjUs4Nv/8QBk/w=="); } CPPUNIT_TEST_FIXTURE(Test, tdf106843) diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx index f2f33283de95..b40ec3abc74d 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx @@ -365,81 +365,94 @@ DECLARE_OOXMLEXPORT_TEST(testTdf125469_singleSpacing, "tdf125469_singleSpacing.d CPPUNIT_ASSERT_EQUAL(1, getPages()); } -DECLARE_OOXMLEXPORT_TEST(testTdf43767_caseMapNumbering, "tdf43767_caseMapNumbering.odt") +CPPUNIT_TEST_FIXTURE(Test, testTdf43767_caseMapNumbering) { - // given a document with 2 numbered Lists [each entry restarts numbering for visual comparison] - xmlDocUniquePtr pDump = parseLayoutDump(); - - // using the relative width difference between "A)" and "a)" as the test comparison - // since ListLabelString etc. does not output the actual string that is displayed on the screen - - // When the entire paragraph has a certain character attribute, that property is also applied - // to the list numbering itself (with some differing exceptions) for both ODT and DOCX. - - // ESTABLISH A BASELINE: these baseline paragraphs have no special character attributes. - // Paragraph 1/list 1(uppercase): no formatting applied to list numbering. Width is 253 for me - const sal_Int32 nUpperCaseWidth - = getXPath(pDump, "//body/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion", "width") - .toInt32(); - // Paragraph 4/list 2(lowercase): no formatting applied to list numbering. Width is 186 for me. - const sal_Int32 nLowerCaseWidth - = getXPath(pDump, "//body/txt[5]/SwParaPortion/SwLineLayout/SwFieldPortion", "width") - .toInt32(); - - // UPPERCASE LIST - // Paragraph 2: ODF should honour "lowercase". MSO doesn't know about lowercase - sal_Int32 nWidth - = getXPath(pDump, "//body/txt[2]/SwParaPortion/SwLineLayout/SwFieldPortion", "width") - .toInt32(); - CPPUNIT_ASSERT_EQUAL(isExported() ? nUpperCaseWidth : nLowerCaseWidth, nWidth); - - // Paragraph 3: ODF should honour "superscript" (for consistency). MSO ignores superscript - nWidth = getXPath(pDump, "//body/txt[3]/SwParaPortion/SwLineLayout/SwFieldPortion", "width") - .toInt32(); - if (!isExported()) - CPPUNIT_ASSERT_LESS(nLowerCaseWidth, nWidth); - else + auto verify = [this](bool bIsExport = false) { + // given a document with 2 numbered Lists [each entry restarts numbering for visual comparison] + xmlDocUniquePtr pDump = parseLayoutDump(); + + // using the relative width difference between "A)" and "a)" as the test comparison + // since ListLabelString etc. does not output the actual string that is displayed on the screen + + // When the entire paragraph has a certain character attribute, that property is also applied + // to the list numbering itself (with some differing exceptions) for both ODT and DOCX. + + // ESTABLISH A BASELINE: these baseline paragraphs have no special character attributes. + // Paragraph 1/list 1(uppercase): no formatting applied to list numbering. Width is 253 for me + const sal_Int32 nUpperCaseWidth + = getXPath(pDump, "//body/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion", "width") + .toInt32(); + // Paragraph 4/list 2(lowercase): no formatting applied to list numbering. Width is 186 for me. + const sal_Int32 nLowerCaseWidth + = getXPath(pDump, "//body/txt[5]/SwParaPortion/SwLineLayout/SwFieldPortion", "width") + .toInt32(); + + // UPPERCASE LIST + // Paragraph 2: ODF should honour "lowercase". MSO doesn't know about lowercase + sal_Int32 nWidth + = getXPath(pDump, "//body/txt[2]/SwParaPortion/SwLineLayout/SwFieldPortion", "width") + .toInt32(); + CPPUNIT_ASSERT_EQUAL(bIsExport ? nUpperCaseWidth : nLowerCaseWidth, nWidth); + + // Paragraph 3: ODF should honour "superscript" (for consistency). MSO ignores superscript + nWidth = getXPath(pDump, "//body/txt[3]/SwParaPortion/SwLineLayout/SwFieldPortion", "width") + .toInt32(); + if (!bIsExport) + CPPUNIT_ASSERT_LESS(nLowerCaseWidth, nWidth); + else + CPPUNIT_ASSERT_EQUAL(nUpperCaseWidth, nWidth); + + // LOWERCASE LIST + //Paragraph 6: ODF should honour "titlecase". MSO doesn't know about titlecase + nWidth = getXPath(pDump, "//body/txt[6]/SwParaPortion/SwLineLayout/SwFieldPortion", "width") + .toInt32(); + CPPUNIT_ASSERT_EQUAL(bIsExport ? nLowerCaseWidth : nUpperCaseWidth, nWidth); + + // Paragraph 7: ODF should honour "smallcaps". MSO apparently has an exception for small caps + nWidth = getXPath(pDump, "//body/txt[7]/SwParaPortion/SwLineLayout/SwFieldPortion", "width") + .toInt32(); + if (!bIsExport) + { + CPPUNIT_ASSERT_GREATER(nLowerCaseWidth, nWidth); + CPPUNIT_ASSERT_LESS(nUpperCaseWidth, nWidth); + } + else + CPPUNIT_ASSERT_EQUAL(nLowerCaseWidth, nWidth); + + // Paragraph 8: ODF should honour "uppercase". MSO also honours uppercase + nWidth = getXPath(pDump, "//body/txt[8]/SwParaPortion/SwLineLayout/SwFieldPortion", "width") + .toInt32(); CPPUNIT_ASSERT_EQUAL(nUpperCaseWidth, nWidth); + }; - // LOWERCASE LIST - //Paragraph 6: ODF should honour "titlecase". MSO doesn't know about titlecase - nWidth = getXPath(pDump, "//body/txt[6]/SwParaPortion/SwLineLayout/SwFieldPortion", "width") - .toInt32(); - CPPUNIT_ASSERT_EQUAL(isExported() ? nLowerCaseWidth : nUpperCaseWidth, nWidth); - - // Paragraph 7: ODF should honour "smallcaps". MSO apparently has an exception for small caps - nWidth = getXPath(pDump, "//body/txt[7]/SwParaPortion/SwLineLayout/SwFieldPortion", "width") - .toInt32(); - if (!isExported()) - { - CPPUNIT_ASSERT_GREATER(nLowerCaseWidth, nWidth); - CPPUNIT_ASSERT_LESS(nUpperCaseWidth, nWidth); - } - else - CPPUNIT_ASSERT_EQUAL(nLowerCaseWidth, nWidth); - - // Paragraph 8: ODF should honour "uppercase". MSO also honours uppercase - nWidth = getXPath(pDump, "//body/txt[8]/SwParaPortion/SwLineLayout/SwFieldPortion", "width") - .toInt32(); - CPPUNIT_ASSERT_EQUAL(nUpperCaseWidth, nWidth); + createSwDoc("tdf43767_caseMapNumbering.odt"); + verify(); + saveAndReload(mpFilter); + verify(/*bIsExport*/ true); } -DECLARE_OOXMLEXPORT_TEST(testTdf156105_percentSuffix, "tdf156105_percentSuffix.odt") +CPPUNIT_TEST_FIXTURE(Test, testTdf156105_percentSuffix) { - // given a numbered list with a non-escaping percent symbol in the prefix and suffix - CPPUNIT_ASSERT_EQUAL(u"(%)[%]"_ustr, - getProperty<OUString>(getParagraph(3), u"ListLabelString"_ustr)); - - // tdf#149258 - NONE number should not export separator since LO doesn't currently show it - CPPUNIT_ASSERT_EQUAL_MESSAGE("showing levels 1, 2, and 4", u"(%)1.1.1[%]"_ustr, - getProperty<OUString>(getParagraph(4), u"ListLabelString"_ustr)); - if (isExported()) - { - xmlDocUniquePtr pXmlNum = parseExport(u"word/numbering.xml"_ustr); - // The 3rd level is NONE. If we include the separator, MS Word will display it. - assertXPath(pXmlNum, "/w:numbering/w:abstractNum[1]/w:lvl[4]/w:lvlText", "val", - u"(%)%1.%2.%3%4[%]"); - } + auto verify = [this]() { + // given a numbered list with a non-escaping percent symbol in the prefix and suffix + CPPUNIT_ASSERT_EQUAL(u"(%)[%]"_ustr, + getProperty<OUString>(getParagraph(3), u"ListLabelString"_ustr)); + + // tdf#149258 - NONE number should not export separator since LO doesn't currently show it + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "showing levels 1, 2, and 4", u"(%)1.1.1[%]"_ustr, + getProperty<OUString>(getParagraph(4), u"ListLabelString"_ustr)); + }; + + createSwDoc("tdf156105_percentSuffix.odt"); + verify(); + saveAndReload(mpFilter); + verify(); + + xmlDocUniquePtr pXmlNum = parseExport(u"word/numbering.xml"_ustr); + // The 3rd level is NONE. If we include the separator, MS Word will display it. + assertXPath(pXmlNum, "/w:numbering/w:abstractNum[1]/w:lvl[4]/w:lvlText", "val", + u"(%)%1.%2.%3%4[%]"); } DECLARE_OOXMLEXPORT_TEST(testTdf160049_anchorMarginVML, "tdf160049_anchorMarginVML.docx") @@ -797,16 +810,20 @@ DECLARE_OOXMLEXPORT_TEST(testTdf126533_pageGradient, "fill.docx") CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_RECT, aGradient.Style); } -DECLARE_OOXMLEXPORT_TEST(testTdf126533_pageBitmap, "tdf126533_pageBitmap.docx") +CPPUNIT_TEST_FIXTURE(Test, testTdf126533_pageBitmap) { - // given a document with a page background image - uno::Reference<beans::XPropertySet> xPageStyle( - getStyles(u"PageStyles"_ustr)->getByName(u"Standard"_ustr), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_BITMAP, - getProperty<drawing::FillStyle>(xPageStyle, u"FillStyle"_ustr)); + auto verify = [this]() { + // given a document with a page background image + uno::Reference<beans::XPropertySet> xPageStyle( + getStyles(u"PageStyles"_ustr)->getByName(u"Standard"_ustr), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_BITMAP, + getProperty<drawing::FillStyle>(xPageStyle, u"FillStyle"_ustr)); + }; - if (!isExported()) - return; + createSwDoc("tdf126533_pageBitmap.docx"); + verify(); + saveAndReload(mpFilter); + verify(); xmlDocUniquePtr pXmlDocRels = parseExport(u"word/_rels/document.xml.rels"_ustr); assertXPath(pXmlDocRels, "/rels:Relationships/rels:Relationship[@Target='media/image1.jpeg']", diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx index 943b7442eb8b..ad48595f8b6f 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx @@ -100,19 +100,17 @@ CPPUNIT_TEST_FIXTURE(Test, testDefaultContentTypes) u"image/jpeg"); } -DECLARE_SW_ROUNDTRIP_TEST(testDocmSave, "hello.docm", nullptr, DocmTest) +CPPUNIT_TEST_FIXTURE(DocmTest, testDocmSave) { // This was // application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml, // we used the wrong content type for .docm files. - if (isExported()) - { - xmlDocUniquePtr pXmlDoc = parseExport(u"[Content_Types].xml"_ustr); - assertXPath(pXmlDoc, - "/ContentType:Types/ContentType:Override[@PartName='/word/document.xml']", - "ContentType", - u"application/vnd.ms-word.document.macroEnabled.main+xml"); - } + loadAndSave("hello.docm"); + xmlDocUniquePtr pXmlDoc = parseExport(u"[Content_Types].xml"_ustr); + assertXPath(pXmlDoc, + "/ContentType:Types/ContentType:Override[@PartName='/word/document.xml']", + "ContentType", + u"application/vnd.ms-word.document.macroEnabled.main+xml"); } DECLARE_SW_ROUNDTRIP_TEST(testBadDocm, "bad.docm", nullptr, DocmTest) @@ -439,14 +437,19 @@ DECLARE_OOXMLEXPORT_TEST(testTdf106970, "tdf106970.docx") CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(494), getProperty<sal_Int32>(getParagraph(4), u"ParaBottomMargin"_ustr)); } -DECLARE_OOXMLEXPORT_TEST(testTdf79272_strictDxa, "tdf79272_strictDxa.docx") +CPPUNIT_TEST_FIXTURE(Test, testTdf79272_strictDxa) { - uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(sal_Int32(4318), getProperty<sal_Int32>(xTables->getByIndex(0), u"Width"_ustr)); + auto verify = [this]() { + uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(4318), getProperty<sal_Int32>(xTables->getByIndex(0), u"Width"_ustr)); + }; + + createSwDoc("tdf79272_strictDxa.docx"); + verify(); + saveAndReload(mpFilter); + verify(); - if (!isExported()) - return; xmlDocUniquePtr pXmlDoc = parseExport(u"word/styles.xml"_ustr); // Validation test: order of elements was wrong. Order was: insideH, end, insideV. int nEnd = getXPathPosition(pXmlDoc, "/w:styles/w:style[@w:styleId='TableGrid']/w:tblPr/w:tblBorders", "end"); @@ -511,35 +514,42 @@ DECLARE_OOXMLEXPORT_TEST(tdf105490_negativeMargins, "tdf105490_negativeMargins.d } #endif -DECLARE_OOXMLEXPORT_TEST(testTdf97648_relativeWidth, "tdf97648_relativeWidth.docx") +CPPUNIT_TEST_FIXTURE(Test, testTdf97648_relativeWidth) { - CPPUNIT_ASSERT_DOUBLES_EQUAL( sal_Int32(7616), getShape(1)->getSize().Width, 10); - CPPUNIT_ASSERT_DOUBLES_EQUAL( sal_Int32(8001), getShape(2)->getSize().Width, 10); - CPPUNIT_ASSERT_DOUBLES_EQUAL( sal_Int32(4001), getShape(3)->getSize().Width, 10); - CPPUNIT_ASSERT_EQUAL( style::ParagraphAdjust_LEFT, static_cast<style::ParagraphAdjust>(getProperty<sal_Int16>(getParagraph(6), u"ParaAdjust"_ustr)) ); - CPPUNIT_ASSERT_DOUBLES_EQUAL( sal_Int32(1600), getShape(4)->getSize().Width, 10); - CPPUNIT_ASSERT_EQUAL( style::ParagraphAdjust_RIGHT, static_cast<style::ParagraphAdjust>(getProperty<sal_Int16>(getParagraph(8), u"ParaAdjust"_ustr)) ); + auto verify = [this](bool bIsExport = false) { + CPPUNIT_ASSERT_DOUBLES_EQUAL( sal_Int32(7616), getShape(1)->getSize().Width, 10); + CPPUNIT_ASSERT_DOUBLES_EQUAL( sal_Int32(8001), getShape(2)->getSize().Width, 10); + CPPUNIT_ASSERT_DOUBLES_EQUAL( sal_Int32(4001), getShape(3)->getSize().Width, 10); + CPPUNIT_ASSERT_EQUAL( style::ParagraphAdjust_LEFT, static_cast<style::ParagraphAdjust>(getProperty<sal_Int16>(getParagraph(6), u"ParaAdjust"_ustr)) ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( sal_Int32(1600), getShape(4)->getSize().Width, 10); + CPPUNIT_ASSERT_EQUAL( style::ParagraphAdjust_RIGHT, static_cast<style::ParagraphAdjust>(getProperty<sal_Int16>(getParagraph(8), u"ParaAdjust"_ustr)) ); - CPPUNIT_ASSERT_EQUAL( sal_Int32(0), getProperty<sal_Int32>(getShape(1), u"LeftMargin"_ustr) ); - if (!isExported()) - { - CPPUNIT_ASSERT_EQUAL_MESSAGE("Text should wrap above/below the line", text::WrapTextMode_NONE, getProperty<text::WrapTextMode>(getShape(1), u"Surround"_ustr)); - CPPUNIT_ASSERT_EQUAL(text::HoriOrientation::CENTER, getProperty<sal_Int16>(getShape(2), u"HoriOrient"_ustr)); - CPPUNIT_ASSERT_EQUAL(text::HoriOrientation::RIGHT, getProperty<sal_Int16>(getShape(3), u"HoriOrient"_ustr)); - CPPUNIT_ASSERT_EQUAL(text::HoriOrientation::LEFT, getProperty<sal_Int16>(getShape(4), u"HoriOrient"_ustr)); - } + CPPUNIT_ASSERT_EQUAL( sal_Int32(0), getProperty<sal_Int32>(getShape(1), u"LeftMargin"_ustr) ); + if (!bIsExport) + { + CPPUNIT_ASSERT_EQUAL_MESSAGE("Text should wrap above/below the line", text::WrapTextMode_NONE, getProperty<text::WrapTextMode>(getShape(1), u"Surround"_ustr)); + CPPUNIT_ASSERT_EQUAL(text::HoriOrientation::CENTER, getProperty<sal_Int16>(getShape(2), u"HoriOrient"_ustr)); + CPPUNIT_ASSERT_EQUAL(text::HoriOrientation::RIGHT, getProperty<sal_Int16>(getShape(3), u"HoriOrient"_ustr)); + CPPUNIT_ASSERT_EQUAL(text::HoriOrientation::LEFT, getProperty<sal_Int16>(getShape(4), u"HoriOrient"_ustr)); + } - uno::Reference<text::XTextSectionsSupplier> xTextSectionsSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XIndexAccess> xSections(xTextSectionsSupplier->getTextSections(), - uno::UNO_QUERY); + uno::Reference<text::XTextSectionsSupplier> xTextSectionsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xSections(xTextSectionsSupplier->getTextSections(), + uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xSections->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xSections->getCount()); - uno::Reference<beans::XPropertySet> xTextSection(xSections->getByIndex(2), uno::UNO_QUERY); - uno::Reference<text::XTextColumns> xTextColumns - = getProperty<uno::Reference<text::XTextColumns>>(xTextSection, u"TextColumns"_ustr); - CPPUNIT_ASSERT_EQUAL(sal_Int16(2), xTextColumns->getColumnCount()); + uno::Reference<beans::XPropertySet> xTextSection(xSections->getByIndex(2), uno::UNO_QUERY); + uno::Reference<text::XTextColumns> xTextColumns + = getProperty<uno::Reference<text::XTextColumns>>(xTextSection, u"TextColumns"_ustr); + CPPUNIT_ASSERT_EQUAL(sal_Int16(2), xTextColumns->getColumnCount()); + }; + + createSwDoc("tdf97648_relativeWidth.docx"); + verify(); + saveAndReload(mpFilter); + verify(/*bIsExport*/ true); } DECLARE_OOXMLEXPORT_TEST(testTdf144362, "tdf144362.odt") @@ -888,61 +898,66 @@ DECLARE_OOXMLEXPORT_TEST(testTdf82173_endnoteStyle, "tdf82173_endnoteStyle.docx" CPPUNIT_TEST_FIXTURE(Test, testTdf55427_footnote2endnote) { - loadAndReload("tdf55427_footnote2endnote.odt"); - CPPUNIT_ASSERT_EQUAL(4, getPages()); - uno::Reference<beans::XPropertySet> xPageStyle(getStyles(u"ParagraphStyles"_ustr)->getByName(u"Footnote"_ustr), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL_MESSAGE( "Footnote style is rose color", Color(0xFF007F), getProperty<Color>(xPageStyle, u"CharColor"_ustr)); - xPageStyle.set(getStyles(u"ParagraphStyles"_ustr)->getByName(u"Endnote"_ustr), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL_MESSAGE( "Endnote style is cyan3 color", Color(0x2BD0D2), getProperty<Color>(xPageStyle, u"CharColor"_ustr)); - - SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); - CPPUNIT_ASSERT(pTextDoc); - SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc(); - // The footnote numbering type of ARABIC will not transfer over when those footnotes are converted to endnotes. - CPPUNIT_ASSERT_EQUAL_MESSAGE( "Footnote numbering type", SVX_NUM_ARABIC, pDoc->GetFootnoteInfo().m_aFormat.GetNumberingType() ); - // The original document has a real endnote using ROMAN_LOWER numbering, so that setting MUST remain unchanged. - CPPUNIT_ASSERT_EQUAL_MESSAGE( "Endnote numbering type", SVX_NUM_ROMAN_LOWER, pDoc->GetEndNoteInfo().m_aFormat.GetNumberingType() ); - - uno::Reference<text::XFootnotesSupplier> xFootnotesSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XIndexAccess> xFootnotes = xFootnotesSupplier->getFootnotes(); - - uno::Reference<text::XEndnotesSupplier> xEndnotesSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XIndexAccess> xEndnotes = xEndnotesSupplier->getEndnotes(); - uno::Reference<text::XFootnote> xEndnote; - xEndnotes->getByIndex(0) >>= xEndnote; - uno::Reference<text::XText> xEndnoteText; - xEndnotes->getByIndex(0) >>= xEndnoteText; - - // ODT footnote-at-document-end's closest DOCX match is an endnote, so the two imports will not exactly match by design. - if (!isExported()) - { - CPPUNIT_ASSERT_EQUAL_MESSAGE( "original footnote count", sal_Int32(5), xFootnotes->getCount() ); - CPPUNIT_ASSERT_EQUAL_MESSAGE( "original endnote count", sal_Int32(1), xEndnotes->getCount() ); - - uno::Reference<text::XFootnote> xFootnote; - xFootnotes->getByIndex(0) >>= xFootnote; - CPPUNIT_ASSERT_EQUAL_MESSAGE( "original footnote's number", u"1"_ustr, xFootnote->getAnchor()->getString() ); - CPPUNIT_ASSERT_EQUAL_MESSAGE( "original endnote's number", u"i"_ustr, xEndnote->getAnchor()->getString() ); - - uno::Reference<text::XText> xFootnoteText; - xFootnotes->getByIndex(0) >>= xFootnoteText; - CPPUNIT_ASSERT_EQUAL_MESSAGE( "original footnote style", u"Footnote"_ustr, getProperty<OUString>(getParagraphOfText(1, xFootnoteText), u"ParaStyleName"_ustr) ); - CPPUNIT_ASSERT_EQUAL_MESSAGE( "original endnote style", u"Endnote"_ustr, getProperty<OUString>(getParagraphOfText(1, xEndnoteText), u"ParaStyleName"_ustr) ); - } - else - { - // These asserted items are major differences in the conversion from footnote to endnote, NOT necessary conditions for a proper functioning document. - CPPUNIT_ASSERT_EQUAL_MESSAGE( "At-Document-End footnotes were converted into endnotes", sal_Int32(0), xFootnotes->getCount() ); - CPPUNIT_ASSERT_EQUAL_MESSAGE( "At-Document-End footnotes became endnotes", sal_Int32(6), xEndnotes->getCount() ); - - CPPUNIT_ASSERT_EQUAL_MESSAGE( "converted footnote's number", u"i"_ustr, xEndnote->getAnchor()->getString() ); - xEndnotes->getByIndex(4) >>= xEndnote; - CPPUNIT_ASSERT_EQUAL_MESSAGE( "original endnote's new number", u"v"_ustr, xEndnote->getAnchor()->getString() ); - - CPPUNIT_ASSERT_EQUAL_MESSAGE( "retained footnote style", u"Footnote"_ustr, getProperty<OUString>(getParagraphOfText(1, xEndnoteText), u"ParaStyleName"_ustr) ); - xEndnotes->getByIndex(4) >>= xEndnoteText; - CPPUNIT_ASSERT_EQUAL_MESSAGE( "original endnote style", u"Endnote"_ustr, getProperty<OUString>(getParagraphOfText(1, xEndnoteText), u"ParaStyleName"_ustr) ); - } + auto verify = [this](bool bIsExport = false) { + CPPUNIT_ASSERT_EQUAL(4, getPages()); + uno::Reference<beans::XPropertySet> xPageStyle(getStyles(u"ParagraphStyles"_ustr)->getByName(u"Footnote"_ustr), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Footnote style is rose color", Color(0xFF007F), getProperty<Color>(xPageStyle, u"CharColor"_ustr)); + xPageStyle.set(getStyles(u"ParagraphStyles"_ustr)->getByName(u"Endnote"_ustr), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Endnote style is cyan3 color", Color(0x2BD0D2), getProperty<Color>(xPageStyle, u"CharColor"_ustr)); + + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc(); + // The footnote numbering type of ARABIC will not transfer over when those footnotes are converted to endnotes. + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Footnote numbering type", SVX_NUM_ARABIC, pDoc->GetFootnoteInfo().m_aFormat.GetNumberingType() ); + // The original document has a real endnote using ROMAN_LOWER numbering, so that setting MUST remain unchanged. + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Endnote numbering type", SVX_NUM_ROMAN_LOWER, pDoc->GetEndNoteInfo().m_aFormat.GetNumberingType() ); + + uno::Reference<text::XFootnotesSupplier> xFootnotesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xFootnotes = xFootnotesSupplier->getFootnotes(); + + uno::Reference<text::XEndnotesSupplier> xEndnotesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xEndnotes = xEndnotesSupplier->getEndnotes(); + uno::Reference<text::XFootnote> xEndnote; + xEndnotes->getByIndex(0) >>= xEndnote; + uno::Reference<text::XText> xEndnoteText; + xEndnotes->getByIndex(0) >>= xEndnoteText; + + // ODT footnote-at-document-end's closest DOCX match is an endnote, so the two imports will not exactly match by design. + if (!bIsExport) + { + CPPUNIT_ASSERT_EQUAL_MESSAGE( "original footnote count", sal_Int32(5), xFootnotes->getCount() ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "original endnote count", sal_Int32(1), xEndnotes->getCount() ); + + uno::Reference<text::XFootnote> xFootnote; + xFootnotes->getByIndex(0) >>= xFootnote; + CPPUNIT_ASSERT_EQUAL_MESSAGE( "original footnote's number", u"1"_ustr, xFootnote->getAnchor()->getString() ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "original endnote's number", u"i"_ustr, xEndnote->getAnchor()->getString() ); + + uno::Reference<text::XText> xFootnoteText; + xFootnotes->getByIndex(0) >>= xFootnoteText; + CPPUNIT_ASSERT_EQUAL_MESSAGE( "original footnote style", u"Footnote"_ustr, getProperty<OUString>(getParagraphOfText(1, xFootnoteText), u"ParaStyleName"_ustr) ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "original endnote style", u"Endnote"_ustr, getProperty<OUString>(getParagraphOfText(1, xEndnoteText), u"ParaStyleName"_ustr) ); + } + else + { + // These asserted items are major differences in the conversion from footnote to endnote, NOT necessary conditions for a proper functioning document. + CPPUNIT_ASSERT_EQUAL_MESSAGE( "At-Document-End footnotes were converted into endnotes", sal_Int32(0), xFootnotes->getCount() ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "At-Document-End footnotes became endnotes", sal_Int32(6), xEndnotes->getCount() ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE( "converted footnote's number", u"i"_ustr, xEndnote->getAnchor()->getString() ); + xEndnotes->getByIndex(4) >>= xEndnote; + CPPUNIT_ASSERT_EQUAL_MESSAGE( "original endnote's new number", u"v"_ustr, xEndnote->getAnchor()->getString() ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE( "retained footnote style", u"Footnote"_ustr, getProperty<OUString>(getParagraphOfText(1, xEndnoteText), u"ParaStyleName"_ustr) ); + xEndnotes->getByIndex(4) >>= xEndnoteText; + CPPUNIT_ASSERT_EQUAL_MESSAGE( "original endnote style", u"Endnote"_ustr, getProperty<OUString>(getParagraphOfText(1, xEndnoteText), u"ParaStyleName"_ustr) ); + } + }; + createSwDoc("tdf55427_footnote2endnote.odt"); + verify(); + saveAndReload(mpFilter); + verify(/*bIsExport*/ true); } DECLARE_OOXMLEXPORT_TEST(testTdf104162, "tdf104162.docx") diff --git a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx index be712f80290f..3c21e915c4f1 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx @@ -555,51 +555,58 @@ CPPUNIT_TEST_FIXTURE(Test, testTableStart2Sdt) assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:text/w:docPartGallery", 0); } -DECLARE_OOXMLEXPORT_TEST(testSdtDateDuplicate, "sdt-date-duplicate.docx") -{ - if (isExported()) - { - xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); - // Single <w:sdt> was exported as 2 <w:sdt> elements. - assertXPath(pXmlDoc, "//w:sdt", 1); - uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), uno::UNO_QUERY); - uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY); - uno::Reference<table::XCell> xCell = xTable->getCellByName(u"A1"_ustr); - uno::Reference<container::XEnumerationAccess> xParagraphsAccess(xCell, uno::UNO_QUERY); - uno::Reference<container::XEnumeration> xParagraphs = xParagraphsAccess->createEnumeration(); - uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphs->nextElement(), - uno::UNO_QUERY); - uno::Reference<container::XEnumeration> xPortions = xParagraph->createEnumeration(); - uno::Reference<beans::XPropertySet> xTextPortion(xPortions->nextElement(), uno::UNO_QUERY); - OUString aPortionType; - xTextPortion->getPropertyValue(u"TextPortionType"_ustr) >>= aPortionType; - CPPUNIT_ASSERT_EQUAL(u"ContentControl"_ustr, aPortionType); - uno::Reference<text::XTextContent> xContentControl; - xTextPortion->getPropertyValue(u"ContentControl"_ustr) >>= xContentControl; - uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY); - bool bDate{}; - xContentControlProps->getPropertyValue(u"Date"_ustr) >>= bDate; - CPPUNIT_ASSERT(bDate); - uno::Reference<container::XEnumerationAccess> xContentControlEnumAccess(xContentControl, uno::UNO_QUERY); - uno::Reference<container::XEnumeration> xContentControlEnum = xContentControlEnumAccess->createEnumeration(); - uno::Reference<text::XTextRange> xTextPortionRange(xContentControlEnum->nextElement(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(u"4/26/2012"_ustr, xTextPortionRange->getString()); - } - else - { - SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get()); - CPPUNIT_ASSERT(pTextDoc); - SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc(); - IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess(); - CPPUNIT_ASSERT_EQUAL(sal_Int32(2), pMarkAccess->getAllMarksCount()); - - ::sw::mark::DateFieldmark* pFieldmark - = dynamic_cast<::sw::mark::DateFieldmark*>(*pMarkAccess->getAllMarksBegin()); - CPPUNIT_ASSERT(pFieldmark); - CPPUNIT_ASSERT_EQUAL(ODF_FORMDATE, pFieldmark->GetFieldname()); - CPPUNIT_ASSERT_EQUAL(u"4/26/2012"_ustr, pFieldmark->GetContent()); - } +CPPUNIT_TEST_FIXTURE(Test, testSdtDateDuplicate) +{ + auto verify = [this](bool bIsExport = false) { + if (bIsExport) + { + xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); + // Single <w:sdt> was exported as 2 <w:sdt> elements. + assertXPath(pXmlDoc, "//w:sdt", 1); + uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), uno::UNO_QUERY); + uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY); + uno::Reference<table::XCell> xCell = xTable->getCellByName(u"A1"_ustr); + uno::Reference<container::XEnumerationAccess> xParagraphsAccess(xCell, uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xParagraphs = xParagraphsAccess->createEnumeration(); + uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphs->nextElement(), + uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xPortions = xParagraph->createEnumeration(); + uno::Reference<beans::XPropertySet> xTextPortion(xPortions->nextElement(), uno::UNO_QUERY); + OUString aPortionType; + xTextPortion->getPropertyValue(u"TextPortionType"_ustr) >>= aPortionType; + CPPUNIT_ASSERT_EQUAL(u"ContentControl"_ustr, aPortionType); + uno::Reference<text::XTextContent> xContentControl; + xTextPortion->getPropertyValue(u"ContentControl"_ustr) >>= xContentControl; + uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY); + bool bDate{}; + xContentControlProps->getPropertyValue(u"Date"_ustr) >>= bDate; + CPPUNIT_ASSERT(bDate); + uno::Reference<container::XEnumerationAccess> xContentControlEnumAccess(xContentControl, uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xContentControlEnum = xContentControlEnumAccess->createEnumeration(); + uno::Reference<text::XTextRange> xTextPortionRange(xContentControlEnum->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(u"4/26/2012"_ustr, xTextPortionRange->getString()); + } + else + { + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc(); + IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), pMarkAccess->getAllMarksCount()); + + ::sw::mark::DateFieldmark* pFieldmark + = dynamic_cast<::sw::mark::DateFieldmark*>(*pMarkAccess->getAllMarksBegin()); + CPPUNIT_ASSERT(pFieldmark); + CPPUNIT_ASSERT_EQUAL(ODF_FORMDATE, pFieldmark->GetFieldname()); + CPPUNIT_ASSERT_EQUAL(u"4/26/2012"_ustr, pFieldmark->GetContent()); + } + }; + + createSwDoc("sdt-date-duplicate.docx"); + verify(); + saveAndReload(mpFilter); + verify(/*bIsExport*/ true); } CPPUNIT_TEST_FIXTURE(Test, testFdo81492) @@ -702,27 +709,31 @@ CPPUNIT_TEST_FIXTURE(Test, testSdtCompanyMultipara) assertXPath(pXmlDoc, "//w:sdtContent/w:r", 2); } -DECLARE_OOXMLEXPORT_TEST(testFixedDateFields, "fixed-date-field.docx") +CPPUNIT_TEST_FIXTURE(Test, testFixedDateFields) { - uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); - uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); - uno::Reference<beans::XPropertySet> xField(xFields->nextElement(), uno::UNO_QUERY); + auto verify = [this]() { + uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); + uno::Reference<beans::XPropertySet> xField(xFields->nextElement(), uno::UNO_QUERY); + + // Check fixed property was imported and date value was parsed correctly + CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xField, u"IsFixed"_ustr)); + css::util::DateTime date = getProperty<css::util::DateTime>(xField, u"DateTimeValue"_ustr); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(24), date.Day); + CPPUNIT_ASSERT_EQUAL(sal_uInt16(7), date.Month); + CPPUNIT_ASSERT_EQUAL(sal_Int16(2014), date.Year); + }; - // Check fixed property was imported and date value was parsed correctly - CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xField, u"IsFixed"_ustr)); - css::util::DateTime date = getProperty<css::util::DateTime>(xField, u"DateTimeValue"_ustr); - CPPUNIT_ASSERT_EQUAL(sal_uInt16(24), date.Day); - CPPUNIT_ASSERT_EQUAL(sal_uInt16(7), date.Month); - CPPUNIT_ASSERT_EQUAL(sal_Int16(2014), date.Year); + createSwDoc("fixed-date-field.docx"); + verify(); + saveAndReload(mpFilter); + verify(); - if (isExported()) - { - xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); - // Previously, fixed fields were exported as static text ("Date (fixed)") - // Check they are now exported correctly as fldChar with fldLock attribute - assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r[1]/w:fldChar", "fldLock", u"true"); - } + xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); + // Previously, fixed fields were exported as static text ("Date (fixed)") + // Check they are now exported correctly as fldChar with fldLock attribute + assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r[1]/w:fldChar", "fldLock", u"true"); } CPPUNIT_TEST_FIXTURE(Test, testToxmarkHyperlink) @@ -765,107 +776,127 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf66401) assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[9]/w:rPr/w:sz", "val", u"24"); } -DECLARE_OOXMLEXPORT_TEST( testDateFieldInShape, "date_field_in_shape.docx" ) +CPPUNIT_TEST_FIXTURE(Test, testDateFieldInShape) { + auto verify = [this](bool bIsExport = false) { // This was crashed on export. - if (isExported()) - { - uno::Reference<text::XTextRange> xShape(getShape(1), uno::UNO_QUERY); - uno::Reference<text::XText> xShapeText = xShape->getText(); - uno::Reference<beans::XPropertySet> xTextPortion(getRun(getParagraphOfText(1, xShapeText), 1), uno::UNO_QUERY); - OUString aPortionType; - xTextPortion->getPropertyValue(u"TextPortionType"_ustr) >>= aPortionType; - CPPUNIT_ASSERT_EQUAL(u"ContentControl"_ustr, aPortionType); - uno::Reference<text::XTextContent> xContentControl; - xTextPortion->getPropertyValue(u"ContentControl"_ustr) >>= xContentControl; - uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY); - bool bDate{}; - xContentControlProps->getPropertyValue(u"Date"_ustr) >>= bDate; - CPPUNIT_ASSERT(bDate); - uno::Reference<container::XEnumerationAccess> xContentControlEnumAccess(xContentControl, uno::UNO_QUERY); - uno::Reference<container::XEnumeration> xContentControlEnum = xContentControlEnumAccess->createEnumeration(); - uno::Reference<text::XTextRange> xTextPortionRange(xContentControlEnum->nextElement(), uno::UNO_QUERY); - CPPUNIT_ASSERT_EQUAL(u"Click here to enter a date."_ustr, xTextPortionRange->getString()); - } - else - { - SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get()); - CPPUNIT_ASSERT(pTextDoc); - SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc(); - IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess(); - CPPUNIT_ASSERT_EQUAL(sal_Int32(2), pMarkAccess->getAllMarksCount()); + if (bIsExport) + { + uno::Reference<text::XTextRange> xShape(getShape(1), uno::UNO_QUERY); + uno::Reference<text::XText> xShapeText = xShape->getText(); + uno::Reference<beans::XPropertySet> xTextPortion(getRun(getParagraphOfText(1, xShapeText), 1), uno::UNO_QUERY); + OUString aPortionType; + xTextPortion->getPropertyValue(u"TextPortionType"_ustr) >>= aPortionType; + CPPUNIT_ASSERT_EQUAL(u"ContentControl"_ustr, aPortionType); + uno::Reference<text::XTextContent> xContentControl; + xTextPortion->getPropertyValue(u"ContentControl"_ustr) >>= xContentControl; + uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY); + bool bDate{}; + xContentControlProps->getPropertyValue(u"Date"_ustr) >>= bDate; + CPPUNIT_ASSERT(bDate); + uno::Reference<container::XEnumerationAccess> xContentControlEnumAccess(xContentControl, uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xContentControlEnum = xContentControlEnumAccess->createEnumeration(); + uno::Reference<text::XTextRange> xTextPortionRange(xContentControlEnum->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(u"Click here to enter a date."_ustr, xTextPortionRange->getString()); + } + else + { + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc(); + IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), pMarkAccess->getAllMarksCount()); + + ::sw::mark::DateFieldmark* pFieldmark + = dynamic_cast<::sw::mark::DateFieldmark*>(*pMarkAccess->getAllMarksBegin()); + CPPUNIT_ASSERT(pFieldmark); + CPPUNIT_ASSERT_EQUAL(ODF_FORMDATE, pFieldmark->GetFieldname()); + CPPUNIT_ASSERT_EQUAL(u"Click here to enter a date."_ustr, pFieldmark->GetContent()); + } + }; + + createSwDoc("date_field_in_shape.docx"); + verify(); + saveAndReload(mpFilter); + verify(/*bIsExport*/ true); +} + +CPPUNIT_TEST_FIXTURE(Test, testDateFieldAtEndOfParagraph) +{ + auto verify = [this](bool bIsExport = false) { + // Additional line end was added by import and it was crashed on export + if (bIsExport) + { + uno::Reference<beans::XPropertySet> xTextPortion(getRun(getParagraph(2), 1), uno::UNO_QUERY); + OUString aPortionType; + xTextPortion->getPropertyValue(u"TextPortionType"_ustr) >>= aPortionType; + CPPUNIT_ASSERT_EQUAL(u"ContentControl"_ustr, aPortionType); + uno::Reference<text::XTextContent> xContentControl; + xTextPortion->getPropertyValue(u"ContentControl"_ustr) >>= xContentControl; + uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY); + bool bDate{}; + xContentControlProps->getPropertyValue(u"Date"_ustr) >>= bDate; + CPPUNIT_ASSERT(bDate); + uno::Reference<container::XEnumerationAccess> xContentControlEnumAccess(xContentControl, uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xContentControlEnum = xContentControlEnumAccess->createEnumeration(); + uno::Reference<text::XTextRange> xTextPortionRange(xContentControlEnum->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(u"Click here to enter a date."_ustr, xTextPortionRange->getString()); + } + else + { + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc(); + IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess(); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), pMarkAccess->getAllMarksCount()); + + ::sw::mark::DateFieldmark* pFieldmark + = dynamic_cast<::sw::mark::DateFieldmark*>(*pMarkAccess->getAllMarksBegin()); + CPPUNIT_ASSERT(pFieldmark); + CPPUNIT_ASSERT_EQUAL(ODF_FORMDATE, pFieldmark->GetFieldname()); + CPPUNIT_ASSERT_EQUAL(u"Click here to enter a date."_ustr, pFieldmark->GetContent()); + } + }; + + createSwDoc("date_field_at_end_of_paragraph.docx"); + verify(); + saveAndReload(mpFilter); + verify(/*bIsExport*/ true); +} + +CPPUNIT_TEST_FIXTURE(Test, testDropDownFieldEntryLimit) +{ + auto verify = [this](bool bIsExport = false) { + CPPUNIT_ASSERT_EQUAL(1, getPages()); + // In MSO, there is a limit of 25 for the items in a drop-down form field. -e ... etc. - the rest is truncated