From cf41b69356672dcedc4448661547c10dbe03f98a Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Tue, 9 Nov 2021 14:43:30 +0100 Subject: tdf#142033: sc_macros_test: Add unittest Change-Id: Id569c3f020c50a30f4c55fecdaa3f7849e1cbb47 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124917 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- sc/qa/extras/macros-test.cxx | 56 +++++++++++++++++++++++++++++++ sc/qa/extras/testdocuments/tdf142033.ods | Bin 0 -> 8833 bytes 2 files changed, 56 insertions(+) create mode 100644 sc/qa/extras/testdocuments/tdf142033.ods diff --git a/sc/qa/extras/macros-test.cxx b/sc/qa/extras/macros-test.cxx index f888deffd25e..5ef95b2018d7 100644 --- a/sc/qa/extras/macros-test.cxx +++ b/sc/qa/extras/macros-test.cxx @@ -51,6 +51,7 @@ public: void testTdf114427(); void testTdf107885(); void testRowColumn(); + void testTdf142033(); void testTdf131562(); void testPasswordProtectedUnicodeString(); void testPasswordProtectedArrayInUserType(); @@ -80,6 +81,7 @@ public: CPPUNIT_TEST(testTdf114427); CPPUNIT_TEST(testTdf107885); CPPUNIT_TEST(testRowColumn); + CPPUNIT_TEST(testTdf142033); CPPUNIT_TEST(testTdf131562); CPPUNIT_TEST(testPasswordProtectedUnicodeString); CPPUNIT_TEST(testPasswordProtectedArrayInUserType); @@ -520,6 +522,60 @@ void ScMacrosTest::testMacroButtonFormControlXlsxExport() assertXPath(pWorkbookDoc, "//x:workbook/definedNames", 0); } +void ScMacrosTest::testTdf142033() +{ + OUString aFileName; + createFileURL(u"tdf142033.ods", aFileName); + uno::Reference< css::lang::XComponent > xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + Any aRet; + Sequence< sal_Int16 > aOutParamIndex; + Sequence< Any > aOutParam; + Sequence< uno::Any > aParams; + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:Standard.Module1.display_bug?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + // Export to ODS + uno::Reference xStorable(xComponent, uno::UNO_QUERY); + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= OUString("calc8"); + auto pTempFile = std::make_shared(); + pTempFile->EnableKillingFile(); + xStorable->storeToURL(pTempFile->GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + xComponent->dispose(); + + xmlDocUniquePtr pContentXml = XPathHelper::parseExport(pTempFile, m_xSFactory, "content.xml"); + CPPUNIT_ASSERT(pContentXml); + + assertXPathContent(pContentXml, + "/office:document-content/office:body/office:spreadsheet/table:table[1]/" + "table:table-row[1]/table:table-cell[1]/text:p", "string no newlines"); + + assertXPathContent(pContentXml, + "/office:document-content/office:body/office:spreadsheet/table:table[1]/" + "table:table-row[1]/table:table-cell[2]/text:p[1]", "string with"); + + // Without the fix in place, this test would have failed here with + // - Expression: xmlXPathNodeSetGetLength(pXmlNodes) > 0 + assertXPathContent(pContentXml, + "/office:document-content/office:body/office:spreadsheet/table:table[1]/" + "table:table-row[1]/table:table-cell[2]/text:p[2]", "newlines"); + + assertXPathContent(pContentXml, + "/office:document-content/office:body/office:spreadsheet/table:table[1]/" + "table:table-row[2]/table:table-cell[1]/text:p", "string no newlines"); + + assertXPathContent(pContentXml, + "/office:document-content/office:body/office:spreadsheet/table:table[1]/" + "table:table-row[2]/table:table-cell[2]/text:p[1]", "string with"); + assertXPathContent(pContentXml, + "/office:document-content/office:body/office:spreadsheet/table:table[1]/" + "table:table-row[2]/table:table-cell[2]/text:p[2]", "newlines"); +} + void ScMacrosTest::testTdf131562() { OUString aFileName; diff --git a/sc/qa/extras/testdocuments/tdf142033.ods b/sc/qa/extras/testdocuments/tdf142033.ods new file mode 100644 index 000000000000..da49b7323489 Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf142033.ods differ -- cgit