[Libreoffice-commits] core.git: vcl/CppunitTest_vcl_skia.mk vcl/inc vcl/Module_vcl.mk vcl/qa

Luboš Luňák (via logerrit) logerrit at kemper.freedesktop.org
Thu Oct 1 07:43:30 UTC 2020


 vcl/CppunitTest_vcl_skia.mk  |   51 ++++++++++++++++++++++++++++++
 vcl/Module_vcl.mk            |    2 +
 vcl/inc/skia/salbmp.hxx      |    6 +++
 vcl/qa/cppunit/skia/skia.cxx |   71 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 130 insertions(+)

New commits:
commit 9c850ca827486db3702699e5c2218842d7361b1b
Author:     Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Wed Sep 30 14:09:55 2020 +0200
Commit:     Luboš Luňák <l.lunak at collabora.com>
CommitDate: Thu Oct 1 09:42:52 2020 +0200

    add CppunitTest_vcl_skia to do Skia-specific tests
    
    Change-Id: I7b5c1637aaf0fc070391f08800cd44308b4db0b6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103710
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lunak at collabora.com>

diff --git a/vcl/CppunitTest_vcl_skia.mk b/vcl/CppunitTest_vcl_skia.mk
new file mode 100644
index 000000000000..094bba75fafa
--- /dev/null
+++ b/vcl/CppunitTest_vcl_skia.mk
@@ -0,0 +1,51 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,vcl_skia))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,vcl_skia, \
+	vcl/qa/cppunit/skia/skia \
+))
+
+$(eval $(call gb_CppunitTest_set_include,vcl_skia,\
+    $$(INCLUDE) \
+    -I$(SRCDIR)/vcl/inc \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,vcl_skia, \
+	basegfx \
+	comphelper \
+	cppu \
+	cppuhelper \
+	sal \
+	sfx \
+	subsequenttest \
+	test \
+	tl \
+	unotest \
+	vcl \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,vcl_skia, \
+	boost_headers \
+	$(if $(filter SKIA,$(BUILD_TYPE)),skia) \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,vcl_skia))
+
+$(eval $(call gb_CppunitTest_use_ure,vcl_skia))
+$(eval $(call gb_CppunitTest_use_vcl_non_headless,vcl_skia))
+
+$(eval $(call gb_CppunitTest_use_rdb,vcl_skia,services))
+
+$(eval $(call gb_CppunitTest_use_configuration,vcl_skia))
+
+# vim: set noet sw=4 ts=4:
diff --git a/vcl/Module_vcl.mk b/vcl/Module_vcl.mk
index 0e7bb1600b0a..436877015d47 100644
--- a/vcl/Module_vcl.mk
+++ b/vcl/Module_vcl.mk
@@ -209,6 +209,8 @@ $(eval $(call gb_Module_add_check_targets,vcl,\
     CppunitTest_vcl_type_serializer_test \
     $(call gb_Helper_optional, PDFIUM, \
         CppunitTest_vcl_pdfium_library_test) \
+    $(if $(filter SKIA,$(BUILD_TYPE)), \
+        CppunitTest_vcl_skia) \
 ))
 
 ifeq ($(USING_X11),TRUE)
diff --git a/vcl/inc/skia/salbmp.hxx b/vcl/inc/skia/salbmp.hxx
index 0f1a8b235164..00cd76ffd10e 100644
--- a/vcl/inc/skia/salbmp.hxx
+++ b/vcl/inc/skia/salbmp.hxx
@@ -86,6 +86,12 @@ public:
     void dump(const char* file) const;
 #endif
 
+    // These are to be used only by unittests.
+    bool unittestHasBuffer() const { return mBuffer.get(); }
+    bool unittestHasImage() const { return mImage.get(); }
+    bool unittestHasAlphaImage() const { return mAlphaImage.get(); }
+    bool unittestHasEraseColor() const { return mEraseColorSet; }
+
 private:
     // Reset the cached images allocated in GetSkImage()/GetAlphaSkImage().
     void ResetCachedData();
diff --git a/vcl/qa/cppunit/skia/skia.cxx b/vcl/qa/cppunit/skia/skia.cxx
new file mode 100644
index 000000000000..07f5a872ddbb
--- /dev/null
+++ b/vcl/qa/cppunit/skia/skia.cxx
@@ -0,0 +1,71 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <test/bootstrapfixture.hxx>
+
+#include <vcl/skia/SkiaHelper.hxx>
+#include <skia/salbmp.hxx>
+#include <vcl/bitmapaccess.hxx>
+
+// This tests backends that use Skia (i.e. intentionally not the svp one, which is the default.)
+// Note that you still may need to actually set for Skia to be used (see vcl/README.vars).
+// If Skia is not enabled, all tests will be silently skipped.
+namespace
+{
+class SkiaTest : public test::BootstrapFixture
+{
+public:
+    SkiaTest()
+        : test::BootstrapFixture(true, false)
+    {
+    }
+
+    void testBitmapErase();
+
+    CPPUNIT_TEST_SUITE(SkiaTest);
+    CPPUNIT_TEST(testBitmapErase);
+    CPPUNIT_TEST_SUITE_END();
+};
+
+void SkiaTest::testBitmapErase()
+{
+    if (!SkiaHelper::isVCLSkiaEnabled())
+        return;
+    Bitmap bitmap(Size(10, 10), 24);
+    SkiaSalBitmap* skiaBitmap = dynamic_cast<SkiaSalBitmap*>(bitmap.ImplGetSalBitmap().get());
+    CPPUNIT_ASSERT(skiaBitmap);
+    // Uninitialized bitmap.
+    CPPUNIT_ASSERT(!skiaBitmap->unittestHasBuffer());
+    CPPUNIT_ASSERT(!skiaBitmap->unittestHasImage());
+    CPPUNIT_ASSERT(!skiaBitmap->unittestHasAlphaImage());
+    CPPUNIT_ASSERT(!skiaBitmap->unittestHasEraseColor());
+    // Test that Bitmap.Erase() just sets erase color and doesn't allocate pixels.
+    bitmap.Erase(COL_RED);
+    skiaBitmap = dynamic_cast<SkiaSalBitmap*>(bitmap.ImplGetSalBitmap().get());
+    CPPUNIT_ASSERT(!skiaBitmap->unittestHasBuffer());
+    CPPUNIT_ASSERT(!skiaBitmap->unittestHasImage());
+    CPPUNIT_ASSERT(!skiaBitmap->unittestHasAlphaImage());
+    CPPUNIT_ASSERT(skiaBitmap->unittestHasEraseColor());
+    // Reading a pixel will create pixel data.
+    BitmapReadAccess access(bitmap);
+    CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_RED), access.GetColor(0, 0));
+    skiaBitmap = dynamic_cast<SkiaSalBitmap*>(bitmap.ImplGetSalBitmap().get());
+    CPPUNIT_ASSERT(skiaBitmap->unittestHasBuffer());
+    CPPUNIT_ASSERT(!skiaBitmap->unittestHasImage());
+    CPPUNIT_ASSERT(!skiaBitmap->unittestHasAlphaImage());
+    CPPUNIT_ASSERT(!skiaBitmap->unittestHasEraseColor());
+}
+
+} // namespace
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SkiaTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list