UnoApiTest: factor out common code

Change-Id: I1d84d8c1e371016a4f4f068af1e9c76635f28cf4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142490
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
This commit is contained in:
Xisco Fauli 2022-11-09 14:22:09 +01:00
parent 7f8b79c21c
commit 87dce617eb
30 changed files with 105 additions and 183 deletions

View file

@ -24,6 +24,7 @@ $(eval $(call gb_CppunitTest_use_libraries,dbaccess_firebird_test, \
subsequenttest \
svt \
test \
tl \
unotest \
utl \
xo \

View file

@ -28,6 +28,7 @@ $(eval $(call gb_CppunitTest_use_libraries,dbaccess_hsqldb_test, \
utl \
test \
tk \
tl \
unotest \
xo \
))

View file

@ -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<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get();
if (!pPDFium)
return;
std::unique_ptr<vcl::pdf::PDFiumDocument> 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);

View file

@ -19,6 +19,7 @@
#include <com/sun/star/lang/XComponent.hpp>
#include <osl/file.hxx>
#include <unotools/tempfile.hxx>
#include <vcl/filter/PDFiumLibrary.hxx>
// basic uno api test class
@ -40,6 +41,8 @@ public:
void saveAndClose(const OUString& rFilter);
void saveAndReload(const OUString& rFilter);
std::unique_ptr<vcl::pdf::PDFiumDocument> 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

View file

@ -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))

View file

@ -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))

View file

@ -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))

View file

@ -26,6 +26,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_functionlistobj, \
test \
unotest \
utl \
tl \
))
$(eval $(call gb_CppunitTest_set_include,sc_functionlistobj,\

View file

@ -32,6 +32,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_$(1), \
test \
unotest \
utl \
tl \
vcl \
))

View file

@ -46,13 +46,11 @@ public:
// helpers
private:
std::shared_ptr<utl::TempFileNamed> exportToPDF(const uno::Reference<frame::XModel>& xModel,
const ScRange& range);
void exportToPDF(const uno::Reference<frame::XModel>& xModel, const ScRange& range);
std::shared_ptr<utl::TempFileNamed> exportToPDFWithUnoCommands(const OUString& rRange);
void exportToPDFWithUnoCommands(const OUString& rRange);
static bool hasTextInPdf(const std::shared_ptr<utl::TempFileNamed>& 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<utl::TempFileNamed>& 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<utl::TempFileNamed>& pP
// close and return the status
pStream = nullptr;
pPDFFile->CloseStream();
maTempFile.CloseStream();
return (nRead == nFileSize);
}
std::shared_ptr<utl::TempFileNamed>
ScPDFExportTest::exportToPDF(const uno::Reference<frame::XModel>& xModel, const ScRange& range)
void ScPDFExportTest::exportToPDF(const uno::Reference<frame::XModel>& xModel, const ScRange& range)
{
// create temp file name
auto pTempFile = std::make_shared<utl::TempFileNamed>();
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<sheet::XSpreadsheetDocument> xDoc(xModel, uno::UNO_QUERY_THROW);
uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW);
@ -165,29 +153,17 @@ ScPDFExportTest::exportToPDF(const uno::Reference<frame::XModel>& xModel, const
css::uno::Sequence<css::beans::PropertyValue> 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<lang::XComponent> xComponent(mxComponent, UNO_SET_THROW);
uno::Reference<css::frame::XStorable> xStorable(xComponent, UNO_QUERY);
xStorable->storeToURL(sFileURL, seqArguments);
// return file object with generated PDF
return pTempFile;
xStorable->storeToURL(maTempFile.GetURL(), seqArguments);
}
std::shared_ptr<utl::TempFileNamed>
ScPDFExportTest::exportToPDFWithUnoCommands(const OUString& rRange)
void ScPDFExportTest::exportToPDFWithUnoCommands(const OUString& rRange)
{
// create temp file name
auto pTempFile = std::make_shared<utl::TempFileNamed>();
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<beans::PropertyValue> aArgs
= comphelper::InitPropertySequence({ { "ToPoint", uno::Any(rRange) } });
dispatchCommand(mxComponent, ".uno:GoToCell", aArgs);
@ -200,12 +176,9 @@ ScPDFExportTest::exportToPDFWithUnoCommands(const OUString& rRange)
uno::Sequence<beans::PropertyValue> 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<utl::TempFileNamed> 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<utl::TempFileNamed> 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<utl::TempFileNamed> 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<utl::TempFileNamed> 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<utl::TempFileNamed> 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<utl::TempFileNamed> 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<utl::TempFileNamed> 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<utl::TempFileNamed> 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<utl::TempFileNamed> 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<utl::TempFileNamed> 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<utl::TempFileNamed> 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<utl::TempFileNamed> 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<vcl::pdf::PDFiumDocument> pPdfDocument
= pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString());
CPPUNIT_ASSERT(pPdfDocument);
std::unique_ptr<vcl::pdf::PDFiumDocument> 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<utl::TempFileNamed> 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<vcl::pdf::PDFiumDocument> pPdfDocument
= pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString());
CPPUNIT_ASSERT(pPdfDocument);
std::unique_ptr<vcl::pdf::PDFiumDocument> 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<utl::TempFileNamed> 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<vcl::pdf::PDFiumDocument> pPdfDocument
= pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString());
CPPUNIT_ASSERT(pPdfDocument);
std::unique_ptr<vcl::pdf::PDFiumDocument> 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<utl::TempFileNamed> pPDFFile = exportToPDF(xModel, range1);
exportToPDF(xModel, range1);
}
CPPUNIT_TEST_SUITE_REGISTRATION(ScPDFExportTest);

View file

@ -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))

View file

@ -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());

View file

