vcl/qa/cppunit/pdfexport/pdfexport2.cxx | 96 +++++++++++++------------------- 1 file changed, 40 insertions(+), 56 deletions(-)
New commits: commit f17959f17e4199ecc0b84750e322dbb9d3546a89 Author: Xisco Fauli <[email protected]> AuthorDate: Wed Aug 13 23:37:08 2025 +0200 Commit: Xisco Fauli <[email protected]> CommitDate: Thu Aug 14 09:46:29 2025 +0200 CppunitTest_vcl_pdfexport2: re-enable test Test the fix for tdf#141171 in a different way It got commented out in commit c2fedef548f2822cf2a7e7b3ff928d389ce25728 Author: Noel Grandin <[email protected]> Date: Wed Aug 6 20:35:05 2025 +0200 BitmapEx->Bitmap in Graphic Change-Id: Ife3c783db936dc8654150c45d5349724ba39ba5a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189544 Tested-by: Jenkins Reviewed-by: Xisco Fauli <[email protected]> diff --git a/vcl/qa/cppunit/pdfexport/pdfexport2.cxx b/vcl/qa/cppunit/pdfexport/pdfexport2.cxx index 717b13d2f004..636c55d4be2b 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport2.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport2.cxx @@ -291,62 +291,46 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest2, testTdf121615) CPPUNIT_TEST_FIXTURE(PdfExportTest2, testTdf141171) { - // Commented out this test, because it doesn't test what it thinks it tests. - // It was supposed to test whether or not an image is exported with transparency. - // But transparency in PDF is weird, it is stored as a separate image. - // So checking the color image (as this test does, is not useful). - // - // vcl::filter::PDFDocument aDocument; - // load(u"tdf141171.odt", aDocument); - // - // // The document has one page. - // std::vector<vcl::filter::PDFObjectElement*> aPages = aDocument.GetPages(); - // CPPUNIT_ASSERT_EQUAL(size_t(1), aPages.size()); - // - // // Get access to the only image on the only page. - // vcl::filter::PDFObjectElement* pResources = aPages[0]->LookupObject("Resources"_ostr); - // CPPUNIT_ASSERT(pResources); - // auto pXObjects - // = dynamic_cast<vcl::filter::PDFDictionaryElement*>(pResources->Lookup("XObject"_ostr)); - // CPPUNIT_ASSERT(pXObjects); - // CPPUNIT_ASSERT_EQUAL(size_t(1), pXObjects->GetItems().size()); - // vcl::filter::PDFObjectElement* pXObject - // = pXObjects->LookupObject(pXObjects->GetItems().begin()->first); - // CPPUNIT_ASSERT(pXObject); - // vcl::filter::PDFStreamElement* pStream = pXObject->GetStream(); - // CPPUNIT_ASSERT(pStream); - // SvMemoryStream& rObjectStream = pStream->GetMemory(); - // - // // Load the embedded image. - // rObjectStream.Seek(0); - // GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter(); - // Graphic aGraphic; - // sal_uInt16 format; - // ErrCode bResult = rFilter.ImportGraphic(aGraphic, u"import", rObjectStream, - // GRFILTER_FORMAT_DONTKNOW, &format); - // CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, bResult); - // - // // The image should be grayscale 8bit JPEG. - // sal_uInt16 jpegFormat = rFilter.GetImportFormatNumberForShortName(JPG_SHORTNAME); - // CPPUNIT_ASSERT(jpegFormat != GRFILTER_FORMAT_NOTFOUND); - // CPPUNIT_ASSERT_EQUAL(jpegFormat, format); - // BitmapEx aBitmap = aGraphic.GetBitmapEx(); - // Size aSize = aBitmap.GetSizePixel(); - // CPPUNIT_ASSERT_EQUAL(tools::Long(878), aSize.Width()); - // CPPUNIT_ASSERT_EQUAL(tools::Long(127), aSize.Height()); - // CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N8_BPP, aBitmap.getPixelFormat()); - // - // for (tools::Long nX = 0; nX < aSize.Width(); ++nX) - // { - // for (tools::Long nY = 0; nY < aSize.Height(); ++nY) - // { - // // Check all pixels in the image are white - // // Without the fix in place, this test would have failed with - // // - Expected: Color: R:255 G:255 B:255 A:0 - // // - Actual : Color: R:0 G:0 B:0 A:0 - // CPPUNIT_ASSERT_EQUAL(COL_WHITE, aBitmap.GetPixelColor(nX, nY)); - // } - // } + vcl::filter::PDFDocument aDocument; + load(u"tdf141171.odt", aDocument); + + int nImages(0); + for (const auto& rDocElement : aDocument.GetElements()) + { + auto pObject = dynamic_cast<vcl::filter::PDFObjectElement*>(rDocElement.get()); + if (!pObject) + continue; + auto pType = dynamic_cast<vcl::filter::PDFNameElement*>(pObject->Lookup("Subtype"_ostr)); + if (pType && pType->GetValue() == "Image") + { + auto pBitsPerComponent = dynamic_cast<vcl::filter::PDFNumberElement*>( + pObject->Lookup("BitsPerComponent"_ostr)); + CPPUNIT_ASSERT(pBitsPerComponent); + CPPUNIT_ASSERT_EQUAL(8.0, pBitsPerComponent->GetValue()); + + auto pWidth + = dynamic_cast<vcl::filter::PDFNumberElement*>(pObject->Lookup("Width"_ostr)); + CPPUNIT_ASSERT(pWidth); + CPPUNIT_ASSERT_EQUAL(878.0, pWidth->GetValue()); + + auto pHeight + = dynamic_cast<vcl::filter::PDFNumberElement*>(pObject->Lookup("Height"_ostr)); + CPPUNIT_ASSERT(pHeight); + CPPUNIT_ASSERT_EQUAL(127.0, pHeight->GetValue()); + + auto pColorSpace + = dynamic_cast<vcl::filter::PDFNameElement*>(pObject->Lookup("ColorSpace"_ostr)); + CPPUNIT_ASSERT(pColorSpace); + CPPUNIT_ASSERT_EQUAL("DeviceGray"_ostr, pColorSpace->GetValue()); + + // Check the first image has a SMask + if (nImages == 0) + CPPUNIT_ASSERT(pObject->Lookup("SMask"_ostr)); + ++nImages; + } + } + // Without the fix in place, there would have been only one image + CPPUNIT_ASSERT_EQUAL(2, nImages); } CPPUNIT_TEST_FIXTURE(PdfExportTest2, testTdf161346)
