diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2024-01-05 17:31:34 +0100 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2024-01-05 23:41:33 +0100 |
commit | 25276df12abd9d002f7f899900434617b256f745 (patch) | |
tree | 51c97b95690a664e2ca7f5920b9dea68c1544b5c /sd | |
parent | 1ec3ef4db8c4c03d89a3d86c0e633effde04efda (diff) |
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 <xiscofauli@libreoffice.org>
Diffstat (limited to 'sd')
-rw-r--r-- | sd/qa/unit/PNGExportTests.cxx | 52 | ||||
-rw-r--r-- | sd/qa/unit/data/odp/tdf158743.odp | bin | 0 -> 28777 bytes |
2 files changed, 52 insertions, 0 deletions
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 Binary files differnew file mode 100644 index 000000000000..38c6bf770854 --- /dev/null +++ b/sd/qa/unit/data/odp/tdf158743.odp |