@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sfx2_classification, \
test \
unotest \
utl \
tl \
vcl \
sal \
subsequenttest \

View file

@ -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))

View file

@ -26,6 +26,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sfx2_misc, \
subsequenttest \
sfx \
utl \
tl \
))
$(eval $(call gb_CppunitTest_use_externals,sfx2_misc,\

View file

@ -27,6 +27,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sfx2_view, \
test \
unotest \
utl \
tl \
sfx \
svl \
))

View file

@ -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))

View file

@ -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<vcl::pdf::PDFiumDocument> 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<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport();
int nPageCount = pPdfDocument->getPageCount();
CPPUNIT_ASSERT_GREATER(0, nPageCount);
}

View file

@ -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<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get();
if (!pPDFium)
{
return;
}
std::unique_ptr<vcl::pdf::PDFiumDocument> pDoc
= pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString());
std::unique_ptr<vcl::pdf::PDFiumDocument> pDoc = parsePDFExport();
std::unique_ptr<vcl::pdf::PDFiumPage> pPage1 = pDoc->openPage(0);
CPPUNIT_ASSERT_EQUAL(3, pPage1->getObjectCount());
std::unique_ptr<vcl::pdf::PDFiumPage> pPage2 = pDoc->openPage(1);

View file

@ -128,7 +128,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testBibliographyUrlPdfExport)
save("writer_pdf_Export");
// Then make sure the field links the source.
std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = LoadPdfFromTempFile();
std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport();
std::unique_ptr<vcl::pdf::PDFiumPage> 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<vcl::pdf::PDFiumDocument> pPdfDocument = LoadPdfFromTempFile();
std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport();
std::unique_ptr<vcl::pdf::PDFiumPage> 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<vcl::pdf::PDFiumDocument> pPdfDocument = LoadPdfFromTempFile();
std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport();
std::unique_ptr<vcl::pdf::PDFiumPage> 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<vcl::pdf::PDFiumDocument> pPdfDocument = LoadPdfFromTempFile();
std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport();
std::unique_ptr<vcl::pdf::PDFiumPage> 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<vcl::pdf::PDFiumDocument> pPdfDocument = LoadPdfFromTempFile();
std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport();
std::unique_ptr<vcl::pdf::PDFiumPage> 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<vcl::pdf::PDFiumDocument> pPdfDocument = LoadPdfFromTempFile();
std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport();
std::unique_ptr<vcl::pdf::PDFiumPage> 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<vcl::pdf::PDFiumDocument> pPdfDocument = LoadPdfFromTempFile();
std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport();
std::unique_ptr<vcl::pdf::PDFiumPage> 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<vcl::pdf::PDFiumDocument> pPdfDocument = LoadPdfFromTempFile();
std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport();
std::unique_ptr<vcl::pdf::PDFiumPage> pPage = pPdfDocument->openPage(0);
// Without the accompanying fix in place, this test would have failed with:
// - Expected: 1

View file

@ -3217,16 +3217,9 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testConditionalHiddenSectionIssue)
}
// PDF export
uno::Reference<frame::XStorable> 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);

View file

@ -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<vcl::pdf::PDFiumDocument> pPdfDocument
= pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString());
CPPUNIT_ASSERT(pPdfDocument);
std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport();
CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount());
std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage = pPdfDocument->openPage(/*nIndex=*/0);
CPPUNIT_ASSERT(pPdfPage);

View file

@ -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<vcl::pdf::PDFiumDocument> LoadPdfFromTempFile();
/**
* Wraps a reqif-xhtml fragment into an XHTML file, so an XML parser can
* parse it.

View file

@ -643,18 +643,6 @@ SwXTextDocument& SwModelTestBase::getSwXTextDocument()
SwDoc* SwModelTestBase::getSwDoc() { return getSwXTextDocument().GetDocShell()->GetDoc(); }
std::unique_ptr<vcl::pdf::PDFiumDocument> SwModelTestBase::LoadPdfFromTempFile()
{
SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ);
maMemory.WriteStream(aFile);
std::shared_ptr<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get();
if (!pPDFium)
{
return nullptr;
}
return pPDFium->openDocument(maMemory.GetData(), maMemory.GetSize(), OString());
}
void SwModelTestBase::WrapReqifFromTempFile(SvMemoryStream& rStream)
{
rStream.WriteCharPtr("<reqif-xhtml:html xmlns:reqif-xhtml=\"http://www.w3.org/1999/xhtml\">\n");

View file

@ -152,4 +152,19 @@ void UnoApiTest::saveAndReload(const OUString& rFilter)
mxComponent = loadFromDesktop(maTempFile.GetURL());
}
std::unique_ptr<vcl::pdf::PDFiumDocument> UnoApiTest::parsePDFExport(const OString& rPassword)
{
SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ);
maMemory.WriteStream(aFile);
std::shared_ptr<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get();
if (!pPDFium)
{
return nullptr;
}
std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument
= pPDFium->openDocument(maMemory.GetData(), maMemory.GetSize(), rPassword);
CPPUNIT_ASSERT(pPdfDocument);
return pPdfDocument;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View file

@ -36,6 +36,7 @@ $(eval $(call gb_CppunitTest_use_libraries,writerfilter_dmapper, \
test \
unotest \
utl \
tl \
vcl \
))

View file

@ -34,6 +34,7 @@ $(eval $(call gb_CppunitTest_use_libraries,writerfilter_rtftok, \
test \
unotest \
utl \
tl \
vcl \
))

View file

@ -29,6 +29,7 @@ $(eval $(call gb_CppunitTest_use_libraries,xmloff_draw, \
test \
unotest \
utl \
tl \
avmedia \
svxcore \
vcl \

View file

@ -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))

View file

@ -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))