summaryrefslogtreecommitdiff
path: root/vcl/qa/cppunit/outdev.cxx
diff options
context:
space:
mode:
authorChris Sherlock <chris.sherlock79@gmail.com>2021-09-03 16:24:19 +1000
committerMike Kaganski <mike.kaganski@collabora.com>2021-09-05 06:18:10 +0200
commitdca138469467a7935550cf1af34b630b3dd7fd60 (patch)
treed4ea141392e0cac3ac90b6267b2781ab641876ef /vcl/qa/cppunit/outdev.cxx
parent567aa49969e0e947f109e465c2006fa8451d7a58 (diff)
vcl: unit tests for Bitmap::Crop() and Bitmap::GetDownsampledBitmap()
Bitmap::Crop() test: - If crop rectangle is fully outside of the bitmap, then return false and don't change the bitmap. - If crop rectangle is same size as bitmap, then return false - If crop rectangle is larger than the bitmap, then return false - If crop rectangle partially overlaps the bitmap, return true and crop the bitmap - If crop rectangle is fully within the bitmap, then return true and crop the bitmap Bitmap::GetDownsampledBitmap() tested to check when empty or not. Change-Id: Id2a6f739fdb1961748ce218862e628dfa8512122 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121546 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'vcl/qa/cppunit/outdev.cxx')
-rw-r--r--vcl/qa/cppunit/outdev.cxx71
1 files changed, 71 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/outdev.cxx b/vcl/qa/cppunit/outdev.cxx
index 1857b4555c8a..2df0df7d8a69 100644
--- a/vcl/qa/cppunit/outdev.cxx
+++ b/vcl/qa/cppunit/outdev.cxx
@@ -44,6 +44,7 @@ public:
void testDrawScalePartBitmap();
void testDrawTransformedBitmapEx();
void testDrawTransformedBitmapExFlip();
+ void testCroppedDownsampledBitmap();
void testRTL();
void testRTLGuard();
void testDefaultFillColor();
@@ -76,6 +77,7 @@ public:
CPPUNIT_TEST(testGetReadableFontColorWindow);
CPPUNIT_TEST(testDrawTransformedBitmapEx);
CPPUNIT_TEST(testDrawTransformedBitmapExFlip);
+ CPPUNIT_TEST(testCroppedDownsampledBitmap);
CPPUNIT_TEST(testRTL);
CPPUNIT_TEST(testRTLGuard);
CPPUNIT_TEST(testDefaultFillColor);
@@ -510,6 +512,75 @@ void VclOutdevTest::testDrawTransformedBitmapExFlip()
CPPUNIT_ASSERT_EQUAL_MESSAGE(ss.str(), COL_BLACK, Color(aColor));
}
+namespace
+{
+class DownsampleBitmapTester : public OutputDevice
+{
+public:
+ DownsampleBitmapTester()
+ : OutputDevice(OUTDEV_VIRDEV)
+ , maBitmap(Bitmap(Size(16, 16), vcl::PixelFormat::N24_BPP))
+ {
+ SetDPIX(96);
+ SetDPIY(96);
+ }
+
+ bool AcquireGraphics() const { return true; }
+ void ReleaseGraphics(bool) {}
+ bool UsePolyPolygonForComplexGradient() { return false; }
+
+ Bitmap testCropFullyOutsideBounds()
+ {
+ return GetDownsampledBitmap(Size(10, 10), Point(20, 20), Size(5, 5), maBitmap, 72, 72);
+ }
+
+ Bitmap testCropSameSize()
+ {
+ return GetDownsampledBitmap(Size(10, 10), Point(0, 0), maBitmap.GetSizePixel(), maBitmap,
+ 72, 72);
+ }
+
+ Bitmap testFullyOvercrop()
+ {
+ return GetDownsampledBitmap(Size(10, 10), Point(0, 0), Size(100, 100), maBitmap, 72, 72);
+ }
+
+ Bitmap testPartiallyOvercrop()
+ {
+ return GetDownsampledBitmap(Size(10, 10), Point(10, 10), Size(100, 100), maBitmap, 72, 72);
+ }
+
+private:
+ Bitmap maBitmap;
+};
+}
+
+void VclOutdevTest::testCroppedDownsampledBitmap()
+{
+ ScopedVclPtrInstance<DownsampleBitmapTester> pTester;
+
+ {
+ Bitmap aDownsampledBmp(pTester->testCropFullyOutsideBounds());
+ CPPUNIT_ASSERT_MESSAGE("Crop was fully outside of bitmap bounds",
+ aDownsampledBmp.IsEmpty());
+ }
+
+ {
+ Bitmap aDownsampledBmp(pTester->testCropSameSize());
+ CPPUNIT_ASSERT_MESSAGE("Crop same size as bitmap", !aDownsampledBmp.IsEmpty());
+ }
+
+ {
+ Bitmap aDownsampledBmp(pTester->testFullyOvercrop());
+ CPPUNIT_ASSERT_MESSAGE("Crop larger than bitmap", !aDownsampledBmp.IsEmpty());
+ }
+
+ {
+ Bitmap aDownsampledBmp(pTester->testPartiallyOvercrop());
+ CPPUNIT_ASSERT_MESSAGE("Crop partially overcrops bitmap", !aDownsampledBmp.IsEmpty());
+ }
+}
+
void VclOutdevTest::testRTL()
{
ScopedVclPtrInstance<vcl::Window> pWindow(nullptr, WB_APP | WB_STDWORK);