vcl/qa/cppunit/pdfexport/data/tdf150846.txt |    1 
 vcl/qa/cppunit/pdfexport/pdfexport.cxx      |   29 ++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)

New commits:
commit 7578842634e007d096ed146f494939bd315b78e4
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Thu Sep 8 12:31:47 2022 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Sep 8 20:00:45 2022 +0200

    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 <xiscofa...@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 000000000000..ce013625030b
--- /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 02a91516a3fb..1e056cc904d1 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.

Reply via email to