sw/qa/extras/htmlexport/htmlexport.cxx | 87 ++++++--------------------------- sw/qa/extras/htmlimport/htmlimport.cxx | 65 +++++++----------------- sw/qa/filter/html/html.cxx | 49 ++++++------------ 3 files changed, 52 insertions(+), 149 deletions(-)
New commits: commit 00f7fae71f95bdbe9fc44a00a0f93924c04948cb Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Fri Nov 4 10:00:57 2022 +0100 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Fri Nov 4 14:16:24 2022 +0100 sw: remove duplicated code Change-Id: Ief47e4d6eeea916c555d28fefca837ef978cb4f7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142267 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index 38ee565cbd14..db78ecc8d22a 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -313,12 +313,8 @@ void SwHtmlDomExportTest::ParseOle1FromRtfUrl(const OUString& rRtfUrl, SvMemoryS void SwHtmlDomExportTest::ExportToReqif() { - uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); - uno::Sequence<beans::PropertyValue> aStoreProperties = { - comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")), - comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")), - }; - xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties); + setFilterOptions("xhtmlns=reqif-xhtml"); + save("HTML (StarWriter)"); } void SwHtmlDomExportTest::ImportFromReqif(const OUString& rUrl) @@ -1057,11 +1053,8 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testBlockQuoteReqIf) xParagraph->setPropertyValue("ParaStyleName", uno::Any(OUString("Quotations"))); // Export it. - uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); - utl::MediaDescriptor aMediaDescriptor; - aMediaDescriptor["FilterName"] <<= OUString("HTML (StarWriter)"); - aMediaDescriptor["FilterOptions"] <<= OUString("xhtmlns=reqif-xhtml"); - xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + setFilterOptions("xhtmlns=reqif-xhtml"); + save("HTML (StarWriter)"); SvMemoryStream aStream; WrapReqifFromTempFile(aStream); xmlDocUniquePtr pDoc = parseXmlStream(&aStream); @@ -1216,16 +1209,10 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifOle1PDF) mxComponent->dispose(); mxComponent.clear(); ImportFromReqif(maTempFile.GetURL()); - uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); - utl::TempFileNamed aTempFile; - aTempFile.EnableKillingFile(); - uno::Sequence<beans::PropertyValue> aStoreProperties = { - comphelper::makePropertyValue("FilterName", OUString("writer8")), - }; - xStorable->storeToURL(aTempFile.GetURL(), aStoreProperties); + save("writer8"); uno::Reference<packages::zip::XZipFileAccess2> xNameAccess = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory), - aTempFile.GetURL()); + maTempFile.GetURL()); uno::Reference<io::XInputStream> xInputStream(xNameAccess->getByName("Object 2"), uno::UNO_QUERY); std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); @@ -1246,12 +1233,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifOle1Paint) ImportFromReqif(aURL); // Save it as ODT to inspect the result of the OLE1 -> OLE2 conversion. - uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); - xStorable.set(mxComponent, uno::UNO_QUERY); - uno::Sequence<beans::PropertyValue> aStoreProperties = { - comphelper::makePropertyValue("FilterName", OUString("writer8")), - }; - xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties); + save("writer8"); uno::Reference<packages::zip::XZipFileAccess2> xNameAccess = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory), maTempFile.GetURL()); @@ -1669,12 +1651,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifEmbedPNGDirectly) dispatchCommand(mxComponent, ".uno:InsertGraphic", aArgs); // When exporting to XHTML: - uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); - uno::Sequence<beans::PropertyValue> aStoreProperties = { - comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")), - comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")), - }; - xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties); + ExportToReqif(); // Then make sure the PNG is embedded directly, without an RTF wrapper: SvMemoryStream aStream; @@ -1699,12 +1676,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifEmbedJPGDirectly) dispatchCommand(mxComponent, ".uno:InsertGraphic", aArgs); // When exporting to XHTML: - uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); - uno::Sequence<beans::PropertyValue> aStoreProperties = { - comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")), - comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")), - }; - xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties); + ExportToReqif(); // Then make sure the JPG is embedded directly, without an RTF wrapper: SvMemoryStream aStream; @@ -1735,12 +1707,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifEmbedPNGShapeDirectly) xDrawPageSupplier->getDrawPage()->add(xShape); // When exporting to XHTML: - uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); - uno::Sequence<beans::PropertyValue> aStoreProperties = { - comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")), - comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")), - }; - xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties); + ExportToReqif(); // Then make sure the PNG is embedded directly, without an RTF wrapper: SvMemoryStream aStream; @@ -1768,12 +1735,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifEmbedJPGShapeDirectly) xDrawPageSupplier->getDrawPage()->add(xShape); // When exporting to XHTML: - uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); - uno::Sequence<beans::PropertyValue> aStoreProperties = { - comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")), - comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")), - }; - xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties); + ExportToReqif(); // Then make sure the JPG is embedded directly, without an RTF wrapper: SvMemoryStream aStream; @@ -1836,12 +1798,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifEmbedShapeAsPNG) xDrawPageSupplier->getDrawPage()->add(xShape); // When exporting to XHTML: - uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); - uno::Sequence<beans::PropertyValue> aStoreProperties = { - comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")), - comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")), - }; - xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties); + ExportToReqif(); // Then make sure the shape is embedded as a PNG: SvMemoryStream aStream; @@ -1876,15 +1833,8 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testShapeAsImageHtml) xDrawPageSupplier->getDrawPage()->add(xShape); // When exporting to plain HTML: - uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); - uno::Sequence<beans::PropertyValue> aStoreProperties = { - comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")), - }; - xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties); - mxComponent->dispose(); + reload("HTML (StarWriter)", ""); - // Then make sure importing it back results in a clean doc model: - mxComponent = loadFromDesktop(maTempFile.GetURL()); // Without the accompanying fix in place, this test would have failed with: // - Expected: // - Actual : /> @@ -1904,14 +1854,9 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testJson) xDrawPageSupplier->getDrawPage()->add(xShape); // When exporting to HTML, and specifying options as JSON: - uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); - OUString aJson("{\"XhtmlNs\":{\"type\":\"string\", \"value\":\"reqif-xhtml\"}," - "\"ShapeDPI\":{\"type\":\"long\",\"value\":\"192\"}}"); - uno::Sequence<beans::PropertyValue> aStoreProperties = { - comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")), - comphelper::makePropertyValue("FilterOptions", aJson), - }; - xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties); + setFilterOptions("{\"XhtmlNs\":{\"type\":\"string\", \"value\":\"reqif-xhtml\"}," + "\"ShapeDPI\":{\"type\":\"long\",\"value\":\"192\"}}"); + save("HTML (StarWriter)"); // Then make sure those options are not ignored: // Without the accompanying fix in place, this test would have failed, as GetPngPath() expects diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx b/sw/qa/extras/htmlimport/htmlimport.cxx index 82b89f5d1bb8..f5b4f5605729 100644 --- a/sw/qa/extras/htmlimport/htmlimport.cxx +++ b/sw/qa/extras/htmlimport/htmlimport.cxx @@ -430,10 +430,10 @@ CPPUNIT_TEST_FIXTURE(HtmlImportTest, testReqIfPageStyle) /// HTML import to the sw doc model tests. class SwHtmlOptionsImportTest : public SwModelTestBase { + public: + SwHtmlOptionsImportTest() : SwModelTestBase("/sw/qa/extras/htmlimport/data/", "HTML (StarWriter)") {} }; -constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/extras/htmlimport/data/"; - CPPUNIT_TEST_FIXTURE(SwHtmlOptionsImportTest, testAllowedRTFOLEMimeTypes) { uno::Sequence<OUString> aTypes = { OUString("test/rtf") }; @@ -443,7 +443,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlOptionsImportTest, testAllowedRTFOLEMimeTypes) comphelper::makePropertyValue("AllowedRTFOLEMimeTypes", aTypes), }; OUString aURL - = m_directories.getURLFromSrc(DATA_DIRECTORY) + "allowed-rtf-ole-mime-types.xhtml"; + = m_directories.getURLFromSrc(mpTestDocumentPath) + "allowed-rtf-ole-mime-types.xhtml"; mxComponent = loadFromDesktop(aURL, "com.sun.star.text.TextDocument", aLoadProperties); uno::Reference<text::XTextEmbeddedObjectsSupplier> xSupplier(mxComponent, uno::UNO_QUERY); uno::Reference<container::XIndexAccess> xObjects(xSupplier->getEmbeddedObjects(), @@ -462,12 +462,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlOptionsImportTest, testAllowedRTFOLEMimeTypes) CPPUNIT_TEST_FIXTURE(SwHtmlOptionsImportTest, testHiddenTextframe) { // Load HTML content into Writer, similar to HTML paste. - uno::Sequence<beans::PropertyValue> aLoadProperties = { - comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")), - }; - OUString aURL - = m_directories.getURLFromSrc(DATA_DIRECTORY) + "hidden-textframe.html"; - mxComponent = loadFromDesktop(aURL, "com.sun.star.text.TextDocument", aLoadProperties); + load(mpTestDocumentPath, "hidden-textframe.html"); // Check the content of the draw page. uno::Reference<drawing::XDrawPageSupplier> xSupplier(mxComponent, uno::UNO_QUERY); @@ -480,18 +475,13 @@ CPPUNIT_TEST_FIXTURE(SwHtmlOptionsImportTest, testHiddenTextframe) CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), xDrawPage->getCount()); } -CPPUNIT_TEST_FIXTURE(SwModelTestBase, testOleImg) +CPPUNIT_TEST_FIXTURE(SwHtmlOptionsImportTest, testOleImg) { // Given an XHTML with an <object> (containing GIF) and an inner <object> (containing PNG, to be // ignored): - uno::Sequence<beans::PropertyValue> aLoadProperties = { - comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")), - comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")), - }; - OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "ole-img.xhtml"; - - // When loading the document: - mxComponent = loadFromDesktop(aURL, "com.sun.star.text.TextDocument", aLoadProperties); + setImportFilterOptions("xhtmlns=reqif-xhtml"); + setImportFilterName("HTML (StarWriter)"); + load(mpTestDocumentPath, "ole-img.xhtml"); // Then make sure the result is a single Writer image: uno::Reference<text::XTextGraphicObjectsSupplier> xSupplier(mxComponent, uno::UNO_QUERY); @@ -504,18 +494,13 @@ CPPUNIT_TEST_FIXTURE(SwModelTestBase, testOleImg) CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xObjects->getCount()); } -CPPUNIT_TEST_FIXTURE(SwModelTestBase, testOleImgSvg) +CPPUNIT_TEST_FIXTURE(SwHtmlOptionsImportTest, testOleImgSvg) { // Given an XHTML with an <object> (containing SVG) and an inner <object> (containing PNG, to be // ignored): - uno::Sequence<beans::PropertyValue> aLoadProperties = { - comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")), - comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")), - }; - OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "ole-img-svg.xhtml"; - - // When loading the document: - mxComponent = loadFromDesktop(aURL, "com.sun.star.text.TextDocument", aLoadProperties); + setImportFilterOptions("xhtmlns=reqif-xhtml"); + setImportFilterName("HTML (StarWriter)"); + load(mpTestDocumentPath, "ole-img-svg.xhtml"); // Then make sure the result is a single Writer image: uno::Reference<text::XTextGraphicObjectsSupplier> xSupplier(mxComponent, uno::UNO_QUERY); @@ -536,18 +521,13 @@ CPPUNIT_TEST_FIXTURE(HtmlImportTest, testUTF16_nonBMP) getParagraph(1)->getString()); } -CPPUNIT_TEST_FIXTURE(SwModelTestBase, testOleData) +CPPUNIT_TEST_FIXTURE(SwHtmlOptionsImportTest, testOleData) { // Given an XHTML with an <object> (containing non-image, non-OLE2 data) and an inner <object> // (containing PNG): - uno::Sequence<beans::PropertyValue> aLoadProperties = { - comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")), - comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")), - }; - OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "ole-data.xhtml"; - - // When loading the document: - mxComponent = loadFromDesktop(aURL, "com.sun.star.text.TextDocument", aLoadProperties); + setImportFilterOptions("xhtmlns=reqif-xhtml"); + setImportFilterName("HTML (StarWriter)"); + load(mpTestDocumentPath, "ole-data.xhtml"); // Then make sure the result is a single clickable Writer image: uno::Reference<text::XTextGraphicObjectsSupplier> xSupplier(mxComponent, uno::UNO_QUERY); @@ -563,17 +543,12 @@ CPPUNIT_TEST_FIXTURE(SwModelTestBase, testOleData) CPPUNIT_ASSERT(getProperty<OUString>(xShape, "HyperLinkURL").endsWith("/data.ole")); } -CPPUNIT_TEST_FIXTURE(SwModelTestBase, testOleData2) +CPPUNIT_TEST_FIXTURE(SwHtmlOptionsImportTest, testOleData2) { // Given an XHTML with 2 objects: the first has a link, the second does not have: - uno::Sequence<beans::PropertyValue> aLoadProperties = { - comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")), - comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")), - }; - OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "ole-data2.xhtml"; - - // When loading the document: - mxComponent = loadFromDesktop(aURL, "com.sun.star.text.TextDocument", aLoadProperties); + setImportFilterOptions("xhtmlns=reqif-xhtml"); + setImportFilterName("HTML (StarWriter)"); + load(mpTestDocumentPath, "ole-data2.xhtml"); // Then make sure that the second image doesn't have a link set: uno::Reference<text::XTextGraphicObjectsSupplier> xSupplier(mxComponent, uno::UNO_QUERY); diff --git a/sw/qa/filter/html/html.cxx b/sw/qa/filter/html/html.cxx index 2881bf8e690f..07bed0ed9f68 100644 --- a/sw/qa/filter/html/html.cxx +++ b/sw/qa/filter/html/html.cxx @@ -19,8 +19,6 @@ namespace { -constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/filter/html/data/"; - /** * Covers sw/source/filter/html/ fixes. * @@ -32,19 +30,19 @@ constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/filter/html/data/"; */ class Test : public SwModelTestBase { +public: + Test() + : SwModelTestBase("/sw/qa/filter/html/data/", "HTML (StarWriter)") + { + } }; CPPUNIT_TEST_FIXTURE(Test, testEmptyParagraph) { // Given a document with 2 paragraphs, the second is empty: - OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "empty-paragraph.xhtml"; - uno::Sequence<beans::PropertyValue> aLoadArgs = { - comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")), - comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")), - }; - - // When loading that file: - mxComponent = loadFromDesktop(aURL, OUString(), aLoadArgs); + setImportFilterOptions("xhtmlns=reqif-xhtml"); + setImportFilterName("HTML (StarWriter)"); + load(mpTestDocumentPath, "empty-paragraph.xhtml"); // Then make sure that the resulting document has a 2nd empty paragraph: getParagraph(1, "a"); @@ -57,14 +55,9 @@ CPPUNIT_TEST_FIXTURE(Test, testEmptyParagraph) CPPUNIT_TEST_FIXTURE(Test, testRelativeKeepAspect) { // Given a document with an OLE object, width set to 100%, height is not set: - OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "relative-keep-aspect.xhtml"; - uno::Sequence<beans::PropertyValue> aLoadArgs = { - comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")), - comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")), - }; - - // When loading that file: - mxComponent = loadFromDesktop(aURL, OUString(), aLoadArgs); + setImportFilterOptions("xhtmlns=reqif-xhtml"); + setImportFilterName("HTML (StarWriter)"); + load(mpTestDocumentPath, "relative-keep-aspect.xhtml"); // Then make sure that the aspect ratio of the image is kept: auto pTextDocument = dynamic_cast<SwXTextDocument*>(mxComponent.get()); @@ -83,15 +76,9 @@ CPPUNIT_TEST_FIXTURE(Test, testRelativeKeepAspect) CPPUNIT_TEST_FIXTURE(Test, testRelativeKeepAspectImage) { // Given a document with an image, width set to 100%, height is not set: - OUString aURL - = m_directories.getURLFromSrc(DATA_DIRECTORY) + "relative-keep-aspect-image.xhtml"; - uno::Sequence<beans::PropertyValue> aLoadArgs = { - comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")), - comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")), - }; - - // When loading that file: - mxComponent = loadFromDesktop(aURL, OUString(), aLoadArgs); + setImportFilterOptions("xhtmlns=reqif-xhtml"); + setImportFilterName("HTML (StarWriter)"); + load(mpTestDocumentPath, "relative-keep-aspect-image.xhtml"); // Then make sure that the aspect ratio of the image is kept: auto pTextDocument = dynamic_cast<SwXTextDocument*>(mxComponent.get()); @@ -126,12 +113,8 @@ CPPUNIT_TEST_FIXTURE(Test, testSvmImageExport) xBodyText->insertTextContent(xCursor, xTextContent, false); // When exporting to reqif: - uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); - uno::Sequence<beans::PropertyValue> aStoreProperties = { - comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")), - comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")), - }; - xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties); + setFilterOptions("xhtmlns=reqif-xhtml"); + save("HTML (StarWriter)"); // Then make sure we only export PNG: SvMemoryStream aStream;