sd/qa/unit/PNGExportTests.cxx | 51 ++++++++++++++++++++++++++++++++++++++ sd/qa/unit/data/ppt/tdf157636.ppt |binary 2 files changed, 51 insertions(+)
New commits: commit e9374f74385d7dfe77d1902d3d82af20143bc775 Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Wed Oct 11 16:10:37 2023 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Fri Oct 13 00:12:42 2023 +0200 tdf#157636: sd_png_export: Add unittest Change-Id: I76ec68fb6482d7c348a08021413c640cf640d7f1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157836 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 04fbed439a41..8f012347644a 100644 --- a/sd/qa/unit/PNGExportTests.cxx +++ b/sd/qa/unit/PNGExportTests.cxx @@ -298,6 +298,57 @@ CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf156808) } } +CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf157636) +{ + loadFromURL(u"ppt/tdf157636.ppt"); + 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)) + }; + + 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); + 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 greater than: 6600 + // - Actual : 559 + CPPUNIT_ASSERT_GREATER(6600, nBlackCount); +} + CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf157635) { loadFromURL(u"pptx/tdf157635.pptx"); diff --git a/sd/qa/unit/data/ppt/tdf157636.ppt b/sd/qa/unit/data/ppt/tdf157636.ppt new file mode 100644 index 000000000000..1dcbbe6f00dc Binary files /dev/null and b/sd/qa/unit/data/ppt/tdf157636.ppt differ