vcl/qa/cppunit/pdfexport/data/tdf103492.odt |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx      |   48 ++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)

New commits:
commit c1446da82b999349e1a09fed3420bd1c38d7b38c
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Mon Aug 15 11:46:19 2022 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Tue Aug 16 00:26:28 2022 +0200

    tdf#103492: vcl_pdfexport: Add unittest
    
    Change-Id: I426ace3f1272b2cb5f40d627c9c701b903c3e632
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138272
    Reviewed-by: خالد حسني <kha...@aliftype.com>
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/vcl/qa/cppunit/pdfexport/data/tdf103492.odt 
b/vcl/qa/cppunit/pdfexport/data/tdf103492.odt
new file mode 100644
index 000000000000..c76e8b4348a9
Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/tdf103492.odt differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index fb821a7777e4..a6d635d21369 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -1251,6 +1251,54 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf115117_2a)
 #endif
 }
 
+CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf103492)
+{
+    // Import the bugdoc and export as PDF.
+    aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
+    saveAsPDF(u"tdf103492.odt");
+
+    // Parse the export result with pdfium.
+    std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parseExport();
+    CPPUNIT_ASSERT(pPdfDocument);
+
+    // The document has two page.
+    CPPUNIT_ASSERT_EQUAL(2, pPdfDocument->getPageCount());
+    std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage1 = 
pPdfDocument->openPage(/*nIndex=*/0);
+    CPPUNIT_ASSERT(pPdfPage1);
+
+    std::unique_ptr<vcl::pdf::PDFiumTextPage> pPdfTextPage1 = 
pPdfPage1->getTextPage();
+    CPPUNIT_ASSERT(pPdfTextPage1);
+
+    int nChars1 = pPdfTextPage1->countChars();
+
+    // Without the fix in place, this test would have failed with
+    // - Expected: 15
+    // - Actual  : 18
+    CPPUNIT_ASSERT_EQUAL(15, nChars1);
+
+    std::vector<sal_uInt32> aChars1(nChars1);
+    for (int i = 0; i < nChars1; i++)
+        aChars1[i] = pPdfTextPage1->getUnicode(i);
+    OUString aActualText1(aChars1.data(), aChars1.size());
+    CPPUNIT_ASSERT_EQUAL(OUString(u"يوسف My name is"), aActualText1);
+
+    std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage2 = 
pPdfDocument->openPage(/*nIndex=*/1);
+    CPPUNIT_ASSERT(pPdfPage2);
+
+    std::unique_ptr<vcl::pdf::PDFiumTextPage> pPdfTextPage2 = 
pPdfPage2->getTextPage();
+    CPPUNIT_ASSERT(pPdfTextPage2);
+
+    int nChars2 = pPdfTextPage2->countChars();
+
+    CPPUNIT_ASSERT_EQUAL(15, nChars2);
+
+    std::vector<sal_uInt32> aChars2(nChars2);
+    for (int i = 0; i < nChars2; i++)
+        aChars2[i] = pPdfTextPage2->getUnicode(i);
+    OUString aActualText2(aChars2.data(), aChars2.size());
+    CPPUNIT_ASSERT_EQUAL(OUString(u"My name is يوسف"), aActualText2);
+}
+
 CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf145274)
 {
     // Import the bugdoc and export as PDF.

Reply via email to