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

New commits:
commit c7579b6d77a837bc03c9aa529dd67952f0f1f4b1
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Wed Mar 2 13:32:32 2022 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Wed Mar 2 16:43:36 2022 +0100

    tdf#113197: sd_png_export_tests: Add unittest
    
    Change-Id: I1e5a6818f7d540153a50cc42c9c12e17a41409ee
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130846
    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 12533d1bcf90..f80d2e6af384 100644
--- a/sd/qa/unit/PNGExportTests.cxx
+++ b/sd/qa/unit/PNGExportTests.cxx
@@ -281,6 +281,61 @@ CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf147119)
     }
 }
 
+CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf113197)
+{
+    mxComponent
+        = 
loadFromDesktop(m_directories.getURLFromSrc(u"/sd/qa/unit/data/odp/tdf113197.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)),
+    };
+
+    utl::TempFile aTempFile;
+    aTempFile.EnableKillingFile();
+
+    uno::Sequence<beans::PropertyValue> aDescriptor{
+        comphelper::makePropertyValue("URL", aTempFile.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(aTempFile.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)
+        {
+            // Check the bottom half of the document is white
+            for (tools::Long nY = 50; nY < aSize.Height() - 1; ++nY)
+            {
+                // Check all pixels in the image are black
+                // Without the fix in place, this test would have failed with
+                // - Expected: Color: R:255 G:255 B:255 A:0
+                // - Actual  : Color: R:153 G:0 B:51 A:0
+                const Color aColor = pReadAccess->GetColor(nY, nX);
+                CPPUNIT_ASSERT_EQUAL(COL_WHITE, aColor);
+            }
+        }
+    }
+}
+
 CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf93124)
 {
     mxComponent
diff --git a/sd/qa/unit/data/odp/tdf113197.odp 
b/sd/qa/unit/data/odp/tdf113197.odp
new file mode 100644
index 000000000000..0ebabeb5fcdc
Binary files /dev/null and b/sd/qa/unit/data/odp/tdf113197.odp differ

Reply via email to