summaryrefslogtreecommitdiff
path: root/sc/qa/extras/scpdfexport.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sc/qa/extras/scpdfexport.cxx')
-rw-r--r--sc/qa/extras/scpdfexport.cxx122
1 files changed, 40 insertions, 82 deletions
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<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);