diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2021-11-12 21:06:48 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2021-11-13 10:19:57 +0100 |
commit | 9af1dc8a03958c32d4bd56804166293cc1031828 (patch) | |
tree | b5912dd04324a453dff1675818f18b77ca2e3447 | |
parent | a4485bd8e03ad4487fe47a4480a9aacfbaf61980 (diff) |
add more tests for OutputDev::DrawOutDev()
Test also copy to self and clipped copy.
Change-Id: I3f741e5035fe1f4fb224dc7fe4ba7aa5b4860dda
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125122
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
-rw-r--r-- | include/vcl/test/GraphicsRenderTests.hxx | 2 | ||||
-rw-r--r-- | vcl/backendtest/GraphicsRenderTests.cxx | 44 | ||||
-rw-r--r-- | vcl/backendtest/VisualBackendTest.cxx | 16 | ||||
-rw-r--r-- | vcl/backendtest/outputdevice/common.cxx | 73 | ||||
-rw-r--r-- | vcl/backendtest/outputdevice/outputdevice.cxx | 67 | ||||
-rw-r--r-- | vcl/inc/test/outputdevice.hxx | 4 | ||||
-rw-r--r-- | vcl/qa/cppunit/BackendTest.cxx | 27 |
7 files changed, 207 insertions, 26 deletions
diff --git a/include/vcl/test/GraphicsRenderTests.hxx b/include/vcl/test/GraphicsRenderTests.hxx index f1adcc6bb721..86266eebe317 100644 --- a/include/vcl/test/GraphicsRenderTests.hxx +++ b/include/vcl/test/GraphicsRenderTests.hxx @@ -99,6 +99,8 @@ class VCL_PLUGIN_PUBLIC GraphicsRenderTests void testClipPolyPolygon(); void testClipB2DPolyPolygon(); void testDrawOutDev(); + void testDrawOutDevScaledClipped(); + void testDrawOutDevSelf(); void testDashedLine(); void testLinearGradient(); void testLinearGradientAngled(); diff --git a/vcl/backendtest/GraphicsRenderTests.cxx b/vcl/backendtest/GraphicsRenderTests.cxx index fa48087fa03e..794910b0f045 100644 --- a/vcl/backendtest/GraphicsRenderTests.cxx +++ b/vcl/backendtest/GraphicsRenderTests.cxx @@ -985,6 +985,48 @@ void GraphicsRenderTests::testDrawOutDev() } } +void GraphicsRenderTests::testDrawOutDevScaledClipped() +{ + vcl::test::OutputDeviceTestAnotherOutDev aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupDrawOutDevScaledClipped(); + OUString aTestName = "testDrawOutDevScaledClipped"; + if (!SHOULD_ASSERT) + { + appendTestResult(aTestName, "SKIPPED"); + return; + } + vcl::test::TestResult eResult + = vcl::test::OutputDeviceTestAnotherOutDev::checkDrawOutDevScaledClipped(aBitmap); + appendTestResult(aTestName, returnTestStatus(eResult), + (m_aStoreResultantBitmap ? aBitmap : Bitmap())); + if (m_aStoreResultantBitmap) + { + BitmapEx aBitmapEx(aBitmap); + exportBitmapExToImage(m_aUserInstallPath + aTestName + ".png", aBitmapEx); + } +} + +void GraphicsRenderTests::testDrawOutDevSelf() +{ + vcl::test::OutputDeviceTestAnotherOutDev aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupDrawOutDevSelf(); + OUString aTestName = "testDrawOutDevSelf"; + if (!SHOULD_ASSERT) + { + appendTestResult(aTestName, "SKIPPED"); + return; + } + vcl::test::TestResult eResult + = vcl::test::OutputDeviceTestAnotherOutDev::checkDrawOutDevSelf(aBitmap); + appendTestResult(aTestName, returnTestStatus(eResult), + (m_aStoreResultantBitmap ? aBitmap : Bitmap())); + if (m_aStoreResultantBitmap) + { + BitmapEx aBitmapEx(aBitmap); + exportBitmapExToImage(m_aUserInstallPath + aTestName + ".png", aBitmapEx); + } +} + void GraphicsRenderTests::testDashedLine() { vcl::test::OutputDeviceTestLine aOutDevTest; @@ -2197,6 +2239,8 @@ void GraphicsRenderTests::runALLTests() testClipPolyPolygon(); testClipB2DPolyPolygon(); testDrawOutDev(); + testDrawOutDevScaledClipped(); + testDrawOutDevSelf(); testDashedLine(); testLinearGradient(); testLinearGradientAngled(); diff --git a/vcl/backendtest/VisualBackendTest.cxx b/vcl/backendtest/VisualBackendTest.cxx index 4ab745c73af0..4ba2cf63897b 100644 --- a/vcl/backendtest/VisualBackendTest.cxx +++ b/vcl/backendtest/VisualBackendTest.cxx @@ -764,7 +764,7 @@ public: } else if (mnTest % gnNumberOfTests == 10) { - std::vector<tools::Rectangle> aRegions = setupRegions(2, 1, nWidth, nHeight); + std::vector<tools::Rectangle> aRegions = setupRegions(2, 2, nWidth, nHeight); size_t index = 0; tools::Rectangle aRectangle = aRegions[index++]; @@ -776,6 +776,20 @@ public: } aRectangle = aRegions[index++]; { + vcl::test::OutputDeviceTestAnotherOutDev aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupDrawOutDevScaledClipped(); + assertAndSetBackground(vcl::test::OutputDeviceTestAnotherOutDev::checkDrawOutDevScaledClipped(aBitmap), aRectangle, rRenderContext); + drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext); + } + aRectangle = aRegions[index++]; + { + vcl::test::OutputDeviceTestAnotherOutDev aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupDrawOutDevSelf(); + assertAndSetBackground(vcl::test::OutputDeviceTestAnotherOutDev::checkDrawOutDevSelf(aBitmap), aRectangle, rRenderContext); + drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext); + } + aRectangle = aRegions[index++]; + { vcl::test::OutputDeviceTestLine aOutDevTest; Bitmap aBitmap = aOutDevTest.setupDashedLine(); assertAndSetBackground(vcl::test::OutputDeviceTestLine::checkDashedLine(aBitmap), aRectangle, rRenderContext); diff --git a/vcl/backendtest/outputdevice/common.cxx b/vcl/backendtest/outputdevice/common.cxx index fb220acea014..21a32635ab85 100644 --- a/vcl/backendtest/outputdevice/common.cxx +++ b/vcl/backendtest/outputdevice/common.cxx @@ -1506,6 +1506,79 @@ TestResult OutputDeviceTestCommon::checkLineJoin(Bitmap& rBitmap, basegfx::B2DLi return aResult; } +TestResult OutputDeviceTestAnotherOutDev::checkDrawOutDev(Bitmap& rBitmap) +{ + std::vector<Color> aExpected + { + constBackgroundColor, constBackgroundColor, + constFillColor, constFillColor, constFillColor, constFillColor, constFillColor + }; + return checkRectangles(rBitmap, aExpected); +} + +TestResult OutputDeviceTestAnotherOutDev::checkDrawOutDevScaledClipped(Bitmap& rBitmap) +{ + TestResult aReturnValue = TestResult::Passed; + TestResult eResult; + + eResult = checkRect(rBitmap, 0, constBackgroundColor); // outer line + checkResult(eResult, aReturnValue); + eResult = checkRect(rBitmap, 1, constBackgroundColor); // next outer line + checkResult(eResult, aReturnValue); + eResult = checkFilled(rBitmap, tools::Rectangle(Point(2, 2), Size(4, 8)), constBackgroundColor); + checkResult(eResult, aReturnValue); + eResult = checkFilled(rBitmap, tools::Rectangle(Point(6, 2), Size(4, 8)), constFillColor); + checkResult(eResult, aReturnValue); + + return aReturnValue; +} + +TestResult OutputDeviceTestAnotherOutDev::checkDrawOutDevSelf(Bitmap& rBitmap) +{ + TestResult aReturnValue = TestResult::Passed; + TestResult eResult; + + eResult = checkRect(rBitmap, 0, constBackgroundColor); // outer line + checkResult(eResult, aReturnValue); + eResult = checkFilled(rBitmap, tools::Rectangle(Point(1, 1), Size(4, 4)), constBackgroundColor); + checkResult(eResult, aReturnValue); + eResult = checkFilled(rBitmap, tools::Rectangle(Point(8, 8), Size(4, 4)), constBackgroundColor); + checkResult(eResult, aReturnValue); + + eResult = checkFilled(rBitmap, tools::Rectangle(Point(11, 1), Size(1, 1)), COL_YELLOW); + checkResult(eResult, aReturnValue); + eResult = checkFilled(rBitmap, tools::Rectangle(Point(7, 5), Size(1, 1)), COL_YELLOW); + checkResult(eResult, aReturnValue); + eResult = checkFilled(rBitmap, tools::Rectangle(Point(1, 11), Size(1, 1)), COL_YELLOW); + checkResult(eResult, aReturnValue); + + eResult = checkFilled(rBitmap, tools::Rectangle(Point(1, 5), Size(6, 6)), constFillColor); + checkResult(eResult, aReturnValue); + eResult = checkFilled(rBitmap, tools::Rectangle(Point(2, 6), Size(6, 6)), constFillColor); + checkResult(eResult, aReturnValue); + eResult = checkFilled(rBitmap, tools::Rectangle(Point(5, 1), Size(6, 4)), constFillColor); + checkResult(eResult, aReturnValue); + eResult = checkFilled(rBitmap, tools::Rectangle(Point(8, 2), Size(4, 6)), constFillColor); + checkResult(eResult, aReturnValue); + + return aReturnValue; +} + +TestResult OutputDeviceTestAnotherOutDev::checkXOR(Bitmap& rBitmap) +{ + Color xorColor( constBackgroundColor.GetRed() ^ constFillColor.GetRed(), + constBackgroundColor.GetGreen() ^ constFillColor.GetGreen(), + constBackgroundColor.GetBlue() ^ constFillColor.GetBlue()); + std::vector<Color> aExpected + { + constBackgroundColor, xorColor, + constBackgroundColor, constBackgroundColor, + constFillColor, constFillColor, + constFillColor + }; + return checkRectangles(rBitmap, aExpected); +} + } // end namespace vcl::test diff --git a/vcl/backendtest/outputdevice/outputdevice.cxx b/vcl/backendtest/outputdevice/outputdevice.cxx index 07d66ffb413c..ca58e006fd49 100644 --- a/vcl/backendtest/outputdevice/outputdevice.cxx +++ b/vcl/backendtest/outputdevice/outputdevice.cxx @@ -27,6 +27,48 @@ Bitmap OutputDeviceTestAnotherOutDev::setupDrawOutDev() return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); } + +Bitmap OutputDeviceTestAnotherOutDev::setupDrawOutDevScaledClipped() +{ + ScopedVclPtrInstance<VirtualDevice> pSourceDev; + Size aSourceSize(18, 18); + pSourceDev->SetOutputSizePixel(aSourceSize); + pSourceDev->SetBackground(Wallpaper(constFillColor)); + pSourceDev->Erase(); + + initialSetup(13, 13, constBackgroundColor); + + tools::Rectangle rectangle = maVDRectangle; + rectangle.SetLeft(rectangle.GetWidth() / 2); + mpVirtualDevice->SetClipRegion(vcl::Region(rectangle)); + + mpVirtualDevice->DrawOutDev(Point(2, 2), aSourceSize / 2, Point(), aSourceSize, *pSourceDev); + + return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); +} + +Bitmap OutputDeviceTestAnotherOutDev::setupDrawOutDevSelf() +{ + initialSetup(13, 13, constBackgroundColor); + + mpVirtualDevice->SetLineColor(); + mpVirtualDevice->SetFillColor(constFillColor); + + tools::Rectangle aDrawRectangle(maVDRectangle); + aDrawRectangle.shrink(3); + aDrawRectangle.Move( 2, -2 ); + mpVirtualDevice->DrawRect(aDrawRectangle); + mpVirtualDevice->SetLineColor(COL_YELLOW); + mpVirtualDevice->DrawPixel(aDrawRectangle.TopLeft() + Point(aDrawRectangle.GetWidth() - 1, 0)); + mpVirtualDevice->DrawPixel(aDrawRectangle.TopLeft() + Point(0,aDrawRectangle.GetHeight() - 1)); + + // Intentionally overlap a bit. + mpVirtualDevice->DrawOutDev(Point(1, 5), aDrawRectangle.GetSize(), + Point(5,1), aDrawRectangle.GetSize(), *mpVirtualDevice); + + return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); +} + Bitmap OutputDeviceTestAnotherOutDev::setupXOR() { initialSetup(13, 13, constBackgroundColor); @@ -65,31 +107,6 @@ Bitmap OutputDeviceTestAnotherOutDev::setupXOR() return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); } -TestResult OutputDeviceTestAnotherOutDev::checkDrawOutDev(Bitmap& rBitmap) -{ - std::vector<Color> aExpected - { - constBackgroundColor, constBackgroundColor, - constFillColor, constFillColor, constFillColor, constFillColor, constFillColor - }; - return checkRectangles(rBitmap, aExpected); -} - -TestResult OutputDeviceTestAnotherOutDev::checkXOR(Bitmap& rBitmap) -{ - Color xorColor( constBackgroundColor.GetRed() ^ constFillColor.GetRed(), - constBackgroundColor.GetGreen() ^ constFillColor.GetGreen(), - constBackgroundColor.GetBlue() ^ constFillColor.GetBlue()); - std::vector<Color> aExpected - { - constBackgroundColor, xorColor, - constBackgroundColor, constBackgroundColor, - constFillColor, constFillColor, - constFillColor - }; - return checkRectangles(rBitmap, aExpected); -} - } // end namespace vcl::test /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/test/outputdevice.hxx b/vcl/inc/test/outputdevice.hxx index d4ae96788736..f92e8d8fe13f 100644 --- a/vcl/inc/test/outputdevice.hxx +++ b/vcl/inc/test/outputdevice.hxx @@ -131,9 +131,13 @@ public: OutputDeviceTestAnotherOutDev() = default; Bitmap setupDrawOutDev(); + Bitmap setupDrawOutDevScaledClipped(); + Bitmap setupDrawOutDevSelf(); Bitmap setupXOR(); static TestResult checkDrawOutDev(Bitmap& rBitmap); + static TestResult checkDrawOutDevScaledClipped(Bitmap& rBitmap); + static TestResult checkDrawOutDevSelf(Bitmap& rBitmap); static TestResult checkXOR(Bitmap& rBitmap); }; diff --git a/vcl/qa/cppunit/BackendTest.cxx b/vcl/qa/cppunit/BackendTest.cxx index 922c6ba1ca0f..209c280d07c6 100644 --- a/vcl/qa/cppunit/BackendTest.cxx +++ b/vcl/qa/cppunit/BackendTest.cxx @@ -712,6 +712,31 @@ public: CPPUNIT_ASSERT(eResult != vcl::test::TestResult::Failed); } + void testDrawOutDevScaledClipped() + { + if (getDefaultDeviceBitCount() < 24) + return; + vcl::test::OutputDeviceTestAnotherOutDev aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupDrawOutDevScaledClipped(); + auto eResult + = vcl::test::OutputDeviceTestAnotherOutDev::checkDrawOutDevScaledClipped(aBitmap); + exportImage("10-02_draw_out_dev_scaled_clipped_test.png", aBitmap); + if (SHOULD_ASSERT) + CPPUNIT_ASSERT(eResult != vcl::test::TestResult::Failed); + } + + void testDrawOutDevSelf() + { + if (getDefaultDeviceBitCount() < 24) + return; + vcl::test::OutputDeviceTestAnotherOutDev aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupDrawOutDevSelf(); + auto eResult = vcl::test::OutputDeviceTestAnotherOutDev::checkDrawOutDevSelf(aBitmap); + exportImage("10-03_draw_out_dev_self_test.png", aBitmap); + if (SHOULD_ASSERT) + CPPUNIT_ASSERT(eResult != vcl::test::TestResult::Failed); + } + void testDashedLine() { if (getDefaultDeviceBitCount() < 24) @@ -1437,6 +1462,8 @@ public: CPPUNIT_TEST(testClipB2DPolyPolygon); CPPUNIT_TEST(testDrawOutDev); + CPPUNIT_TEST(testDrawOutDevScaledClipped); + CPPUNIT_TEST(testDrawOutDevSelf); CPPUNIT_TEST(testDashedLine); |