sw/qa/extras/htmlexport/data/NestingInA1.fodt | 47 ++++ sw/qa/extras/htmlexport/htmlexport.cxx | 302 ++++++++++---------------- sw/qa/filter/html/html.cxx | 12 - sw/qa/inc/swmodeltestbase.hxx | 5 sw/qa/unit/swmodeltestbase.cxx | 15 - sw/source/filter/html/wrthtml.cxx | 17 - 6 files changed, 193 insertions(+), 205 deletions(-)
New commits: commit 9b0ac7bf8d9cb4f0a52279e7177606795475150b Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Fri Aug 4 07:46:12 2023 +0300 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Tue Aug 8 10:16:43 2023 +0200 tdf#156602: fix handling of nesting of tables in the document beginning The old code only accounted for a single table in the document start, finding the innermost table, and so ignoring any outer tables there. Do the same as for nesting sections: find the outermost one. Change-Id: Ide0e5bcf7c81e43fa5467da86e2e7e00a7076528 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155332 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155413 Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/sw/qa/extras/htmlexport/data/NestingInA1.fodt b/sw/qa/extras/htmlexport/data/NestingInA1.fodt new file mode 100644 index 000000000000..439ef0a57d42 --- /dev/null +++ b/sw/qa/extras/htmlexport/data/NestingInA1.fodt @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:body> + <office:text> + <table:table table:name="Outer"> + <table:table-column table:number-columns-repeated="2"/> + <table:table-row> + <table:table-cell office:value-type="string"> + <table:table table:name="Inner"> + <table:table-column table:number-columns-repeated="2"/> + <table:table-row> + <table:table-cell office:value-type="string"> + <text:p>Inner.A1</text:p> + </table:table-cell> + <table:table-cell office:value-type="string"> + <text:p>Inner.B1</text:p> + </table:table-cell> + </table:table-row> + <table:table-row> + <table:table-cell office:value-type="string"> + <text:p>Inner.A2</text:p> + </table:table-cell> + <table:table-cell office:value-type="string"> + <text:p>Inner.B2</text:p> + </table:table-cell> + </table:table-row> + </table:table> + <text:p>Outer.A1</text:p> + </table:table-cell> + <table:table-cell office:value-type="string"> + <text:p>Outer.B1</text:p> + </table:table-cell> + </table:table-row> + <table:table-row> + <table:table-cell office:value-type="string"> + <text:p>Outer.A2</text:p> + </table:table-cell> + <table:table-cell office:value-type="string"> + <text:p>Outer.B2</text:p> + </table:table-cell> + </table:table-row> + </table:table> + <text:p>Following text</text:p> + </office:text> + </office:body> +</office:document> \ No newline at end of file diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index 8eea82b9263d..54df6ebf4e1e 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -2645,6 +2645,75 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testSingleOleExport) CPPUNIT_ASSERT_EQUAL(tools::Long(450), xReader->GetObjh()); } +CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqIF_Tdf156602) +{ + createSwDoc("NestingInA1.fodt"); + ExportToReqif(); + + xmlDocUniquePtr pDoc = WrapReqifFromTempFile(); + + // The outer table must be kept in the document where the outer table is the first element, + // and its A1 starts with a nested table + + // Only two sub-elements must be inside the div: an outer table and a trailing paragraph + assertXPathChildren(pDoc, "/reqif-xhtml:html/reqif-xhtml:div", 2); + // The outer table must have exactly two rows + assertXPath(pDoc, "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr", 2); + // First outer table cell must have two sub-elements: an inner table and a trailing paragraph + assertXPathChildren( + pDoc, + "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[1]", + 2); + // The inner table must have exactly two rows + assertXPath( + pDoc, + "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[1]/" + "reqif-xhtml:table/reqif-xhtml:tr", + 2); + // Check all the elements' content + assertXPathContent( + pDoc, + "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[1]/" + "reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[1]/reqif-xhtml:p", + "Inner.A1"); + assertXPathContent( + pDoc, + "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[1]/" + "reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[2]/reqif-xhtml:p", + "Inner.B1"); + assertXPathContent( + pDoc, + "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[1]/" + "reqif-xhtml:table/reqif-xhtml:tr[2]/reqif-xhtml:td[1]/reqif-xhtml:p", + "Inner.A2"); + assertXPathContent( + pDoc, + "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[1]/" + "reqif-xhtml:table/reqif-xhtml:tr[2]/reqif-xhtml:td[2]/reqif-xhtml:p", + "Inner.B2"); + assertXPathContent( + pDoc, + "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[1]/" + "reqif-xhtml:p", + "Outer.A1"); + assertXPathContent( + pDoc, + "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[2]/" + "reqif-xhtml:p", + "Outer.B1"); + assertXPathContent( + pDoc, + "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[2]/reqif-xhtml:td[1]/" + "reqif-xhtml:p", + "Outer.A2"); + assertXPathContent( + pDoc, + "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[2]/reqif-xhtml:td[2]/" + "reqif-xhtml:p", + "Outer.B2"); + assertXPathContent(pDoc, "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:p", "Following text"); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/html/wrthtml.cxx b/sw/source/filter/html/wrthtml.cxx index bff741ff3fcd..346dbaa64f1c 100644 --- a/sw/source/filter/html/wrthtml.cxx +++ b/sw/source/filter/html/wrthtml.cxx @@ -500,17 +500,20 @@ ErrCode SwHTMLWriter::WriteStream() // respect table and section at document beginning { - SwTableNode * pTNd = m_pCurrentPam->GetPointNode().FindTableNode(); - if( pTNd && m_bWriteAll ) + if (m_bWriteAll) { - // start with table node !! - m_pCurrentPam->GetPoint()->Assign(*pTNd); + while (const SwStartNode* pTNd = m_pCurrentPam->GetPointNode().FindTableBoxStartNode()) + { + // start with table node !! + m_pCurrentPam->GetPoint()->Assign(*pTNd->FindTableNode()); - if( m_bWriteOnlyFirstTable ) - m_pCurrentPam->GetMark()->Assign(*pTNd->EndOfSectionNode()); + if (m_bWriteOnlyFirstTable) + m_pCurrentPam->GetMark()->Assign( + *m_pCurrentPam->GetPointNode().EndOfSectionNode()); + } } - // first node (with can contain a page break) + // first node (which can contain a page break) m_pStartNdIdx = new SwNodeIndex( m_pCurrentPam->GetPoint()->GetNode() ); SwSectionNode * pSNd = m_pCurrentPam->GetPointNode().FindSectionNode(); commit 83e07f1e31dc4f725d97271f440b0bcbe4f9c993 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Fri Jul 28 15:10:37 2023 +0300 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Tue Aug 8 10:16:36 2023 +0200 Simplify WrapReqifFromTempFile usage This function was only ever used together with creation of a memory stream, and parsing the result. So put it all inside. Change-Id: I4d77b9b0519539f774b73936c3f2eacaab481cb5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155018 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155421 diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index 8607fd623c90..8eea82b9263d 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -261,10 +261,7 @@ public: OUString SwHtmlDomExportTest::GetOlePath() { - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pDoc); + xmlDocUniquePtr pDoc = WrapReqifFromTempFile(); OUString aOlePath = getXPath( pDoc, "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:p/reqif-xhtml:object", "data"); OUString aOleSuffix(".ole"); @@ -277,10 +274,7 @@ OUString SwHtmlDomExportTest::GetOlePath() OUString SwHtmlDomExportTest::GetPngPath() { - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pDoc); + xmlDocUniquePtr pDoc = WrapReqifFromTempFile(); OUString aPngPath = getXPath( pDoc, "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:p/reqif-xhtml:object", "data"); OUString aPngSuffix(".png"); @@ -829,10 +823,7 @@ CPPUNIT_TEST_FIXTURE(HtmlExportTest, testReqIfTable) setFilterOptions("xhtmlns=reqif-xhtml"); save(mpFilter); - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pDoc); + xmlDocUniquePtr pDoc = WrapReqifFromTempFile(); // <div> was missing, so the XHTML fragment wasn't a valid // xhtml.BlkStruct.class type anymore. @@ -883,9 +874,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqIfTableHeight) ExportToReqif(); // Then make sure that the explicit cell height is omitted from the output: - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pDoc = parseXmlStream(&aStream); + xmlDocUniquePtr pDoc = WrapReqifFromTempFile(); // Without the accompanying fix in place, this test would have failed, explicit height was // written, which is not valid reqif-xhtml. assertXPathNoAttribute(pDoc, "//reqif-xhtml:td", "height"); @@ -955,10 +944,7 @@ CPPUNIT_TEST_FIXTURE(HtmlExportTest, testReqIfOle2) if (isExported()) { // Check that the replacement graphic is exported at RTF level. - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pDoc); + xmlDocUniquePtr pDoc = WrapReqifFromTempFile(); // Get the path of the RTF data. OUString aOlePath = getXPath( pDoc, "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:p/reqif-xhtml:object", "data"); @@ -1043,10 +1029,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testTransparentImageReqIf) comphelper::makePropertyValue("ExportImagesAsOLE", true), }; xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties); - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pDoc); + xmlDocUniquePtr pDoc = WrapReqifFromTempFile(); OUString aSource = getXPath( pDoc, @@ -1060,10 +1043,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testTransparentImageReqIf) DECLARE_HTMLEXPORT_TEST(testOleNodataReqIf, "reqif-ole-nodata.odt") { // This failed, io::IOException was thrown during the filter() call. - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pDoc); + xmlDocUniquePtr pDoc = WrapReqifFromTempFile(); // Make sure the native <object> element has the required data attribute. OUString aSource = getXPath( @@ -1079,10 +1059,7 @@ CPPUNIT_TEST_FIXTURE(HtmlExportTest, testNoLangReqIf) setFilterOptions("xhtmlns=reqif-xhtml"); save(mpFilter); - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pDoc); + xmlDocUniquePtr pDoc = WrapReqifFromTempFile(); // Make sure that xml:lang is not written in ReqIF mode. assertXPathNoAttribute(pDoc, "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:h1", "lang"); @@ -1152,10 +1129,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testBlockQuoteReqIf) // Export it. setFilterOptions("xhtmlns=reqif-xhtml"); save("HTML (StarWriter)"); - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pDoc); + xmlDocUniquePtr pDoc = WrapReqifFromTempFile(); // Without the accompanying fix in place, this test would have failed with: // - Expected: 1 @@ -1178,10 +1152,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testRTFOLEMimeType) comphelper::makePropertyValue("RTFOLEMimeType", aType), }; xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties); - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pDoc); + xmlDocUniquePtr pDoc = WrapReqifFromTempFile(); // Without the accompanying fix in place, this test would have failed with: // - Expected: test/rtf @@ -1198,13 +1169,9 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testChinese) // Export it. ExportToReqif(); - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pDoc = parseXmlStream(&aStream); - - // Without the accompanying fix in place, this test would have failed as the output was not + // Without the accompanying fix in place, this would have failed as the output was not // well-formed. - CPPUNIT_ASSERT(pDoc); + WrapReqifFromTempFile(); } CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifComment) @@ -1219,13 +1186,9 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifComment) // Export it. ExportToReqif(); - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pDoc = parseXmlStream(&aStream); - - // Without the accompanying fix in place, this test would have failed as the output was not + // Without the accompanying fix in place, this would have failed as the output was not // well-formed. - CPPUNIT_ASSERT(pDoc); + WrapReqifFromTempFile(); } CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifFontNameSize) @@ -1243,12 +1206,8 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifFontNameSize) // Export it. ExportToReqif(); - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pDoc = parseXmlStream(&aStream); + xmlDocUniquePtr pDoc = WrapReqifFromTempFile(); - // Make sure the output is well-formed. - CPPUNIT_ASSERT(pDoc); // Without the accompanying fix in place, this test would have failed with: // - Expected: 1 // - Actual : 3 @@ -1266,12 +1225,8 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifParagraphAlignment) // Export it. ExportToReqif(); - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pDoc = parseXmlStream(&aStream); + xmlDocUniquePtr pDoc = WrapReqifFromTempFile(); - // Make sure the output is well-formed. - CPPUNIT_ASSERT(pDoc); // Without the accompanying fix in place, this test would have failed with: // - Expected: // - Actual : right @@ -1428,10 +1383,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testMultiParaListItem) ExportToReqif(); - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pXmlDoc); + xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile(); assertXPathContent(pXmlDoc, "//reqif-xhtml:ol/reqif-xhtml:li[1]/reqif-xhtml:p", "A"); assertXPathContent(pXmlDoc, "//reqif-xhtml:ol/reqif-xhtml:li[2]/reqif-xhtml:p[1]", "B"); // Without the accompanying fix in place, this test would have failed with: @@ -1456,10 +1408,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testUnderlineNone) // Make sure that the paragraph has no explicit style, because "text-decoration: none" is // filtered out. - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pXmlDoc); + xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile(); assertXPathNoAttribute(pXmlDoc, "//reqif-xhtml:div/reqif-xhtml:p", "style"); } @@ -1558,10 +1507,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testListHeading) ExportToReqif(); // Then make sure the output is valid xhtml: - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pXmlDoc); + xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile(); // Without the accompanying fix in place, this test would have failed: // - expected: <div><ol><li style="display: block"><p>...</p></li></ol></div> @@ -1602,10 +1548,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testPartiallyNumberedList) ExportToReqif(); // Then make sure the output is well-formed xhtml: - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pXmlDoc); + xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile(); // Without the accompanying fix in place, this test would have failed: // - expected: <li><p>...</p><p>...</p></li> // - actual : <li><p>...</p><p>...</p> @@ -1685,13 +1628,10 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testListHeaderAndItem) ExportToReqif(); // Then make sure the output is well-formed xhtml: - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); - // Without the accompanying fix in place, this test would have failed: + // Without the accompanying fix in place, this would have failed: // Entity: line 3: parser error : Opening and ending tag mismatch: ol line 3 and li // <reqif-xhtml:ol><reqif-xhtml:p>not numbered</reqif-xhtml:p></reqif-xhtml:li> - CPPUNIT_ASSERT(pXmlDoc); + xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile(); // Make sure that in case the list has a header and an item, then both are wrapped in an <li> // element. assertXPath(pXmlDoc, @@ -1715,10 +1655,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testBlockQuoteNoMargin) ExportToReqif(); // Then make sure the output is valid xhtml: - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pXmlDoc); + xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile(); // Without the accompanying fix in place, this test would have failed: // - expected: <blockquote><p>...</p></blockquote> // - actual : <blockquote>...</blockquote> @@ -1784,10 +1721,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifEmbedPNGDirectly) ExportToReqif(); // Then make sure the PNG is embedded directly, without an RTF wrapper: - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pXmlDoc); + xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile(); // Without the accompanying fix in place, this test would have failed with: // - Expected: image/png // - Actual : text/rtf @@ -1808,10 +1742,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifEmbedJPGDirectly) ExportToReqif(); // Then make sure the JPG is embedded directly, without an RTF wrapper: - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pXmlDoc); + xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile(); assertXPath(pXmlDoc, "//reqif-xhtml:p/reqif-xhtml:object", "type", "image/jpeg"); // Without the accompanying fix in place, this test would have failed with: // - Expected: image/jpeg @@ -1838,10 +1769,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifEmbedPNGShapeDirectly) ExportToReqif(); // Then make sure the PNG is embedded directly, without an RTF wrapper: - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pXmlDoc); + xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile(); // Without the accompanying fix in place, this test would have failed with: // - no attribute 'type' exist // i.e. the PNG was exported as GIF, without an explicit type. @@ -1865,10 +1793,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifEmbedJPGShapeDirectly) ExportToReqif(); // Then make sure the JPG is embedded directly, without an RTF wrapper: - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pXmlDoc); + xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile(); // Without the accompanying fix in place, this test would have failed with: // - Expected: image/jpeg // - Actual : image/png @@ -1901,10 +1826,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifEmbedPNGShapeAsOLE) xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties); // Then make sure the PNG is embedded with an RTF wrapper: - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pXmlDoc); + xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile(); // Without the accompanying fix in place, this test would have failed with: // - Expected: text/rtf // - Actual : image/png @@ -1927,10 +1849,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifEmbedShapeAsPNG) ExportToReqif(); // Then make sure the shape is embedded as a PNG: - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pXmlDoc); + xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile(); // Without the accompanying fix in place, this test would have failed with: // - Expected: image/png // - Actual : image/x-vclgraphic @@ -2018,10 +1937,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifEmbedShapeAsPNGCustomDPI) xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties); // Then make sure the shape is embedded as a PNG: - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pXmlDoc); + xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile(); assertXPath(pXmlDoc, "//reqif-xhtml:p/reqif-xhtml:object", "type", "image/png"); // Then check the pixel size of the shape: @@ -2063,13 +1979,8 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifOleBmpTransparent) xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties); // Then make sure the transparent pixel turns into white: - OUString aRtfUrl = GetOlePath(); - SvMemoryStream aRtf; - HtmlExportTest::wrapRtfFragment(aRtfUrl, aRtf); - tools::SvRef<TestReqIfRtfReader> xReader(new TestReqIfRtfReader(aRtf)); - CPPUNIT_ASSERT(xReader->CallParser() != SvParserState::Error); SvMemoryStream aOle1; - CPPUNIT_ASSERT(xReader->WriteObjectData(aOle1)); + ParseOle1FromRtfUrl(GetOlePath(), aOle1); OLE1Reader aOle1Reader(aOle1); SvMemoryStream aBitmapStream(aOle1Reader.m_aNativeData.data(), aOle1Reader.m_aNativeData.size(), StreamMode::READ); @@ -2161,10 +2072,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testListsHeading) ExportToReqif(); // Then make sure the output is valid xhtml: - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pXmlDoc); + xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile(); OUString aContent = getXPathContent(pXmlDoc, "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:ol/" @@ -2220,10 +2128,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testNestedBullets) ExportToReqif(); // Then make sure that there is a <li> between the outer and the inner <ol>: - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pXmlDoc); + xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile(); // Without the accompanying fix in place, this test would have failed with: // - XPath '//reqif-xhtml:ol/reqif-xhtml:li/reqif-xhtml:ol/reqif-xhtml:li/reqif-xhtml:p' not found // i.e. the <li> inside the outer <ol> was missing. @@ -2244,10 +2149,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testTrailingLineBreak) ExportToReqif(); // Then make sure that we still have a single line-break: - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pXmlDoc); + xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile(); // Without the accompanying fix in place, this test would have failed with: // - Expected: 1 // - Actual : 2 @@ -2295,10 +2197,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testLeadingTab) xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties); // Then make sure that leading tabs are replaced with 2 nbsps: - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pXmlDoc); + xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile(); // Without the accompanying fix in place, this test would have failed with: // - Expected: <nbsp><nbsp><space>first // - Actual : <tab><space>first @@ -2406,9 +2305,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testTableBackground) ExportToReqif(); // Then make sure that CSS markup is used, not HTML one: - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); + xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile(); // Without the accompanying fix in place, this test would have failed with: // - XPath '//reqif-xhtml:table[1]' no attribute 'style' exist // i.e. HTML markup was used for the table background color. @@ -2470,9 +2367,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testSectionDir) ExportToReqif(); // Then make sure CSS is used to export the text direction of the section: - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); + xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile(); // Without the accompanying fix in place, this test would have failed with: // - XPath '//reqif-xhtml:div[@id='mysect']' no attribute 'style' exist // i.e. the dir="ltr" HTML attribute was used instead. @@ -2557,10 +2452,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testTdf153923_ReqIF) createSwDoc("TableWithIndent.fodt"); ExportToReqif(); - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pDoc); + xmlDocUniquePtr pDoc = WrapReqifFromTempFile(); assertXPath(pDoc, "//reqif-xhtml:table"); // There should be no 'dd' or 'dl' tags, used as a hack for table indentation @@ -2574,9 +2466,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqIfTransparentTifImg) createSwDoc("reqif-transparent-tif-img.odt"); ExportToReqif(); - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); + xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile(); assertXPath(pXmlDoc, "//reqif-xhtml:p/reqif-xhtml:object[1]", "type", "image/tiff"); OUString imageName = getXPath(pXmlDoc, "//reqif-xhtml:p/reqif-xhtml:object[1]", "data"); // Without the accompanying fix in place, this test would have failed, @@ -2596,11 +2486,8 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testTdf155387) createSwDoc("sub_li_and_ctd.fodt"); ExportToReqif(); - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pDoc = parseXmlStream(&aStream); // Without the fix in place, this would fail - CPPUNIT_ASSERT(pDoc); + xmlDocUniquePtr pDoc = WrapReqifFromTempFile(); // Single top-level list assertXPath(pDoc, "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:ul"); @@ -2630,11 +2517,8 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testTdf155496) createSwDoc("listItemSubheader.fodt"); ExportToReqif(); - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pDoc = parseXmlStream(&aStream); // Without the fix in place, this would fail - CPPUNIT_ASSERT(pDoc); + xmlDocUniquePtr pDoc = WrapReqifFromTempFile(); // Two top-level lists assertXPath(pDoc, "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:ul", 2); @@ -2662,10 +2546,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqIF_RightAlignedTable) createSwDoc("tableRight.fodt"); ExportToReqif(); - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pDoc); + xmlDocUniquePtr pDoc = WrapReqifFromTempFile(); // No 'align' attribute must be present in 'div' assertXPathNoAttribute(pDoc, "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:div", "align"); @@ -2676,10 +2557,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqIF_ListsWithNumFormat) createSwDoc("listsWithNumFormat.fodt"); ExportToReqif(); - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pDoc); + xmlDocUniquePtr pDoc = WrapReqifFromTempFile(); // No 'type' attribute must be present in 'ol' assertXPathNoAttribute(pDoc, "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:ol[1]", "type"); @@ -2693,11 +2571,8 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testTdf155871) createSwDoc("tdf155871.fodt"); ExportToReqif(); - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pDoc = parseXmlStream(&aStream); // Without the fix in place, this would fail - CPPUNIT_ASSERT(pDoc); + xmlDocUniquePtr pDoc = WrapReqifFromTempFile(); } CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqIF_ListsNoStartAttribute) @@ -2705,10 +2580,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqIF_ListsNoStartAttribute) createSwDoc("twoListsWithSameStyle.fodt"); ExportToReqif(); - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pDoc); + xmlDocUniquePtr pDoc = WrapReqifFromTempFile(); // No 'start' attribute must be present in 'ol' assertXPath(pDoc, "//reqif-xhtml:ol[@start]", 0); @@ -2719,10 +2591,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqIF_FrameTextAsObjectAltText) createSwDoc("frameWithText.fodt"); ExportToReqif(); - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pDoc = parseXmlStream(&aStream); - CPPUNIT_ASSERT(pDoc); + xmlDocUniquePtr pDoc = WrapReqifFromTempFile(); // Without the fix, this would fail with // - Expected: Some text in frame & <foo> @@ -2755,9 +2624,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testSingleOleExport) }; xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties); - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); + xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile(); // The root element must be reqif-xhtml:object assertXPath(pXmlDoc, "/reqif-xhtml:html/reqif-xhtml:object", "type", "text/rtf"); diff --git a/sw/qa/filter/html/html.cxx b/sw/qa/filter/html/html.cxx index 523bc49a4358..91f322137ef1 100644 --- a/sw/qa/filter/html/html.cxx +++ b/sw/qa/filter/html/html.cxx @@ -120,9 +120,7 @@ CPPUNIT_TEST_FIXTURE(Test, testSvmImageExport) save("HTML (StarWriter)"); // Then make sure we only export PNG: - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); + xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile(); // Without the accompanying fix in place, this test would have failed with: // - Expected: 1 // - Actual : 2 @@ -154,9 +152,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTableCellFloatValueType) save("HTML (StarWriter)"); // Then make sure that the sdval attribute is omitted, which is not in the XHTML spec: - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); + xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile(); // Without the accompanying fix in place, this test would have failed with: // - XPath '//reqif-xhtml:td' unexpected 'sdval' attribute // i.e. sdval was written in XHTML mode. @@ -216,9 +212,7 @@ CPPUNIT_TEST_FIXTURE(Test, testCenteredTableCSSExport) save("HTML (StarWriter)"); // Then make sure that CSS is used to horizontally position the table: - SvMemoryStream aStream; - WrapReqifFromTempFile(aStream); - xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); + xmlDocUniquePtr pXmlDoc = WrapReqifFromTempFile(); // Without the accompanying fix in place, this test would have failed with: // - Expected: 0 // - Actual : 1 diff --git a/sw/qa/inc/swmodeltestbase.hxx b/sw/qa/inc/swmodeltestbase.hxx index b6ce2f442f8d..838622230877 100644 --- a/sw/qa/inc/swmodeltestbase.hxx +++ b/sw/qa/inc/swmodeltestbase.hxx @@ -324,10 +324,9 @@ protected: SwDocShell* getSwDocShell(); /** - * Wraps a reqif-xhtml fragment into an XHTML file, so an XML parser can - * parse it. + * Wraps a reqif-xhtml fragment into an XHTML file, and XML-parses it. */ - void WrapReqifFromTempFile(SvMemoryStream& rStream); + xmlDocUniquePtr WrapReqifFromTempFile(); void WrapFromTempFile(SvMemoryStream& rStream); diff --git a/sw/qa/unit/swmodeltestbase.cxx b/sw/qa/unit/swmodeltestbase.cxx index da3a0c40d92e..206f8dd53660 100644 --- a/sw/qa/unit/swmodeltestbase.cxx +++ b/sw/qa/unit/swmodeltestbase.cxx @@ -568,13 +568,18 @@ SwDocShell* SwModelTestBase::getSwDocShell() return pTextDoc->GetDocShell(); } -void SwModelTestBase::WrapReqifFromTempFile(SvMemoryStream& rStream) +xmlDocUniquePtr SwModelTestBase::WrapReqifFromTempFile() { - rStream.WriteOString("<reqif-xhtml:html xmlns:reqif-xhtml=\"http://www.w3.org/1999/xhtml\">\n"); + SvMemoryStream aStream; + aStream.WriteOString("<reqif-xhtml:html xmlns:reqif-xhtml=\"http://www.w3.org/1999/xhtml\">\n"); SvFileStream aFileStream(maTempFile.GetURL(), StreamMode::READ); - rStream.WriteStream(aFileStream); - rStream.WriteOString("</reqif-xhtml:html>\n"); - rStream.Seek(0); + aStream.WriteStream(aFileStream); + aStream.WriteOString("</reqif-xhtml:html>\n"); + aStream.Seek(0); + xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); + // Make sure the output is well-formed. + CPPUNIT_ASSERT(pXmlDoc); + return pXmlDoc; } void SwModelTestBase::WrapFromTempFile(SvMemoryStream& rStream) commit 9df132654e1a0817f3fa74c4fb29d2aa015979f3 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Tue Jun 20 20:32:43 2023 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Tue Aug 8 10:16:29 2023 +0200 CppunitTest_sw_htmlexport: avoid reqif magic in testNoLangReqIf Set the filter options explicitly, rather than inferring it from the test name. Change-Id: I49cf0e34354178054db2daa10902917cb5d45080 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153361 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155420 diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index dcfd6b9d535f..8607fd623c90 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -1073,8 +1073,12 @@ DECLARE_HTMLEXPORT_TEST(testOleNodataReqIf, "reqif-ole-nodata.odt") CPPUNIT_ASSERT(!aSource.isEmpty()); } -DECLARE_HTMLEXPORT_TEST(testNoLangReqIf, "reqif-no-lang.odt") +CPPUNIT_TEST_FIXTURE(HtmlExportTest, testNoLangReqIf) { + createSwDoc("reqif-no-lang.odt"); + setFilterOptions("xhtmlns=reqif-xhtml"); + save(mpFilter); + SvMemoryStream aStream; WrapReqifFromTempFile(aStream); xmlDocUniquePtr pDoc = parseXmlStream(&aStream);