[Libreoffice-commits] core.git: vcl/qa

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Fri May 18 03:26:52 UTC 2018


 vcl/qa/cppunit/GraphicTest.cxx |   65 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 58 insertions(+), 7 deletions(-)

New commits:
commit 8eb15f031003f6431d41853ff70e307b617d1a5a
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Thu May 17 15:15:01 2018 +0900

    Extend test for unloaded graphic
    
    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 <ci at libreoffice.org>
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

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 <cppunit/extensions/HelperMacros.h>
 #include <cppunit/plugin/TestPlugIn.h>
 
+#include <com/sun/star/beans/PropertyValue.hpp>
+
+#include <vcl/bitmapaccess.hxx>
 #include <vcl/graph.hxx>
 #include <vcl/graphicfilter.hxx>
 #include <tools/stream.hxx>
 #include <vcl/pngwrite.hxx>
 
+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<beans::PropertyValue> 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);


More information about the Libreoffice-commits mailing list