diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2021-03-23 10:44:12 +0100 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2021-03-24 08:38:37 +0100 |
commit | 71f3980e40454907ee7e512678635eb48d9a4058 (patch) | |
tree | 77bc6ffb868293a261ee9a06d7de2c8884384766 /vcl | |
parent | a20c9604f1f53e01850fb753e7f932e7648d2459 (diff) |
tdf#141171: vcl_pdfexport: Add unittest
Change-Id: Ic577103b84afc97dfe9042b3b0a20988b8083e54
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112974
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/qa/cppunit/pdfexport/data/tdf141171.odt | bin | 0 -> 9512 bytes | |||
-rw-r--r-- | vcl/qa/cppunit/pdfexport/pdfexport.cxx | 55 |
2 files changed, 55 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/pdfexport/data/tdf141171.odt b/vcl/qa/cppunit/pdfexport/data/tdf141171.odt Binary files differnew file mode 100644 index 000000000000..951f69541a01 --- /dev/null +++ b/vcl/qa/cppunit/pdfexport/data/tdf141171.odt diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx index 1074e0d1aa95..75832ec20324 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -1813,6 +1813,61 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf121615) CPPUNIT_ASSERT_EQUAL(COL_BLACK, aBitmap.GetPixelColor(199, 299)); } +CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf141171) +{ + 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(static_cast<size_t>(1), aPages.size()); + + // Get access to the only image on the only page. + vcl::filter::PDFObjectElement* pResources = aPages[0]->LookupObject("Resources"); + CPPUNIT_ASSERT(pResources); + auto pXObjects + = dynamic_cast<vcl::filter::PDFDictionaryElement*>(pResources->Lookup("XObject")); + CPPUNIT_ASSERT(pXObjects); + CPPUNIT_ASSERT_EQUAL(static_cast<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, OUString("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(8, int(aBitmap.GetBitCount())); + + 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)); + } + } +} + CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf129085) { vcl::filter::PDFDocument aDocument; |