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

Chris Sherlock (via logerrit) logerrit at kemper.freedesktop.org
Thu Sep 2 06:54:20 UTC 2021


 vcl/qa/cppunit/outdev.cxx |   48 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

New commits:
commit 0dbe108ad80e30751be584ccb0e04bbcf35bdce1
Author:     Chris Sherlock <chris.sherlock79 at gmail.com>
AuthorDate: Thu Aug 26 03:40:13 2021 +1000
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Thu Sep 2 08:53:47 2021 +0200

    vcl: test bitmap color when using DrawBitmap()
    
    Change-Id: I0c4f9517ca4573300b6ef9237ac9536f19523ab7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121043
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/vcl/qa/cppunit/outdev.cxx b/vcl/qa/cppunit/outdev.cxx
index f5d814fe91fb..0f2039d27943 100644
--- a/vcl/qa/cppunit/outdev.cxx
+++ b/vcl/qa/cppunit/outdev.cxx
@@ -38,6 +38,7 @@ public:
     void testDrawInvertedBitmap();
     void testDrawBlackBitmap();
     void testDrawWhiteBitmap();
+    void testDrawGrayBitmap();
     void testDrawBitmap();
     void testDrawScaleBitmap();
     void testDrawScalePartBitmap();
@@ -63,6 +64,7 @@ public:
     CPPUNIT_TEST(testDrawInvertedBitmap);
     CPPUNIT_TEST(testDrawBlackBitmap);
     CPPUNIT_TEST(testDrawWhiteBitmap);
+    CPPUNIT_TEST(testDrawGrayBitmap);
     CPPUNIT_TEST(testDrawBitmap);
     CPPUNIT_TEST(testDrawScaleBitmap);
     CPPUNIT_TEST(testDrawScalePartBitmap);
@@ -211,6 +213,10 @@ void VclOutdevTest::testDrawBlackBitmap()
 {
     ScopedVclPtrInstance<VirtualDevice> pVDev;
     Bitmap aBitmap(Size(16, 16), vcl::PixelFormat::N24_BPP);
+    {
+        BitmapScopedWriteAccess pWriteAccess(aBitmap);
+        pWriteAccess->Erase(COL_RED);
+    }
 
     GDIMetaFile aMtf;
     aMtf.Record(pVDev.get());
@@ -242,6 +248,12 @@ void VclOutdevTest::testDrawBlackBitmap()
 
     pAction = aMtf.GetAction(4);
     CPPUNIT_ASSERT_EQUAL(MetaActionType::POP, pAction->GetType());
+
+    // test to see if the color is black
+    Bitmap aBlackBmp(pVDev->GetBitmap(Point(0, 0), Size(10, 10)));
+    Bitmap::ScopedReadAccess pReadAccess(aBlackBmp);
+    const BitmapColor& rColor = pReadAccess->GetColor(0, 0);
+    CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_BLACK), rColor);
 }
 
 void VclOutdevTest::testDrawWhiteBitmap()
@@ -279,6 +291,12 @@ void VclOutdevTest::testDrawWhiteBitmap()
 
     pAction = aMtf.GetAction(4);
     CPPUNIT_ASSERT_EQUAL(MetaActionType::POP, pAction->GetType());
+
+    // test to see if the color is white
+    Bitmap aWhiteBmp(pVDev->GetBitmap(Point(0, 0), Size(10, 10)));
+    Bitmap::ScopedReadAccess pReadAccess(aWhiteBmp);
+    const BitmapColor& rColor = pReadAccess->GetColor(0, 0);
+    CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_WHITE), rColor);
 }
 
 void VclOutdevTest::testDrawBitmap()
@@ -339,6 +357,36 @@ void VclOutdevTest::testDrawScalePartBitmap()
     CPPUNIT_ASSERT_EQUAL(Size(10, 10), pBmpScalePartAction->GetDestSize());
 }
 
+void VclOutdevTest::testDrawGrayBitmap()
+{
+    // draw a red 1x1 bitmap
+    Bitmap aBmp(Size(1, 1), vcl::PixelFormat::N24_BPP);
+    BitmapScopedWriteAccess pWriteAccess(aBmp);
+    pWriteAccess->Erase(COL_RED);
+
+    // check to ensure that the bitmap is red
+    {
+        Bitmap::ScopedReadAccess pReadAccess(aBmp);
+        const BitmapColor& rColor = pReadAccess->GetColor(0, 0);
+        CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_RED), rColor);
+    }
+
+    ScopedVclPtrInstance<VirtualDevice> pVDev;
+
+    pVDev->SetDrawMode(DrawModeFlags::GrayBitmap);
+    pVDev->DrawBitmap(Point(0, 0), Size(1, 1), Point(0, 0), Size(1, 1), aBmp, MetaActionType::BMP);
+
+    // should be a grey
+    Bitmap aVDevBmp(pVDev->GetBitmap(Point(), Size(1, 1)));
+    {
+        Bitmap::ScopedReadAccess pReadAccess(aVDevBmp);
+        const BitmapColor& rColor = pReadAccess->GetColor(0, 0);
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(0x26), sal_Int32(rColor.GetRed()));
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(0x26), sal_Int32(rColor.GetGreen()));
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(0x26), sal_Int32(rColor.GetBlue()));
+    }
+}
+
 void VclOutdevTest::testDrawTransformedBitmapEx()
 {
     // Create a virtual device, and connect a metafile to it.


More information about the Libreoffice-commits mailing list