tdf#150846: vcl_pdfexport: Add unittest
Change-Id: I16a7326a0164e319cf97b1a34849a3134232364d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139646
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
diff --git a/vcl/qa/cppunit/pdfexport/data/tdf150846.txt b/vcl/qa/cppunit/pdfexport/data/tdf150846.txt
new file mode 100644
index 0000000..ce01362
--- /dev/null
+++ b/vcl/qa/cppunit/pdfexport/data/tdf150846.txt
@@ -0,0 +1 @@
hello
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 02a9151..1e056cc 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -1251,6 +1251,35 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf115117_2a)
#endif
}
CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf150846)
{
// Without the fix in place, this test would have failed with
// An uncaught exception of type com.sun.star.io.IOException
aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
saveAsPDF(u"tdf150846.txt");
// Parse the export result with pdfium.
std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parseExport();
CPPUNIT_ASSERT(pPdfDocument);
CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->getPageCount());
std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage = pPdfDocument->openPage(/*nIndex=*/0);
CPPUNIT_ASSERT(pPdfPage);
std::unique_ptr<vcl::pdf::PDFiumTextPage> pPdfTextPage = pPdfPage->getTextPage();
CPPUNIT_ASSERT(pPdfTextPage);
int nChars = pPdfTextPage->countChars();
CPPUNIT_ASSERT_EQUAL(5, nChars);
std::vector<sal_uInt32> aChars(nChars);
for (int i = 0; i < nChars; i++)
aChars[i] = pPdfTextPage->getUnicode(i);
OUString aActualText(aChars.data(), aChars.size());
CPPUNIT_ASSERT_EQUAL(OUString(u"hello"), aActualText);
}
CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf103492)
{
// Import the bugdoc and export as PDF.