From 8eb15f031003f6431d41853ff70e307b617d1a5a Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Thu, 17 May 2018 15:15:01 +0900 Subject: Extend test for unloaded graphic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To make sure they are loaded correctly for most common graphic formats. Change-Id: Id121df0ddc763a299c5714cadd0d61740876e3dd Reviewed-on: https://gerrit.libreoffice.org/54467 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- vcl/qa/cppunit/GraphicTest.cxx | 65 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/vcl/qa/cppunit/GraphicTest.cxx b/vcl/qa/cppunit/GraphicTest.cxx index d039ba1dec25..428ebda0560d 100644 --- a/vcl/qa/cppunit/GraphicTest.cxx +++ b/vcl/qa/cppunit/GraphicTest.cxx @@ -12,19 +12,26 @@ #include #include +#include + +#include #include #include #include #include +using namespace css; + namespace { class GraphicTest : public CppUnit::TestFixture { void testUnloadedGraphic(); + void testUnloadedGraphicLoading(); CPPUNIT_TEST_SUITE(GraphicTest); CPPUNIT_TEST(testUnloadedGraphic); + CPPUNIT_TEST(testUnloadedGraphicLoading); CPPUNIT_TEST_SUITE_END(); }; @@ -36,28 +43,30 @@ BitmapEx createBitmap() return BitmapEx(aBitmap); } -void createBitmapAndExportToPNG(SvStream& rStream) +void createBitmapAndExportForType(SvStream& rStream, OUString const& sType) { BitmapEx aBitmapEx = createBitmap(); - vcl::PNGWriter aWriter(aBitmapEx); - aWriter.Write(rStream); + uno::Sequence aFilterData; + GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter(); + sal_uInt16 nFilterFormat = rGraphicFilter.GetExportFormatNumberForShortName(sType); + rGraphicFilter.ExportGraphic(aBitmapEx, "none", rStream, nFilterFormat, &aFilterData); rStream.Seek(STREAM_SEEK_TO_BEGIN); } -Graphic makeUnloadedGraphic() +Graphic makeUnloadedGraphic(OUString const& sType) { SvMemoryStream aStream; GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter(); - createBitmapAndExportToPNG(aStream); + createBitmapAndExportForType(aStream, sType); return rGraphicFilter.ImportUnloadedGraphic(aStream); } void GraphicTest::testUnloadedGraphic() { // make unloaded test graphic - Graphic aGraphic = makeUnloadedGraphic(); + Graphic aGraphic = makeUnloadedGraphic("png"); Graphic aGraphic2 = aGraphic; // check available @@ -69,7 +78,7 @@ void GraphicTest::testUnloadedGraphic() CPPUNIT_ASSERT_EQUAL(true, aGraphic2.isAvailable()); // check GetSizePixel doesn't load graphic - aGraphic = makeUnloadedGraphic(); + aGraphic = makeUnloadedGraphic("png"); CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable()); CPPUNIT_ASSERT_EQUAL(100L, aGraphic.GetSizePixel().Width()); CPPUNIT_ASSERT_EQUAL(100L, aGraphic.GetSizePixel().Height()); @@ -81,6 +90,48 @@ void GraphicTest::testUnloadedGraphic() CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable()); } +void GraphicTest::testUnloadedGraphicLoading() +{ + const OUString aFormats[] = { "png", "gif", "jpg" }; + + for (OUString const& sFormat : aFormats) + { + Graphic aGraphic = makeUnloadedGraphic(sFormat); + + // check available + CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable()); + CPPUNIT_ASSERT_EQUAL(100L, aGraphic.GetSizePixel().Width()); + CPPUNIT_ASSERT_EQUAL(100L, aGraphic.GetSizePixel().Height()); + CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable()); + CPPUNIT_ASSERT(aGraphic.GetSizeBytes() > 0); + CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable()); + Bitmap aBitmap(aGraphic.GetBitmapEx().GetBitmap()); + + { + Bitmap::ScopedReadAccess pReadAccess(aBitmap); + for (long y = 0; y < aGraphic.GetSizePixel().Height(); y++) + { + for (long x = 0; x < aGraphic.GetSizePixel().Width(); x++) + { + if (pReadAccess->HasPalette()) + { + Color aColor + = pReadAccess->GetPaletteColor(pReadAccess->GetPixelIndex(y, x)) + .GetColor(); + CPPUNIT_ASSERT_EQUAL(OUString("ff0000"), aColor.AsRGBHexString()); + } + else + { + Color aColor = pReadAccess->GetPixel(y, x).GetColor(); + if (sFormat != "jpg") + CPPUNIT_ASSERT_EQUAL(OUString("ff0000"), aColor.AsRGBHexString()); + } + } + } + } + } +} + } // namespace CPPUNIT_TEST_SUITE_REGISTRATION(GraphicTest); -- cgit