From 87dce617eb1cbbb650dda3e5dc557fa0a058e505 Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Wed, 9 Nov 2022 14:22:09 +0100 Subject: [PATCH] UnoApiTest: factor out common code Change-Id: I1d84d8c1e371016a4f4f068af1e9c76635f28cf4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142490 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- .../CppunitTest_dbaccess_firebird_test.mk | 1 + dbaccess/CppunitTest_dbaccess_hsqldb_test.mk | 1 + desktop/qa/desktop_lib/test_desktop_lib.cxx | 51 ++------ include/test/unoapi_test.hxx | 4 + oox/CppunitTest_oox_export.mk | 1 + oox/CppunitTest_oox_mathml.mk | 1 + oox/CppunitTest_oox_vml.mk | 1 + sc/CppunitTest_sc_functionlistobj.mk | 1 + sc/common_unoapi_tests.mk | 1 + sc/qa/extras/scpdfexport.cxx | 122 ++++++------------ sd/CppunitTest_sd_filter_eppt.mk | 1 + sd/qa/unit/SdrPdfImportTest.cxx | 8 +- sfx2/CppunitTest_sfx2_classification.mk | 1 + sfx2/CppunitTest_sfx2_doc.mk | 1 + sfx2/CppunitTest_sfx2_misc.mk | 1 + sfx2/CppunitTest_sfx2_view.mk | 1 + svx/CppunitTest_svx_styles.mk | 1 + svx/qa/unit/core.cxx | 9 +- svx/qa/unit/svdraw.cxx | 11 +- sw/qa/core/text/text.cxx | 16 +-- sw/qa/extras/uiwriter/uiwriter2.cxx | 11 +- sw/qa/extras/uiwriter/uiwriter8.cxx | 8 +- sw/qa/inc/swmodeltestbase.hxx | 3 - sw/qa/unit/swmodeltestbase.cxx | 12 -- test/source/unoapi_test.cxx | 15 +++ .../CppunitTest_writerfilter_dmapper.mk | 1 + .../CppunitTest_writerfilter_rtftok.mk | 1 + xmloff/CppunitTest_xmloff_draw.mk | 1 + xmloff/CppunitTest_xmloff_style.mk | 1 + xmloff/CppunitTest_xmloff_text.mk | 1 + 30 files changed, 105 insertions(+), 183 deletions(-) diff --git a/dbaccess/CppunitTest_dbaccess_firebird_test.mk b/dbaccess/CppunitTest_dbaccess_firebird_test.mk index c9ca5b9bf4bb..9b7af21ff31b 100644 --- a/dbaccess/CppunitTest_dbaccess_firebird_test.mk +++ b/dbaccess/CppunitTest_dbaccess_firebird_test.mk @@ -24,6 +24,7 @@ $(eval $(call gb_CppunitTest_use_libraries,dbaccess_firebird_test, \ subsequenttest \ svt \ test \ + tl \ unotest \ utl \ xo \ diff --git a/dbaccess/CppunitTest_dbaccess_hsqldb_test.mk b/dbaccess/CppunitTest_dbaccess_hsqldb_test.mk index 3cad59f2ad47..07b4f960b859 100644 --- a/dbaccess/CppunitTest_dbaccess_hsqldb_test.mk +++ b/dbaccess/CppunitTest_dbaccess_hsqldb_test.mk @@ -28,6 +28,7 @@ $(eval $(call gb_CppunitTest_use_libraries,dbaccess_hsqldb_test, \ utl \ test \ tk \ + tl \ unotest \ xo \ )) diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 2ac74ba74a87..0850a1cb884d 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -675,9 +675,7 @@ void DesktopLOKTest::testPaintTile() void DesktopLOKTest::testSaveAs() { LibLODocument_Impl* pDocument = loadDoc("blank_text.odt"); - utl::TempFileNamed aTempFile; - aTempFile.EnableKillingFile(); - CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, aTempFile.GetURL().toUtf8().getStr(), "png", nullptr)); + CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, maTempFile.GetURL().toUtf8().getStr(), "png", nullptr)); } void DesktopLOKTest::testSaveAsJsonOptions() @@ -686,21 +684,12 @@ void DesktopLOKTest::testSaveAsJsonOptions() LibLODocument_Impl* pDocument = loadDoc("3page.odg"); // When exporting that document to PDF, skipping the first page: - utl::TempFileNamed aTempFile; - aTempFile.EnableKillingFile(); OString aOptions("{\"PageRange\":{\"type\":\"string\",\"value\":\"2-\"}}"); - CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, aTempFile.GetURL().toUtf8().getStr(), "pdf", aOptions.getStr())); + CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, maTempFile.GetURL().toUtf8().getStr(), "pdf", aOptions.getStr())); // Then make sure the resulting PDF has 2 pages: - SvFileStream aFile(aTempFile.GetURL(), StreamMode::READ); - SvMemoryStream aMemory; - aMemory.WriteStream(aFile); - std::shared_ptr pPDFium = vcl::pdf::PDFiumLibrary::get(); - if (!pPDFium) - return; std::unique_ptr pPdfDocument - = pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString()); - CPPUNIT_ASSERT(pPdfDocument); + = parsePDFExport(); // Without the accompanying fix in place, this test would have failed with: // - Expected: 2 // - Actual : 3 @@ -711,9 +700,7 @@ void DesktopLOKTest::testSaveAsJsonOptions() void DesktopLOKTest::testSaveAsCalc() { LibLODocument_Impl* pDocument = loadDoc("search.ods"); - utl::TempFileNamed aTempFile; - aTempFile.EnableKillingFile(); - CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, aTempFile.GetURL().toUtf8().getStr(), "png", nullptr)); + CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, maTempFile.GetURL().toUtf8().getStr(), "png", nullptr)); } void DesktopLOKTest::testPasteWriter() @@ -2725,12 +2712,10 @@ void DesktopLOKTest::testInsertCertificate_DER_ODT() { // Load the document, save it into a temp file and load that file again LibLODocument_Impl* pDocument = loadDoc("blank_text.odt"); - utl::TempFileNamed aTempFile; - aTempFile.EnableKillingFile(); - CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, aTempFile.GetURL().toUtf8().getStr(), "odt", nullptr)); + CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, maTempFile.GetURL().toUtf8().getStr(), "odt", nullptr)); closeDoc(); - pDocument = loadDocUrl(aTempFile.GetURL(), LOK_DOCTYPE_TEXT); + pDocument = loadDocUrl(maTempFile.GetURL(), LOK_DOCTYPE_TEXT); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT(mxComponent.is()); @@ -2775,12 +2760,10 @@ void DesktopLOKTest::testInsertCertificate_PEM_ODT() { // Load the document, save it into a temp file and load that file again LibLODocument_Impl* pDocument = loadDoc("blank_text.odt"); - utl::TempFileNamed aTempFile; - aTempFile.EnableKillingFile(); - CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, aTempFile.GetURL().toUtf8().getStr(), "odt", nullptr)); + CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, maTempFile.GetURL().toUtf8().getStr(), "odt", nullptr)); closeDoc(); - pDocument = loadDocUrl(aTempFile.GetURL(), LOK_DOCTYPE_TEXT); + pDocument = loadDocUrl(maTempFile.GetURL(), LOK_DOCTYPE_TEXT); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT(mxComponent.is()); @@ -2832,12 +2815,10 @@ void DesktopLOKTest::testInsertCertificate_PEM_DOCX() { // Load the document, save it into a temp file and load that file again LibLODocument_Impl* pDocument = loadDoc("blank_text.docx"); - utl::TempFileNamed aTempFile; - aTempFile.EnableKillingFile(); - CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, aTempFile.GetURL().toUtf8().getStr(), "docx", nullptr)); + CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, maTempFile.GetURL().toUtf8().getStr(), "docx", nullptr)); closeDoc(); - pDocument = loadDocUrl(aTempFile.GetURL(), LOK_DOCTYPE_TEXT); + pDocument = loadDocUrl(maTempFile.GetURL(), LOK_DOCTYPE_TEXT); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT(mxComponent.is()); @@ -2889,8 +2870,6 @@ void DesktopLOKTest::testSignDocument_PEM_PDF() { // Load the document, save it into a temp file and load that file again LibLODocument_Impl* pDocument = loadDoc("blank_text.odt"); - utl::TempFileNamed aTempFile; - aTempFile.EnableKillingFile(); Scheduler::ProcessEventsToIdle(); CPPUNIT_ASSERT(mxComponent.is()); @@ -2924,7 +2903,7 @@ void DesktopLOKTest::testSignDocument_PEM_PDF() CPPUNIT_ASSERT(bResult); } - CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, aTempFile.GetURL().toUtf8().getStr(), "pdf", nullptr)); + CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, maTempFile.GetURL().toUtf8().getStr(), "pdf", nullptr)); closeDoc(); @@ -2934,7 +2913,7 @@ void DesktopLOKTest::testSignDocument_PEM_PDF() readFileIntoByteVector(u"test-PK-signing.pem", aPrivateKey); LibLibreOffice_Impl aOffice; - bool bResult = aOffice.m_pOfficeClass->signDocument(&aOffice, aTempFile.GetURL().toUtf8().getStr(), + bool bResult = aOffice.m_pOfficeClass->signDocument(&aOffice, maTempFile.GetURL().toUtf8().getStr(), aCertificate.data(), int(aCertificate.size()), aPrivateKey.data(), int(aPrivateKey.size())); @@ -3096,13 +3075,11 @@ void DesktopLOKTest::testCalcSaveAs() Scheduler::ProcessEventsToIdle(); // Save as a new file. - utl::TempFileNamed aTempFile; - aTempFile.EnableKillingFile(); - pDocument->pClass->saveAs(pDocument, aTempFile.GetURL().toUtf8().getStr(), "ods", nullptr); + pDocument->pClass->saveAs(pDocument, maTempFile.GetURL().toUtf8().getStr(), "ods", nullptr); closeDoc(); // Load the new document and verify that the in-flight changes are saved. - pDocument = loadDocUrl(aTempFile.GetURL(), LOK_DOCTYPE_SPREADSHEET); + pDocument = loadDocUrl(maTempFile.GetURL(), LOK_DOCTYPE_SPREADSHEET); CPPUNIT_ASSERT(pDocument); ViewCallback aView(pDocument); diff --git a/include/test/unoapi_test.hxx b/include/test/unoapi_test.hxx index ede9734776ad..8b7a6464f144 100644 --- a/include/test/unoapi_test.hxx +++ b/include/test/unoapi_test.hxx @@ -19,6 +19,7 @@ #include #include #include +#include // basic uno api test class @@ -40,6 +41,8 @@ public: void saveAndClose(const OUString& rFilter); void saveAndReload(const OUString& rFilter); + std::unique_ptr parsePDFExport(const OString& rPassword = OString()); + void skipValidation() { mbSkipValidation = true; } void setFilterOptions(const OUString& rFilterOptions) { maFilterOptions = rFilterOptions; } @@ -53,6 +56,7 @@ private: bool mbSkipValidation; OUString m_aBaseString; OUString maFilterOptions; + SvMemoryStream maMemory; // Underlying memory for parsed PDF files. }; #endif // INCLUDED_TEST_UNOAPI_TEST_HXX diff --git a/oox/CppunitTest_oox_export.mk b/oox/CppunitTest_oox_export.mk index 98f4dc8e6363..68d4566cefc8 100644 --- a/oox/CppunitTest_oox_export.mk +++ b/oox/CppunitTest_oox_export.mk @@ -29,6 +29,7 @@ $(eval $(call gb_CppunitTest_use_libraries,oox_export, \ test \ unotest \ utl \ + tl \ )) $(eval $(call gb_CppunitTest_use_sdk_api,oox_export)) diff --git a/oox/CppunitTest_oox_mathml.mk b/oox/CppunitTest_oox_mathml.mk index 4022c762aebc..133e66c8444d 100644 --- a/oox/CppunitTest_oox_mathml.mk +++ b/oox/CppunitTest_oox_mathml.mk @@ -28,6 +28,7 @@ $(eval $(call gb_CppunitTest_use_libraries,oox_mathml, \ test \ unotest \ utl \ + tl \ )) $(eval $(call gb_CppunitTest_use_sdk_api,oox_mathml)) diff --git a/oox/CppunitTest_oox_vml.mk b/oox/CppunitTest_oox_vml.mk index 9968aa83870a..28ccb2a9c816 100644 --- a/oox/CppunitTest_oox_vml.mk +++ b/oox/CppunitTest_oox_vml.mk @@ -28,6 +28,7 @@ $(eval $(call gb_CppunitTest_use_libraries,oox_vml, \ test \ unotest \ utl \ + tl \ )) $(eval $(call gb_CppunitTest_use_sdk_api,oox_vml)) diff --git a/sc/CppunitTest_sc_functionlistobj.mk b/sc/CppunitTest_sc_functionlistobj.mk index b09aac6e2a11..a190b1c9acef 100644 --- a/sc/CppunitTest_sc_functionlistobj.mk +++ b/sc/CppunitTest_sc_functionlistobj.mk @@ -26,6 +26,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_functionlistobj, \ test \ unotest \ utl \ + tl \ )) $(eval $(call gb_CppunitTest_set_include,sc_functionlistobj,\ diff --git a/sc/common_unoapi_tests.mk b/sc/common_unoapi_tests.mk index 3daa8d9d411d..2f044599b2d9 100644 --- a/sc/common_unoapi_tests.mk +++ b/sc/common_unoapi_tests.mk @@ -32,6 +32,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_$(1), \ test \ unotest \ utl \ + tl \ vcl \ )) diff --git a/sc/qa/extras/scpdfexport.cxx b/sc/qa/extras/scpdfexport.cxx index c3a48c8b4868..a3056965c733 100644 --- a/sc/qa/extras/scpdfexport.cxx +++ b/sc/qa/extras/scpdfexport.cxx @@ -46,13 +46,11 @@ public: // helpers private: - std::shared_ptr exportToPDF(const uno::Reference& xModel, - const ScRange& range); + void exportToPDF(const uno::Reference& xModel, const ScRange& range); - std::shared_ptr exportToPDFWithUnoCommands(const OUString& rRange); + void exportToPDFWithUnoCommands(const OUString& rRange); - static bool hasTextInPdf(const std::shared_ptr& pPDFFile, const char* sText, - bool& bFound); + bool hasTextInPdf(const char* sText, bool& bFound); void setFont(ScFieldEditEngine& rEE, sal_Int32 nStart, sal_Int32 nEnd, const OUString& rFontName); @@ -92,10 +90,9 @@ ScPDFExportTest::~ScPDFExportTest() #endif } -bool ScPDFExportTest::hasTextInPdf(const std::shared_ptr& pPDFFile, - const char* sText, bool& bFound) +bool ScPDFExportTest::hasTextInPdf(const char* sText, bool& bFound) { - SvStream* pStream = pPDFFile->GetStream(StreamMode::STD_READ); + SvStream* pStream = maTempFile.GetStream(StreamMode::STD_READ); CPPUNIT_ASSERT(pStream); // get file size @@ -118,21 +115,12 @@ bool ScPDFExportTest::hasTextInPdf(const std::shared_ptr& pP // close and return the status pStream = nullptr; - pPDFFile->CloseStream(); + maTempFile.CloseStream(); return (nRead == nFileSize); } -std::shared_ptr -ScPDFExportTest::exportToPDF(const uno::Reference& xModel, const ScRange& range) +void ScPDFExportTest::exportToPDF(const uno::Reference& xModel, const ScRange& range) { - // create temp file name - auto pTempFile = std::make_shared(); - pTempFile->EnableKillingFile(); - OUString sFileURL = pTempFile->GetURL(); - // Note: under Windows path path should be with "/" delimiters instead of "\\" - // due to usage of INetURLObject() that converts "\\" to hexadecimal notation. - ::osl::FileBase::getFileURLFromSystemPath(sFileURL, sFileURL); - // get XSpreadsheet uno::Reference xDoc(xModel, uno::UNO_QUERY_THROW); uno::Reference xSheets(xDoc->getSheets(), UNO_SET_THROW); @@ -165,29 +153,17 @@ ScPDFExportTest::exportToPDF(const uno::Reference& xModel, const css::uno::Sequence seqArguments{ comphelper::makePropertyValue("FilterData", aFilterData), comphelper::makePropertyValue("FilterName", OUString("calc_pdf_Export")), - comphelper::makePropertyValue("URL", sFileURL) + comphelper::makePropertyValue("URL", maTempFile.GetURL()) }; // call storeToURL() uno::Reference xComponent(mxComponent, UNO_SET_THROW); uno::Reference xStorable(xComponent, UNO_QUERY); - xStorable->storeToURL(sFileURL, seqArguments); - - // return file object with generated PDF - return pTempFile; + xStorable->storeToURL(maTempFile.GetURL(), seqArguments); } -std::shared_ptr -ScPDFExportTest::exportToPDFWithUnoCommands(const OUString& rRange) +void ScPDFExportTest::exportToPDFWithUnoCommands(const OUString& rRange) { - // create temp file name - auto pTempFile = std::make_shared(); - pTempFile->EnableKillingFile(); - OUString sFileURL = pTempFile->GetURL(); - // Note: under Windows path path should be with "/" delimiters instead of "\\" - // due to usage of INetURLObject() that converts "\\" to hexadecimal notation. - ::osl::FileBase::getFileURLFromSystemPath(sFileURL, sFileURL); - uno::Sequence aArgs = comphelper::InitPropertySequence({ { "ToPoint", uno::Any(rRange) } }); dispatchCommand(mxComponent, ".uno:GoToCell", aArgs); @@ -200,12 +176,9 @@ ScPDFExportTest::exportToPDFWithUnoCommands(const OUString& rRange) uno::Sequence aDescriptor( comphelper::InitPropertySequence({ { "FilterName", uno::Any(OUString("calc_pdf_Export")) }, { "FilterData", uno::Any(aFilterData) }, - { "URL", uno::Any(sFileURL) } })); + { "URL", uno::Any(maTempFile.GetURL()) } })); dispatchCommand(mxComponent, ".uno:ExportToPDF", aDescriptor); - - // return file object with generated PDF - return pTempFile; } void ScPDFExportTest::setFont(ScFieldEditEngine& rEE, sal_Int32 nStart, sal_Int32 nEnd, @@ -259,27 +232,27 @@ void ScPDFExportTest::testExportRange_Tdf120161() // A1:G1 { ScRange range1(0, 0, 0, 6, 0, 0); - std::shared_ptr pPDFFile = exportToPDF(xModel, range1); + exportToPDF(xModel, range1); bool bFound = false; - CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "DejaVuSans", bFound)); + CPPUNIT_ASSERT(hasTextInPdf("DejaVuSans", bFound)); CPPUNIT_ASSERT_EQUAL(false, bFound); } // G1:H1 { ScRange range1(6, 0, 0, 7, 0, 0); - std::shared_ptr pPDFFile = exportToPDF(xModel, range1); + exportToPDF(xModel, range1); bool bFound = false; - CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "DejaVuSans", bFound)); + CPPUNIT_ASSERT(hasTextInPdf("DejaVuSans", bFound)); CPPUNIT_ASSERT_EQUAL(true, bFound); } // H1:I1 { ScRange range1(7, 0, 0, 8, 0, 0); - std::shared_ptr pPDFFile = exportToPDF(xModel, range1); + exportToPDF(xModel, range1); bool bFound = false; - CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "DejaVuSans", bFound)); + CPPUNIT_ASSERT(hasTextInPdf("DejaVuSans", bFound)); CPPUNIT_ASSERT_EQUAL(true, bFound); } } @@ -312,18 +285,18 @@ void ScPDFExportTest::testExportFitToPage_Tdf103516() // A1:G50: 2-page export { ScRange range1(0, 0, 0, 6, 49, 0); - std::shared_ptr pPDFFile = exportToPDF(xModel, range1); + exportToPDF(xModel, range1); bool bFound = false; - CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "/Count 2>>", bFound)); + CPPUNIT_ASSERT(hasTextInPdf("/Count 2>>", bFound)); CPPUNIT_ASSERT_EQUAL(true, bFound); } // A1:L80: 4-page export { ScRange range1(0, 0, 0, 11, 79, 0); - std::shared_ptr pPDFFile = exportToPDF(xModel, range1); + exportToPDF(xModel, range1); bool bFound = false; - CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "/Count 4>>", bFound)); + CPPUNIT_ASSERT(hasTextInPdf("/Count 4>>", bFound)); CPPUNIT_ASSERT_EQUAL(true, bFound); } @@ -351,18 +324,18 @@ void ScPDFExportTest::testExportFitToPage_Tdf103516() // A1:G50 with fit to page width=1: slightly smaller zoom results only 1-page export { ScRange range1(0, 0, 0, 6, 49, 0); - std::shared_ptr pPDFFile = exportToPDF(xModel, range1); + exportToPDF(xModel, range1); bool bFound = false; - CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "/Count 1>>", bFound)); + CPPUNIT_ASSERT(hasTextInPdf("/Count 1>>", bFound)); CPPUNIT_ASSERT_EQUAL(true, bFound); } // A1:L80 with fit to page width=1: slightly smaller zoom results only 1-page export { ScRange range1(0, 0, 0, 11, 79, 0); - std::shared_ptr pPDFFile = exportToPDF(xModel, range1); + exportToPDF(xModel, range1); bool bFound = false; - CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "/Count 1>>", bFound)); + CPPUNIT_ASSERT(hasTextInPdf("/Count 1>>", bFound)); CPPUNIT_ASSERT_EQUAL(true, bFound); } } @@ -373,25 +346,25 @@ void ScPDFExportTest::testUnoCommands_Tdf120161() // A1:G1 { - std::shared_ptr pPDFFile = exportToPDFWithUnoCommands("A1:G1"); + exportToPDFWithUnoCommands("A1:G1"); bool bFound = false; - CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "DejaVuSans", bFound)); + CPPUNIT_ASSERT(hasTextInPdf("DejaVuSans", bFound)); CPPUNIT_ASSERT_EQUAL(false, bFound); } // G1:H1 { - std::shared_ptr pPDFFile = exportToPDFWithUnoCommands("G1:H1"); + exportToPDFWithUnoCommands("G1:H1"); bool bFound = false; - CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "DejaVuSans", bFound)); + CPPUNIT_ASSERT(hasTextInPdf("DejaVuSans", bFound)); CPPUNIT_ASSERT_EQUAL(true, bFound); } // H1:I1 { - std::shared_ptr pPDFFile = exportToPDFWithUnoCommands("H1:I1"); + exportToPDFWithUnoCommands("H1:I1"); bool bFound = false; - CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "DejaVuSans", bFound)); + CPPUNIT_ASSERT(hasTextInPdf("DejaVuSans", bFound)); CPPUNIT_ASSERT_EQUAL(true, bFound); } } @@ -405,9 +378,9 @@ void ScPDFExportTest::testTdf64703_hiddenPageBreak() // A1:A11: 4-page export { ScRange range1(0, 0, 0, 0, 10, 0); - std::shared_ptr pPDFFile = exportToPDF(xModel, range1); + exportToPDF(xModel, range1); bool bFound = false; - CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "/Count 4>>", bFound)); + CPPUNIT_ASSERT(hasTextInPdf("/Count 4>>", bFound)); CPPUNIT_ASSERT_EQUAL(true, bFound); } } @@ -425,14 +398,9 @@ void ScPDFExportTest::testTdf143978() // A1:A2 ScRange range1(0, 0, 0, 0, 1, 0); - std::shared_ptr pPDFFile = exportToPDF(xModel, range1); + exportToPDF(xModel, range1); // Parse the export result with pdfium. - SvFileStream aFile(pPDFFile->GetURL(), StreamMode::READ); - SvMemoryStream aMemory; - aMemory.WriteStream(aFile); - std::unique_ptr pPdfDocument - = pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString()); - CPPUNIT_ASSERT(pPdfDocument); + std::unique_ptr pPdfDocument = parsePDFExport(); CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount()); // Get the first page @@ -471,14 +439,9 @@ void ScPDFExportTest::testTdf84012() // A1 ScRange range1(0, 0, 0, 0, 0, 0); - std::shared_ptr pPDFFile = exportToPDF(xModel, range1); + exportToPDF(xModel, range1); // Parse the export result with pdfium. - SvFileStream aFile(pPDFFile->GetURL(), StreamMode::READ); - SvMemoryStream aMemory; - aMemory.WriteStream(aFile); - std::unique_ptr pPdfDocument - = pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString()); - CPPUNIT_ASSERT(pPdfDocument); + std::unique_ptr pPdfDocument = parsePDFExport(); CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount()); // Get the first page @@ -511,14 +474,9 @@ void ScPDFExportTest::testTdf78897() // C3:D3 ScRange range1(2, 2, 0, 3, 2, 0); - std::shared_ptr pPDFFile = exportToPDF(xModel, range1); + exportToPDF(xModel, range1); // Parse the export result with pdfium. - SvFileStream aFile(pPDFFile->GetURL(), StreamMode::READ); - SvMemoryStream aMemory; - aMemory.WriteStream(aFile); - std::unique_ptr pPdfDocument - = pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString()); - CPPUNIT_ASSERT(pPdfDocument); + std::unique_ptr pPdfDocument = parsePDFExport(); CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount()); // Get the first page @@ -546,7 +504,7 @@ void ScPDFExportTest::testForcepoint97() // A1:H81 ScRange range1(0, 0, 0, 7, 81, 0); - std::shared_ptr pPDFFile = exportToPDF(xModel, range1); + exportToPDF(xModel, range1); } CPPUNIT_TEST_SUITE_REGISTRATION(ScPDFExportTest); diff --git a/sd/CppunitTest_sd_filter_eppt.mk b/sd/CppunitTest_sd_filter_eppt.mk index 7764d95cd197..7e304e419d76 100644 --- a/sd/CppunitTest_sd_filter_eppt.mk +++ b/sd/CppunitTest_sd_filter_eppt.mk @@ -29,6 +29,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sd_filter_eppt, \ test \ unotest \ utl \ + tl \ )) $(eval $(call gb_CppunitTest_use_sdk_api,sd_filter_eppt)) diff --git a/sd/qa/unit/SdrPdfImportTest.cxx b/sd/qa/unit/SdrPdfImportTest.cxx index 4f45d5f300f3..631dcdde3374 100644 --- a/sd/qa/unit/SdrPdfImportTest.cxx +++ b/sd/qa/unit/SdrPdfImportTest.cxx @@ -220,15 +220,9 @@ CPPUNIT_TEST_FIXTURE(SdrPdfImportTest, testAnnotationsImportExport) comphelper::InitPropertySequence({ { "ExportBookmarks", uno::Any(true) } })); aMediaDescriptor["FilterData"] <<= aFilterData; xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); - mxComponent->dispose(); - - SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ); - SvMemoryStream aMemory; - aMemory.WriteStream(aFile); // Check PDF for annotations - auto pPDFDocument - = pPdfiumLibrary->openDocument(aMemory.GetData(), aMemory.GetSize(), OString()); + auto pPDFDocument = parsePDFExport(); CPPUNIT_ASSERT(pPDFDocument); CPPUNIT_ASSERT_EQUAL(1, pPDFDocument->getPageCount()); diff --git a/sfx2/CppunitTest_sfx2_classification.mk b/sfx2/CppunitTest_sfx2_classification.mk index bfb2c367ed93..2595c9c15135 100644 --- a/sfx2/CppunitTest_sfx2_classification.mk +++ b/sfx2/CppunitTest_sfx2_classification.mk @@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sfx2_classification, \ test \ unotest \ utl \ + tl \ vcl \ sal \ subsequenttest \ diff --git a/sfx2/CppunitTest_sfx2_doc.mk b/sfx2/CppunitTest_sfx2_doc.mk index 8156822a9d87..81ddc76e55f3 100644 --- a/sfx2/CppunitTest_sfx2_doc.mk +++ b/sfx2/CppunitTest_sfx2_doc.mk @@ -29,6 +29,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sfx2_doc, \ sfx \ svl \ utl \ + tl \ )) $(eval $(call gb_CppunitTest_use_sdk_api,sfx2_doc)) diff --git a/sfx2/CppunitTest_sfx2_misc.mk b/sfx2/CppunitTest_sfx2_misc.mk index 9954d71e7ffb..6e2708c9a63c 100644 --- a/sfx2/CppunitTest_sfx2_misc.mk +++ b/sfx2/CppunitTest_sfx2_misc.mk @@ -26,6 +26,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sfx2_misc, \ subsequenttest \ sfx \ utl \ + tl \ )) $(eval $(call gb_CppunitTest_use_externals,sfx2_misc,\ diff --git a/sfx2/CppunitTest_sfx2_view.mk b/sfx2/CppunitTest_sfx2_view.mk index 626fdfee8300..f6f247ee7618 100644 --- a/sfx2/CppunitTest_sfx2_view.mk +++ b/sfx2/CppunitTest_sfx2_view.mk @@ -27,6 +27,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sfx2_view, \ test \ unotest \ utl \ + tl \ sfx \ svl \ )) diff --git a/svx/CppunitTest_svx_styles.mk b/svx/CppunitTest_svx_styles.mk index 71e9743e2b3f..b23984657a96 100644 --- a/svx/CppunitTest_svx_styles.mk +++ b/svx/CppunitTest_svx_styles.mk @@ -28,6 +28,7 @@ $(eval $(call gb_CppunitTest_use_libraries,svx_styles, \ test \ unotest \ utl \ + tl \ )) $(eval $(call gb_CppunitTest_use_sdk_api,svx_styles)) diff --git a/svx/qa/unit/core.cxx b/svx/qa/unit/core.cxx index e627215807d2..f834222ea009 100644 --- a/svx/qa/unit/core.cxx +++ b/svx/qa/unit/core.cxx @@ -47,16 +47,9 @@ CPPUNIT_TEST_FIXTURE(Test, testChartExportToPdf) maTempFile.GetURL()); // Then make sure we get a valid, non-empty PDF: - auto pPdfium = vcl::pdf::PDFiumLibrary::get(); - if (!pPdfium) - return; - SvMemoryStream aMemory; - aMemory.WriteStream(*maTempFile.GetStream(StreamMode::READ)); - std::unique_ptr pPdfDocument - = pPdfium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString()); // Without the accompanying fix in place, this test would have failed, because the output was // empty (0 bytes). - CPPUNIT_ASSERT(pPdfDocument); + std::unique_ptr pPdfDocument = parsePDFExport(); int nPageCount = pPdfDocument->getPageCount(); CPPUNIT_ASSERT_GREATER(0, nPageCount); } diff --git a/svx/qa/unit/svdraw.cxx b/svx/qa/unit/svdraw.cxx index 4373d2b5d608..c1c8bc435a9a 100644 --- a/svx/qa/unit/svdraw.cxx +++ b/svx/qa/unit/svdraw.cxx @@ -497,16 +497,7 @@ CPPUNIT_TEST_FIXTURE(SvdrawTest, testPageViewDrawLayerClip) save("writer_pdf_Export"); // Then make sure that line shape gets clipped: - SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ); - SvMemoryStream aMemory; - aMemory.WriteStream(aFile); - std::shared_ptr pPDFium = vcl::pdf::PDFiumLibrary::get(); - if (!pPDFium) - { - return; - } - std::unique_ptr pDoc - = pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString()); + std::unique_ptr pDoc = parsePDFExport(); std::unique_ptr pPage1 = pDoc->openPage(0); CPPUNIT_ASSERT_EQUAL(3, pPage1->getObjectCount()); std::unique_ptr pPage2 = pDoc->openPage(1); diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx index 4127a3c1c108..d51f6c18f71c 100644 --- a/sw/qa/core/text/text.cxx +++ b/sw/qa/core/text/text.cxx @@ -128,7 +128,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testBibliographyUrlPdfExport) save("writer_pdf_Export"); // Then make sure the field links the source. - std::unique_ptr pPdfDocument = LoadPdfFromTempFile(); + std::unique_ptr pPdfDocument = parsePDFExport(); std::unique_ptr pPdfPage = pPdfDocument->openPage(/*nIndex=*/0); // Without the accompanying fix in place, this test would have failed, the field was not // clickable (while it was clickable on the UI). @@ -651,7 +651,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testContentControlPDF) save("writer_pdf_Export"); // Then make sure that a fillable form widget is emitted: - std::unique_ptr pPdfDocument = LoadPdfFromTempFile(); + std::unique_ptr pPdfDocument = parsePDFExport(); std::unique_ptr pPage = pPdfDocument->openPage(0); // Without the accompanying fix in place, this test would have failed with: // - Expected: 1 @@ -677,7 +677,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testCheckboxContentControlPDF) save("writer_pdf_Export"); // Then make sure that a checkbox form widget is emitted: - std::unique_ptr pPdfDocument = LoadPdfFromTempFile(); + std::unique_ptr pPdfDocument = parsePDFExport(); std::unique_ptr pPage = pPdfDocument->openPage(0); // Without the accompanying fix in place, this test would have failed with: // - Expected: 1 @@ -702,7 +702,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testDropdownContentControlPDF) save("writer_pdf_Export"); // Then make sure that a dropdown form widget is emitted: - std::unique_ptr pPdfDocument = LoadPdfFromTempFile(); + std::unique_ptr pPdfDocument = parsePDFExport(); std::unique_ptr pPage = pPdfDocument->openPage(0); // Without the accompanying fix in place, this test would have failed with: // - Expected: 1 @@ -727,7 +727,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testDateContentControlPDF) save("writer_pdf_Export"); // Then make sure that a date form widget is emitted: - std::unique_ptr pPdfDocument = LoadPdfFromTempFile(); + std::unique_ptr pPdfDocument = parsePDFExport(); std::unique_ptr pPage = pPdfDocument->openPage(0); // Without the accompanying fix in place, this test would have failed with: // - Expected: 1 @@ -756,7 +756,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testContentControlPDFFont) save("writer_pdf_Export"); // Then make sure that the widget in the PDF result has that custom font size: - std::unique_ptr pPdfDocument = LoadPdfFromTempFile(); + std::unique_ptr pPdfDocument = parsePDFExport(); std::unique_ptr pPage = pPdfDocument->openPage(0); pPage->onAfterLoadPage(pPdfDocument.get()); CPPUNIT_ASSERT_EQUAL(1, pPage->getAnnotationCount()); @@ -779,7 +779,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testComboContentControlPDF) save("writer_pdf_Export"); // Then make sure that a combo box form widget is emitted: - std::unique_ptr pPdfDocument = LoadPdfFromTempFile(); + std::unique_ptr pPdfDocument = parsePDFExport(); std::unique_ptr pPage = pPdfDocument->openPage(0); // Without the accompanying fix in place, this test would have failed with: // - Expected: 1 @@ -816,7 +816,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testRichContentControlPDF) save("writer_pdf_Export"); // Then make sure that a single fillable form widget is emitted: - std::unique_ptr pPdfDocument = LoadPdfFromTempFile(); + std::unique_ptr pPdfDocument = parsePDFExport(); std::unique_ptr pPage = pPdfDocument->openPage(0); // Without the accompanying fix in place, this test would have failed with: // - Expected: 1 diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index 239aa71ac3ad..0f4d5086bb81 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -3217,16 +3217,9 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testConditionalHiddenSectionIssue) } // PDF export - uno::Reference xStorable(mxComponent, uno::UNO_QUERY); - utl::MediaDescriptor aMediaDescriptor; - aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export"); - xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + save("writer_pdf_Export"); - SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ); - SvMemoryStream aMemory; - aMemory.WriteStream(aFile); - auto pPdfDocument = pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString()); - CPPUNIT_ASSERT(pPdfDocument); + auto pPdfDocument = parsePDFExport(); auto pPdfPage = pPdfDocument->openPage(0); CPPUNIT_ASSERT(pPdfPage); diff --git a/sw/qa/extras/uiwriter/uiwriter8.cxx b/sw/qa/extras/uiwriter/uiwriter8.cxx index 674747b6c0d7..86976f715253 100644 --- a/sw/qa/extras/uiwriter/uiwriter8.cxx +++ b/sw/qa/extras/uiwriter/uiwriter8.cxx @@ -648,13 +648,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf145584) // Without the fix in place, this test would have crashed here dispatchCommand(mxComponent, ".uno:ExportToPDF", aDescriptor); - // Parse the export result. - SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ); - SvMemoryStream aMemory; - aMemory.WriteStream(aFile); - std::unique_ptr pPdfDocument - = pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString()); - CPPUNIT_ASSERT(pPdfDocument); + std::unique_ptr pPdfDocument = parsePDFExport(); CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount()); std::unique_ptr pPdfPage = pPdfDocument->openPage(/*nIndex=*/0); CPPUNIT_ASSERT(pPdfPage); diff --git a/sw/qa/inc/swmodeltestbase.hxx b/sw/qa/inc/swmodeltestbase.hxx index 4ec714a3a9c4..ed1537384686 100644 --- a/sw/qa/inc/swmodeltestbase.hxx +++ b/sw/qa/inc/swmodeltestbase.hxx @@ -105,7 +105,6 @@ protected: const char* mpFilter; sal_uInt32 mnStartTime; - SvMemoryStream maMemory; ///< Underlying memory for parsed PDF files. virtual OUString getTestName() { return OUString(); } @@ -371,8 +370,6 @@ protected: */ SwDoc* getSwDoc(); - std::unique_ptr LoadPdfFromTempFile(); - /** * Wraps a reqif-xhtml fragment into an XHTML file, so an XML parser can * parse it. diff --git a/sw/qa/unit/swmodeltestbase.cxx b/sw/qa/unit/swmodeltestbase.cxx index 540874ac9322..6aa8639d16e9 100644 --- a/sw/qa/unit/swmodeltestbase.cxx +++ b/sw/qa/unit/swmodeltestbase.cxx @@ -643,18 +643,6 @@ SwXTextDocument& SwModelTestBase::getSwXTextDocument() SwDoc* SwModelTestBase::getSwDoc() { return getSwXTextDocument().GetDocShell()->GetDoc(); } -std::unique_ptr SwModelTestBase::LoadPdfFromTempFile() -{ - SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ); - maMemory.WriteStream(aFile); - std::shared_ptr pPDFium = vcl::pdf::PDFiumLibrary::get(); - if (!pPDFium) - { - return nullptr; - } - return pPDFium->openDocument(maMemory.GetData(), maMemory.GetSize(), OString()); -} - void SwModelTestBase::WrapReqifFromTempFile(SvMemoryStream& rStream) { rStream.WriteCharPtr("\n"); diff --git a/test/source/unoapi_test.cxx b/test/source/unoapi_test.cxx index 6918f7a7a174..bc9395246c8c 100644 --- a/test/source/unoapi_test.cxx +++ b/test/source/unoapi_test.cxx @@ -152,4 +152,19 @@ void UnoApiTest::saveAndReload(const OUString& rFilter) mxComponent = loadFromDesktop(maTempFile.GetURL()); } +std::unique_ptr UnoApiTest::parsePDFExport(const OString& rPassword) +{ + SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ); + maMemory.WriteStream(aFile); + std::shared_ptr pPDFium = vcl::pdf::PDFiumLibrary::get(); + if (!pPDFium) + { + return nullptr; + } + std::unique_ptr pPdfDocument + = pPDFium->openDocument(maMemory.GetData(), maMemory.GetSize(), rPassword); + CPPUNIT_ASSERT(pPdfDocument); + return pPdfDocument; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/CppunitTest_writerfilter_dmapper.mk b/writerfilter/CppunitTest_writerfilter_dmapper.mk index 3eb3a1bf370d..c54f3105b766 100644 --- a/writerfilter/CppunitTest_writerfilter_dmapper.mk +++ b/writerfilter/CppunitTest_writerfilter_dmapper.mk @@ -36,6 +36,7 @@ $(eval $(call gb_CppunitTest_use_libraries,writerfilter_dmapper, \ test \ unotest \ utl \ + tl \ vcl \ )) diff --git a/writerfilter/CppunitTest_writerfilter_rtftok.mk b/writerfilter/CppunitTest_writerfilter_rtftok.mk index d52970045ac6..e7e58d844797 100644 --- a/writerfilter/CppunitTest_writerfilter_rtftok.mk +++ b/writerfilter/CppunitTest_writerfilter_rtftok.mk @@ -34,6 +34,7 @@ $(eval $(call gb_CppunitTest_use_libraries,writerfilter_rtftok, \ test \ unotest \ utl \ + tl \ vcl \ )) diff --git a/xmloff/CppunitTest_xmloff_draw.mk b/xmloff/CppunitTest_xmloff_draw.mk index 8ee751b89107..77f931e3eec7 100644 --- a/xmloff/CppunitTest_xmloff_draw.mk +++ b/xmloff/CppunitTest_xmloff_draw.mk @@ -29,6 +29,7 @@ $(eval $(call gb_CppunitTest_use_libraries,xmloff_draw, \ test \ unotest \ utl \ + tl \ avmedia \ svxcore \ vcl \ diff --git a/xmloff/CppunitTest_xmloff_style.mk b/xmloff/CppunitTest_xmloff_style.mk index 3d0d6b730e0c..9b58ee33e5bb 100644 --- a/xmloff/CppunitTest_xmloff_style.mk +++ b/xmloff/CppunitTest_xmloff_style.mk @@ -29,6 +29,7 @@ $(eval $(call gb_CppunitTest_use_libraries,xmloff_style, \ test \ unotest \ utl \ + tl \ )) $(eval $(call gb_CppunitTest_use_sdk_api,xmloff_style)) diff --git a/xmloff/CppunitTest_xmloff_text.mk b/xmloff/CppunitTest_xmloff_text.mk index 7c4ffd32d389..6734e852ac6e 100644 --- a/xmloff/CppunitTest_xmloff_text.mk +++ b/xmloff/CppunitTest_xmloff_text.mk @@ -29,6 +29,7 @@ $(eval $(call gb_CppunitTest_use_libraries,xmloff_text, \ test \ unotest \ utl \ + tl \ )) $(eval $(call gb_CppunitTest_use_sdk_api,xmloff_text))