sd/qa/unit/PNGExportTests.cxx     |   52 ++++++++++++++++++++++++++++++++++++++
 sd/qa/unit/data/odp/tdf158743.odp |binary
 2 files changed, 52 insertions(+)

New commits:
commit 25276df12abd9d002f7f899900434617b256f745
Author:     Xisco Fauli <[email protected]>
AuthorDate: Fri Jan 5 17:31:34 2024 +0100
Commit:     Xisco Fauli <[email protected]>
CommitDate: Fri Jan 5 23:41:33 2024 +0100

    tdf#158743: sd_png_export: Add unittest
    
    Change-Id: I598960d8cc7d394581def20de3ab64a8ff6c7789
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161694
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <[email protected]>

diff --git a/sd/qa/unit/PNGExportTests.cxx b/sd/qa/unit/PNGExportTests.cxx
index 8b2926bbd896..4f0078b13a85 100644
--- a/sd/qa/unit/PNGExportTests.cxx
+++ b/sd/qa/unit/PNGExportTests.cxx
@@ -301,6 +301,58 @@ CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf156808)
     CPPUNIT_ASSERT_GREATER(9000, nBlackCount);
 }
 
+CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf158743)
+{
+    loadFromFile(u"odp/tdf158743.odp");
+    uno::Reference<uno::XComponentContext> xContext = getComponentContext();
+    CPPUNIT_ASSERT(xContext.is());
+    uno::Reference<drawing::XGraphicExportFilter> xGraphicExporter
+        = drawing::GraphicExportFilter::create(xContext);
+
+    uno::Sequence<beans::PropertyValue> aFilterData{
+        comphelper::makePropertyValue("PixelWidth", sal_Int32(100)),
+        comphelper::makePropertyValue("PixelHeight", sal_Int32(100)),
+        comphelper::makePropertyValue("Translucent", sal_Int32(1))
+    };
+
+    uno::Sequence<beans::PropertyValue> aDescriptor{
+        comphelper::makePropertyValue("URL", maTempFile.GetURL()),
+        comphelper::makePropertyValue("FilterName", OUString("PNG")),
+        comphelper::makePropertyValue("FilterData", aFilterData)
+    };
+
+    uno::Reference<drawing::XDrawPagesSupplier> 
xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<lang::XComponent> 
xPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
+                                           uno::UNO_QUERY);
+    xGraphicExporter->setSourceDocument(xPage);
+    xGraphicExporter->filter(aDescriptor);
+
+    SvFileStream aFileStream(maTempFile.GetURL(), StreamMode::READ);
+    vcl::PngImageReader aPNGReader(aFileStream);
+    BitmapEx aBMPEx = aPNGReader.read();
+
+    // make sure the bitmap is not empty and correct size (PNG export->import 
was successful)
+    Size aSize = aBMPEx.GetSizePixel();
+    CPPUNIT_ASSERT_EQUAL(Size(100, 100), aSize);
+    Bitmap aBMP = aBMPEx.GetBitmap();
+    BitmapScopedReadAccess pReadAccess(aBMP);
+    int nBlackCount = 0;
+    for (tools::Long nX = 1; nX < aSize.Width() - 1; ++nX)
+    {
+        for (tools::Long nY = 1; nY < aSize.Height() - 1; ++nY)
+        {
+            const Color aColor = pReadAccess->GetColor(nY, nX);
+            if (aColor == COL_BLACK)
+                ++nBlackCount;
+        }
+    }
+
+    // Without the fix in place, this test would have failed with
+    // - Expected: 842
+    // - Actual  : 2493
+    CPPUNIT_ASSERT_LESS(850, nBlackCount);
+}
+
 CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf157795)
 {
     loadFromFile(u"odp/tdf157795.odp");
diff --git a/sd/qa/unit/data/odp/tdf158743.odp 
b/sd/qa/unit/data/odp/tdf158743.odp
new file mode 100644
index 000000000000..38c6bf770854
Binary files /dev/null and b/sd/qa/unit/data/odp/tdf158743.odp differ

Reply via email to