[Libreoffice-commits] core.git: vcl/qa

Xisco Fauli (via logerrit) logerrit at kemper.freedesktop.org
Fri Mar 12 14:34:34 UTC 2021


 vcl/qa/cppunit/pdfexport/data/tdf129085.docx |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx       |   43 +++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)

New commits:
commit f4f6ec04544059910ab5ec47817fad2287dd3f5a
Author:     Xisco Fauli <xiscofauli at libreoffice.org>
AuthorDate: Thu Mar 11 14:00:26 2021 +0100
Commit:     Xisco Fauli <xiscofauli at libreoffice.org>
CommitDate: Fri Mar 12 15:33:41 2021 +0100

    tdf#129085: vcl_pdfexport: Add unittest
    
    Change-Id: Id0d46d258c960e31896bdf5b288135364f0ecd2b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112342
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofauli at libreoffice.org>

diff --git a/vcl/qa/cppunit/pdfexport/data/tdf129085.docx b/vcl/qa/cppunit/pdfexport/data/tdf129085.docx
new file mode 100644
index 000000000000..6ac21d8f28b8
Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/tdf129085.docx differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index a15832aeabff..514ea6ef73bc 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -1780,6 +1780,49 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf121615)
     CPPUNIT_ASSERT_EQUAL(COL_BLACK, aBitmap.GetPixelColor(199, 299));
 }
 
+CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf129085)
+{
+    vcl::filter::PDFDocument aDocument;
+    load(u"tdf129085.docx", aDocument);
+
+    // The document has one page.
+    std::vector<vcl::filter::PDFObjectElement*> aPages = aDocument.GetPages();
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aPages.size());
+
+    // Get access to the only image on the only page.
+    vcl::filter::PDFObjectElement* pResources = aPages[0]->LookupObject("Resources");
+    CPPUNIT_ASSERT(pResources);
+    auto pXObjects
+        = dynamic_cast<vcl::filter::PDFDictionaryElement*>(pResources->Lookup("XObject"));
+
+    // Without the fix in place, this test would have failed here
+    CPPUNIT_ASSERT(pXObjects);
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pXObjects->GetItems().size());
+    vcl::filter::PDFObjectElement* pXObject
+        = pXObjects->LookupObject(pXObjects->GetItems().begin()->first);
+    CPPUNIT_ASSERT(pXObject);
+    vcl::filter::PDFStreamElement* pStream = pXObject->GetStream();
+    CPPUNIT_ASSERT(pStream);
+    SvMemoryStream& rObjectStream = pStream->GetMemory();
+
+    // Load the embedded image.
+    rObjectStream.Seek(0);
+    GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
+    Graphic aGraphic;
+    sal_uInt16 format;
+    ErrCode bResult = rFilter.ImportGraphic(aGraphic, OUString("import"), rObjectStream,
+                                            GRFILTER_FORMAT_DONTKNOW, &format);
+    CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, bResult);
+
+    sal_uInt16 jpegFormat = rFilter.GetImportFormatNumberForShortName(JPG_SHORTNAME);
+    CPPUNIT_ASSERT(jpegFormat != GRFILTER_FORMAT_NOTFOUND);
+    CPPUNIT_ASSERT_EQUAL(jpegFormat, format);
+    BitmapEx aBitmap = aGraphic.GetBitmapEx();
+    CPPUNIT_ASSERT_EQUAL(tools::Long(884), aBitmap.GetSizePixel().Width());
+    CPPUNIT_ASSERT_EQUAL(tools::Long(925), aBitmap.GetSizePixel().Height());
+    CPPUNIT_ASSERT_EQUAL(24, int(aBitmap.GetBitCount()));
+}
+
 CPPUNIT_TEST_FIXTURE(PdfExportTest, testTocLink)
 {
     // Load the Writer document.


More information about the Libreoffice-commits mailing list