vcl/backendtest/outputdevice/common.cxx | 126 ++++++++++++++++++++++++++--- vcl/backendtest/outputdevice/rectangle.cxx | 58 +++++++++++++ vcl/inc/test/outputdevice.hxx | 11 ++ vcl/qa/cppunit/BackendTest.cxx | 40 +++++++++ 4 files changed, 225 insertions(+), 10 deletions(-)
New commits: commit 233f6762a1eaa07c5134c677f65e38932f9dfb13 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Fri Oct 18 10:10:31 2019 +0200 Commit: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> CommitDate: Fri Oct 18 10:10:31 2019 +0200 add "invert" tests to BackendTest All backend tests are not enabled yet as none of the backends pass, but testDrawInvertWithRectangle and testDrawInvertN50WithRectangle should pass with skia backend. testDrawInvertTrackFrameWithRectangle is more complicated as drawing an inverted dashed frame around overshoots outside of the rectangle area (as with gtk3 backend, maybe others too). This is something we need to fix or better yet to get rid of this invert mode. Change-Id: Ibc08ff99d91014c41324b67e8e984111bcd3c7ac diff --git a/vcl/backendtest/outputdevice/common.cxx b/vcl/backendtest/outputdevice/common.cxx index a885cac9088b..e701f5b61348 100644 --- a/vcl/backendtest/outputdevice/common.cxx +++ b/vcl/backendtest/outputdevice/common.cxx @@ -247,6 +247,92 @@ TestResult OutputDeviceTestCommon::checkAALines(Bitmap& rBitmap) return checkHorizontalVerticalDiagonalLines(rBitmap, constLineColor, 30); // 30 color values threshold delta } +void checkResult(TestResult eResult, TestResult & eTotal) +{ + if (eTotal == TestResult::Failed) + return; + + if (eResult == TestResult::Failed) + eTotal = TestResult::Failed; + + if (eResult == TestResult::PassedWithQuirks) + eTotal = TestResult::PassedWithQuirks; +} + +TestResult OutputDeviceTestCommon::checkInvertRectangle(Bitmap& aBitmap) +{ + TestResult aReturnValue = TestResult::Passed; + TestResult eResult; + + std::vector<Color> aExpected{ COL_WHITE, COL_WHITE }; + eResult = checkRectangles(aBitmap, aExpected); + checkResult(eResult, aReturnValue); + + eResult = checkFilled(aBitmap, tools::Rectangle(Point(2, 2), Size(8, 8)), COL_LIGHTCYAN); + checkResult(eResult, aReturnValue); + + eResult = checkFilled(aBitmap, tools::Rectangle(Point(10, 2), Size(8, 8)), COL_LIGHTMAGENTA); + checkResult(eResult, aReturnValue); + + eResult = checkFilled(aBitmap, tools::Rectangle(Point(2, 10), Size(8, 8)), COL_YELLOW); + checkResult(eResult, aReturnValue); + + eResult = checkFilled(aBitmap, tools::Rectangle(Point(10, 10), Size(8, 8)), COL_BLACK); + checkResult(eResult, aReturnValue); + + return aReturnValue; +} + +TestResult OutputDeviceTestCommon::checkChecker(Bitmap& rBitmap, sal_Int32 nStartX, sal_Int32 nEndX, sal_Int32 nStartY, sal_Int32 nEndY, std::vector<Color> const & rExpected) +{ + TestResult aReturnValue = TestResult::Passed; + + int choice = 0; + for (sal_Int32 y = nStartY; y <= nEndY; y+=2) + { + for (sal_Int32 x = nStartX; x <= nEndX; x+=2) + { + TestResult eResult = checkFilled(rBitmap, tools::Rectangle(Point(x, y), Size(2, 2)), rExpected[choice % 2]); + checkResult(eResult, aReturnValue); + choice++; + } + choice++; + } + return aReturnValue; +} + +TestResult OutputDeviceTestCommon::checkInvertN50Rectangle(Bitmap& aBitmap) +{ + TestResult aReturnValue = TestResult::Passed; + TestResult eResult; + + std::vector<Color> aExpected{ COL_WHITE, COL_WHITE }; + eResult = checkRectangles(aBitmap, aExpected); + checkResult(eResult, aReturnValue); + + eResult = checkChecker(aBitmap, 2, 8, 2, 8, { COL_LIGHTCYAN, COL_LIGHTRED }); + checkResult(eResult, aReturnValue); + eResult = checkChecker(aBitmap, 2, 8, 10, 16, { COL_YELLOW, COL_LIGHTBLUE }); + checkResult(eResult, aReturnValue); + eResult = checkChecker(aBitmap, 10, 16, 2, 8, { COL_LIGHTMAGENTA, COL_LIGHTGREEN }); + checkResult(eResult, aReturnValue); + eResult = checkChecker(aBitmap, 10, 16, 10, 16, { COL_BLACK, COL_WHITE }); + checkResult(eResult, aReturnValue); + + return aReturnValue; +} + +TestResult OutputDeviceTestCommon::checkInvertTrackFrameRectangle(Bitmap& aBitmap) +{ + TestResult aReturnValue = TestResult::Passed; + + std::vector<Color> aExpected + { + COL_WHITE, COL_WHITE + }; + return checkRectangles(aBitmap, aExpected); +} + TestResult OutputDeviceTestCommon::checkRectangle(Bitmap& aBitmap) { std::vector<Color> aExpected @@ -277,22 +363,42 @@ TestResult OutputDeviceTestCommon::checkFilledRectangle(Bitmap& aBitmap) return checkRectangles(aBitmap, aExpected); } +TestResult OutputDeviceTestCommon::checkFilled(Bitmap& rBitmap, tools::Rectangle aRectangle, Color aExpectedColor) +{ + BitmapScopedWriteAccess pAccess(rBitmap); + + TestResult aResult = TestResult::Passed; + int nNumberOfQuirks = 0; + int nNumberOfErrors = 0; + + for (long y = aRectangle.Top(); y < aRectangle.Top() + aRectangle.GetHeight(); y++) + { + for (long x = aRectangle.Left(); x < aRectangle.Left() + aRectangle.GetWidth(); x++) + { + checkValue(pAccess, x, y, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, false); + } + } + + if (nNumberOfQuirks > 0) + aResult = TestResult::PassedWithQuirks; + + if (nNumberOfErrors > 0) + aResult = TestResult::Failed; + + return aResult; +} + TestResult OutputDeviceTestCommon::checkRectangles(Bitmap& aBitmap, std::vector<Color>& aExpectedColors) { TestResult aReturnValue = TestResult::Passed; for (size_t i = 0; i < aExpectedColors.size(); i++) { - switch(checkRect(aBitmap, i, aExpectedColors[i])) - { - case TestResult::Failed: - return TestResult::Failed; - case TestResult::PassedWithQuirks: - aReturnValue = TestResult::PassedWithQuirks; - break; - default: - break; - } + TestResult eResult = checkRect(aBitmap, i, aExpectedColors[i]); + if (eResult == TestResult::Failed) + aReturnValue = TestResult::Failed; + if (eResult == TestResult::PassedWithQuirks && aReturnValue != TestResult::Failed) + aReturnValue = TestResult::PassedWithQuirks; } return aReturnValue; } diff --git a/vcl/backendtest/outputdevice/rectangle.cxx b/vcl/backendtest/outputdevice/rectangle.cxx index a491d67f5c52..f861cc2f05bb 100644 --- a/vcl/backendtest/outputdevice/rectangle.cxx +++ b/vcl/backendtest/outputdevice/rectangle.cxx @@ -21,6 +21,14 @@ namespace rRect.Right() - nOffset, rRect.Bottom() - nOffset)); } + + void drawInvertOffset(OutputDevice& rDevice, tools::Rectangle const & rRect, int nOffset, InvertFlags eFlags) + { + tools::Rectangle aRectangle(rRect.Left() + nOffset, rRect.Top() + nOffset, + rRect.Right() - nOffset, rRect.Bottom() - nOffset); + rDevice.Invert(aRectangle, eFlags); + } + } // end anonymous namespace Bitmap OutputDeviceTestRect::setupFilledRectangle() @@ -48,6 +56,56 @@ Bitmap OutputDeviceTestRect::setupRectangle(bool bEnableAA) return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); } +Bitmap OutputDeviceTestRect::setupInvert_NONE() +{ + initialSetup(20, 20, COL_WHITE); + + mpVirtualDevice->SetLineColor(); + mpVirtualDevice->SetFillColor(COL_LIGHTRED); + mpVirtualDevice->DrawRect(tools::Rectangle(Point(2, 2), Size(8, 8))); + mpVirtualDevice->SetFillColor(COL_LIGHTGREEN); + mpVirtualDevice->DrawRect(tools::Rectangle(Point(10, 2), Size(8, 8))); + mpVirtualDevice->SetFillColor(COL_LIGHTBLUE); + mpVirtualDevice->DrawRect(tools::Rectangle(Point(2, 10), Size(8, 8))); + + drawInvertOffset(*mpVirtualDevice, maVDRectangle, 2, InvertFlags::NONE); + + return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); +} + +Bitmap OutputDeviceTestRect::setupInvert_N50() +{ + initialSetup(20, 20, COL_WHITE); + + mpVirtualDevice->SetLineColor(); + mpVirtualDevice->SetFillColor(COL_LIGHTRED); + mpVirtualDevice->DrawRect(tools::Rectangle(Point(2, 2), Size(8, 8))); + mpVirtualDevice->SetFillColor(COL_LIGHTGREEN); + mpVirtualDevice->DrawRect(tools::Rectangle(Point(10, 2), Size(8, 8))); + mpVirtualDevice->SetFillColor(COL_LIGHTBLUE); + mpVirtualDevice->DrawRect(tools::Rectangle(Point(2, 10), Size(8, 8))); + + drawInvertOffset(*mpVirtualDevice, maVDRectangle, 2, InvertFlags::N50); + + return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); +} + +Bitmap OutputDeviceTestRect::setupInvert_TrackFrame() +{ + initialSetup(20, 20, COL_WHITE); + + mpVirtualDevice->SetLineColor(); + mpVirtualDevice->SetFillColor(COL_LIGHTRED); + mpVirtualDevice->DrawRect(tools::Rectangle(Point(2, 2), Size(8, 8))); + mpVirtualDevice->SetFillColor(COL_LIGHTGREEN); + mpVirtualDevice->DrawRect(tools::Rectangle(Point(10, 2), Size(8, 8))); + mpVirtualDevice->SetFillColor(COL_LIGHTBLUE); + mpVirtualDevice->DrawRect(tools::Rectangle(Point(2, 10), Size(8, 8))); + + drawInvertOffset(*mpVirtualDevice, maVDRectangle, 2, InvertFlags::TrackFrame); + + return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); +} }} // end namespace vcl::test diff --git a/vcl/inc/test/outputdevice.hxx b/vcl/inc/test/outputdevice.hxx index 966cd2b6b09c..dadc2fc70288 100644 --- a/vcl/inc/test/outputdevice.hxx +++ b/vcl/inc/test/outputdevice.hxx @@ -53,8 +53,16 @@ public: static TestResult checkAALines(Bitmap& rBitmap); static TestResult checkDiamond(Bitmap& rBitmap); + static TestResult checkInvertRectangle(Bitmap& rBitmap); + static TestResult checkInvertN50Rectangle(Bitmap& aBitmap); + static TestResult checkInvertTrackFrameRectangle(Bitmap& aBitmap); + static TestResult checkRectangles(Bitmap& rBitmap, std::vector<Color>& aExpectedColors); + static TestResult checkFilled(Bitmap& rBitmap, tools::Rectangle aRectangle, Color aExpectedColor); + static TestResult checkChecker(Bitmap& rBitmap, sal_Int32 nStartX, sal_Int32 nEndX, + sal_Int32 nStartY, sal_Int32 nEndY, std::vector<Color> const & rExpected); + static void createDiamondPoints(tools::Rectangle rRect, int nOffset, Point& rPoint1, Point& rPoint2, Point& rPoint3, Point& rPoint4); @@ -140,6 +148,9 @@ public: Bitmap setupRectangle(bool bEnableAA); Bitmap setupFilledRectangle(); + Bitmap setupInvert_NONE(); + Bitmap setupInvert_N50(); + Bitmap setupInvert_TrackFrame(); }; class VCL_DLLPUBLIC OutputDeviceTestPolygon : public OutputDeviceTestCommon diff --git a/vcl/qa/cppunit/BackendTest.cxx b/vcl/qa/cppunit/BackendTest.cxx index 741a3dfbd14d..7b3106bdfa59 100644 --- a/vcl/qa/cppunit/BackendTest.cxx +++ b/vcl/qa/cppunit/BackendTest.cxx @@ -322,6 +322,42 @@ public: #endif } + void testDrawInvertWithRectangle() + { + vcl::test::OutputDeviceTestRect aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupInvert_NONE(); + auto eResult = vcl::test::OutputDeviceTestCommon::checkInvertRectangle(aBitmap); + exportImage("05-01_invert_test-rectangle.png", aBitmap); + (void)eResult; +#ifndef SKIP_TEST_ASSERTS + CPPUNIT_ASSERT(eResult != vcl::test::TestResult::Failed); +#endif + } + + void testDrawInvertN50WithRectangle() + { + vcl::test::OutputDeviceTestRect aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupInvert_N50(); + auto eResult = vcl::test::OutputDeviceTestCommon::checkInvertN50Rectangle(aBitmap); + exportImage("05-02_invert_N50_test-rectangle.png", aBitmap); + (void)eResult; +#ifndef SKIP_TEST_ASSERTS + CPPUNIT_ASSERT(eResult != vcl::test::TestResult::Failed); +#endif + } + + void testDrawInvertTrackFrameWithRectangle() + { + vcl::test::OutputDeviceTestRect aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupInvert_TrackFrame(); + auto eResult = vcl::test::OutputDeviceTestCommon::checkInvertTrackFrameRectangle(aBitmap); + exportImage("05-03_invert_TrackFrame_test-rectangle.png", aBitmap); + (void)eResult; +#ifndef SKIP_TEST_ASSERTS + CPPUNIT_ASSERT(eResult != vcl::test::TestResult::Failed); +#endif + } + #undef SKIP_TEST_ASSERTS CPPUNIT_TEST_SUITE(BackendTest); @@ -352,6 +388,10 @@ public: CPPUNIT_TEST(testDrawDiamondWithLine); CPPUNIT_TEST(testDrawDiamondWithPolyline); + CPPUNIT_TEST(testDrawInvertWithRectangle); + CPPUNIT_TEST(testDrawInvertN50WithRectangle); + CPPUNIT_TEST(testDrawInvertTrackFrameWithRectangle); + CPPUNIT_TEST_SUITE_END(); }; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits