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

New commits:
commit 33f158d96c5782a862345736bc6561afe3d583b5
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Wed Oct 25 10:33:01 2023 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Wed Oct 25 12:28:08 2023 +0200

    tdf#157795: sd_png_export: Add unittest
    
    Change-Id: Iedf8c33833ce08d42fd52a7080fa6b60e9555c09
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158417
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sd/qa/unit/PNGExportTests.cxx b/sd/qa/unit/PNGExportTests.cxx
index af48ecbdd713..513d7a1e8cf9 100644
--- a/sd/qa/unit/PNGExportTests.cxx
+++ b/sd/qa/unit/PNGExportTests.cxx
@@ -301,6 +301,55 @@ CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf156808)
     CPPUNIT_ASSERT_GREATER(9000, nBlackCount);
 }
 
+CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf157795)
+{
+    loadFromURL(u"odp/tdf157795.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();
+    Bitmap::ScopedReadAccess pReadAccess(aBMP);
+    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);
+
+            // Without the fix in place, this test would have failed with
+            // - Expected: rgba[000000ff]
+            // - Actual  : rgba[010101ff]
+            CPPUNIT_ASSERT_EQUAL(COL_BLACK, aColor);
+        }
+    }
+}
+
 CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf105362)
 {
     loadFromURL(u"odp/tdf105362.odp");
diff --git a/sd/qa/unit/data/odp/tdf157795.odp 
b/sd/qa/unit/data/odp/tdf157795.odp
new file mode 100644
index 000000000000..abfe29bb7940
Binary files /dev/null and b/sd/qa/unit/data/odp/tdf157795.odp differ

Reply via email to