diff options
author | homeboy445 <akshitsan13@gmail.com> | 2021-08-06 20:44:39 +0530 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-10-31 18:47:39 +0100 |
commit | 3eeb77ece8db11e6c57864c507af5d24253a6276 (patch) | |
tree | 3a8130815e4a78cf370be04700794dbe4375ceaa /vcl/backendtest | |
parent | a8bf972230545cd0c0e5dcacb73f5fff804d22de (diff) |
backendtest: Drawing Open Polygon test
Change-Id: I57af3232ad5e83b649fdfac719dc2359e1bbb412
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120171
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/backendtest')
-rw-r--r-- | vcl/backendtest/GraphicsRenderTests.cxx | 105 | ||||
-rw-r--r-- | vcl/backendtest/outputdevice/common.cxx | 69 | ||||
-rw-r--r-- | vcl/backendtest/outputdevice/polygon.cxx | 13 | ||||
-rw-r--r-- | vcl/backendtest/outputdevice/polyline.cxx | 15 | ||||
-rw-r--r-- | vcl/backendtest/outputdevice/polyline_b2d.cxx | 13 | ||||
-rw-r--r-- | vcl/backendtest/outputdevice/polypolygon.cxx | 17 | ||||
-rw-r--r-- | vcl/backendtest/outputdevice/polypolygon_b2d.cxx | 16 |
7 files changed, 248 insertions, 0 deletions
diff --git a/vcl/backendtest/GraphicsRenderTests.cxx b/vcl/backendtest/GraphicsRenderTests.cxx index bf3932ffa2b1..0f360f2ae9c0 100644 --- a/vcl/backendtest/GraphicsRenderTests.cxx +++ b/vcl/backendtest/GraphicsRenderTests.cxx @@ -2015,6 +2015,106 @@ void GraphicsRenderTests::testDrawRectangleOnSize4096WithPolygonPolygonB2D() } } +void GraphicsRenderTests::testDrawOpenPolygonWithPolyLine() +{ + vcl::test::OutputDeviceTestPolyLine aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupOpenPolygon(); + OUString aTestName = "testDrawOpenPolygonWithPolyLine"; + if (!SHOULD_ASSERT) + { + appendTestResult(aTestName, "SKIPPED"); + return; + } + vcl::test::TestResult eResult = vcl::test::OutputDeviceTestCommon::checkOpenPolygon(aBitmap); + appendTestResult(aTestName, returnTestStatus(eResult), + (m_aStoreResultantBitmap ? aBitmap : Bitmap())); + if (m_aStoreResultantBitmap) + { + BitmapEx aBitmapEx(aBitmap); + exportBitmapExToImage(m_aUserInstallPath + aTestName + ".png", aBitmapEx); + } +} + +void GraphicsRenderTests::testDrawOpenPolygonWithPolyLineB2D() +{ + vcl::test::OutputDeviceTestPolyLineB2D aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupOpenPolygon(); + OUString aTestName = "testDrawOpenPolygonWithPolyLineB2D"; + if (!SHOULD_ASSERT) + { + appendTestResult(aTestName, "SKIPPED"); + return; + } + vcl::test::TestResult eResult = vcl::test::OutputDeviceTestCommon::checkOpenPolygon(aBitmap); + appendTestResult(aTestName, returnTestStatus(eResult), + (m_aStoreResultantBitmap ? aBitmap : Bitmap())); + if (m_aStoreResultantBitmap) + { + BitmapEx aBitmapEx(aBitmap); + exportBitmapExToImage(m_aUserInstallPath + aTestName + ".png", aBitmapEx); + } +} + +void GraphicsRenderTests::testDrawOpenPolygonWithPolygon() +{ + vcl::test::OutputDeviceTestPolygon aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupOpenPolygon(); + OUString aTestName = "testDrawOpenPolygonWithPolygon"; + if (!SHOULD_ASSERT) + { + appendTestResult(aTestName, "SKIPPED"); + return; + } + vcl::test::TestResult eResult = vcl::test::OutputDeviceTestCommon::checkOpenPolygon(aBitmap); + appendTestResult(aTestName, returnTestStatus(eResult), + (m_aStoreResultantBitmap ? aBitmap : Bitmap())); + if (m_aStoreResultantBitmap) + { + BitmapEx aBitmapEx(aBitmap); + exportBitmapExToImage(m_aUserInstallPath + aTestName + ".png", aBitmapEx); + } +} + +void GraphicsRenderTests::testDrawOpenPolygonWithPolyPolygon() +{ + vcl::test::OutputDeviceTestPolyPolygon aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupOpenPolygon(); + OUString aTestName = "testDrawOpenPolygonWithPolyPolygon"; + if (!SHOULD_ASSERT) + { + appendTestResult(aTestName, "SKIPPED"); + return; + } + vcl::test::TestResult eResult = vcl::test::OutputDeviceTestCommon::checkOpenPolygon(aBitmap); + appendTestResult(aTestName, returnTestStatus(eResult), + (m_aStoreResultantBitmap ? aBitmap : Bitmap())); + if (m_aStoreResultantBitmap) + { + BitmapEx aBitmapEx(aBitmap); + exportBitmapExToImage(m_aUserInstallPath + aTestName + ".png", aBitmapEx); + } +} + +void GraphicsRenderTests::testDrawOpenPolygonWithPolyPolygonB2D() +{ + vcl::test::OutputDeviceTestPolyPolygon aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupOpenPolygon(); + OUString aTestName = "testDrawOpenPolygonWithPolyPolygonB2D"; + if (!SHOULD_ASSERT) + { + appendTestResult(aTestName, "SKIPPED"); + return; + } + vcl::test::TestResult eResult = vcl::test::OutputDeviceTestCommon::checkOpenPolygon(aBitmap); + appendTestResult(aTestName, returnTestStatus(eResult), + (m_aStoreResultantBitmap ? aBitmap : Bitmap())); + if (m_aStoreResultantBitmap) + { + BitmapEx aBitmapEx(aBitmap); + exportBitmapExToImage(m_aUserInstallPath + aTestName + ".png", aBitmapEx); + } +} + void GraphicsRenderTests::runALLTests() { testDrawRectWithRectangle(); @@ -2112,6 +2212,11 @@ void GraphicsRenderTests::runALLTests() testDrawRectangleOnSize4096WithPolyPolygon(); testDrawRectangleOnSize1028WithPolyPolygonB2D(); testDrawRectangleOnSize4096WithPolygonPolygonB2D(); + testDrawOpenPolygonWithPolyLine(); + testDrawOpenPolygonWithPolyLineB2D(); + testDrawOpenPolygonWithPolygon(); + testDrawOpenPolygonWithPolyPolygon(); + testDrawOpenPolygonWithPolyPolygonB2D(); } void GraphicsRenderTests::appendTestResult(OUString aTestName, OUString aTestStatus, diff --git a/vcl/backendtest/outputdevice/common.cxx b/vcl/backendtest/outputdevice/common.cxx index 9e9f67bd9513..8a5b80cb8dec 100644 --- a/vcl/backendtest/outputdevice/common.cxx +++ b/vcl/backendtest/outputdevice/common.cxx @@ -18,6 +18,7 @@ namespace vcl::test { namespace { + int deltaColor(BitmapColor aColor1, BitmapColor aColor2) { int deltaR = std::abs(aColor1.GetRed() - aColor2.GetRed()); @@ -719,6 +720,19 @@ tools::Polygon OutputDeviceTestCommon::createClosedBezierLoop(const tools::Recta return aPolygon; } +basegfx::B2DPolygon OutputDeviceTestCommon::createOpenPolygon(tools::Rectangle& rRect, int nOffset) +{ + int nMidOffset = rRect.GetWidth() / 2; + basegfx::B2DPolygon aPolygon{ + basegfx::B2DPoint(rRect.Left() + nOffset - (nOffset + 1) / 2, rRect.Top() + nOffset - 1), + basegfx::B2DPoint(rRect.Left() + nOffset - (nOffset + 1) / 2, rRect.Bottom() - nOffset + 1), + basegfx::B2DPoint(rRect.Right() - nMidOffset - nOffset / 3, rRect.Bottom() - nOffset + 1), + basegfx::B2DPoint(rRect.Right() - nMidOffset - nOffset / 3, rRect.Top() + nOffset - 1), + }; + aPolygon.setClosed(false); + return aPolygon; +} + TestResult OutputDeviceTestCommon::checkDropShape(Bitmap& rBitmap, bool aEnableAA) { BitmapScopedWriteAccess pAccess(rBitmap); @@ -1095,6 +1109,61 @@ TestResult OutputDeviceTestCommon::checkEvenOddRuleInIntersectingRecs(Bitmap& rB return aReturnValue; } +TestResult OutputDeviceTestCommon::checkOpenPolygon(Bitmap& rBitmap, bool aEnableAA) +{ + std::vector<Color> aExpected = { constBackgroundColor, constLineColor, constLineColor }; + + BitmapScopedWriteAccess pAccess(rBitmap); + + TestResult aResult = TestResult::Passed; + int nNumberOfQuirks = 0; + int nNumberOfErrors = 0; + + for (size_t aLayerNumber = 0; aLayerNumber < aExpected.size(); aLayerNumber++) + { + tools::Long startX = aLayerNumber + 1, endX = pAccess->Width() / 2 - aLayerNumber; + tools::Long startY = aLayerNumber + 2, endY = pAccess->Height() - aLayerNumber - 3; + + for (tools::Long ptX = startX; ptX <= endX; ++ptX) + { + if (aEnableAA) + { + checkValueAA(pAccess, ptX, endY - (aLayerNumber == 2 ? 2 : 0), + aExpected[aLayerNumber], nNumberOfQuirks, nNumberOfErrors); + } + else + { + checkValue(pAccess, ptX, endY - (aLayerNumber == 2 ? 2 : 0), + aExpected[aLayerNumber], nNumberOfQuirks, nNumberOfErrors, true); + } + } + for (tools::Long ptY = startY + (aLayerNumber == 2 ? 2 : 0); + ptY <= endY - (aLayerNumber == 2 ? 2 : 0); ++ptY) + { + if (aEnableAA) + { + checkValueAA(pAccess, startX, ptY, aExpected[aLayerNumber], nNumberOfQuirks, + nNumberOfErrors); + checkValueAA(pAccess, endX, ptY, aExpected[aLayerNumber], nNumberOfQuirks, + nNumberOfErrors); + } + else + { + checkValue(pAccess, startX, ptY, aExpected[aLayerNumber], nNumberOfQuirks, + nNumberOfErrors, true); + checkValue(pAccess, endX, ptY, aExpected[aLayerNumber], nNumberOfQuirks, + nNumberOfErrors, true); + } + } + } + + if (nNumberOfQuirks > 0) + aResult = TestResult::PassedWithQuirks; + if (nNumberOfErrors > 0) + aResult = TestResult::Failed; + return aResult; +} + // Check 'count' pixels from (x,y) in (addX,addY) direction, the color values must not decrease. static bool checkGradient(BitmapScopedWriteAccess& pAccess, int x, int y, int count, int addX, int addY) { diff --git a/vcl/backendtest/outputdevice/polygon.cxx b/vcl/backendtest/outputdevice/polygon.cxx index 6b52ccabf72c..051c0d893cb1 100644 --- a/vcl/backendtest/outputdevice/polygon.cxx +++ b/vcl/backendtest/outputdevice/polygon.cxx @@ -239,6 +239,19 @@ Bitmap OutputDeviceTestPolygon::setupRectangleOnSize4096() return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); } +Bitmap OutputDeviceTestPolygon::setupOpenPolygon() +{ + initialSetup(21, 21, constBackgroundColor); + + mpVirtualDevice->SetLineColor(constLineColor); + mpVirtualDevice->SetFillColor(); + + mpVirtualDevice->DrawPolygon(tools::Polygon(OutputDeviceTestCommon::createOpenPolygon(maVDRectangle))); + mpVirtualDevice->DrawPolygon(tools::Polygon(OutputDeviceTestCommon::createOpenPolygon(maVDRectangle, 7))); + + return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); +} + } // end namespace vcl::test /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/backendtest/outputdevice/polyline.cxx b/vcl/backendtest/outputdevice/polyline.cxx index 86f9de6306b4..da5a4a6474c6 100644 --- a/vcl/backendtest/outputdevice/polyline.cxx +++ b/vcl/backendtest/outputdevice/polyline.cxx @@ -213,6 +213,21 @@ Bitmap OutputDeviceTestPolyLine::setupRectangleOnSize4096() return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); } +Bitmap OutputDeviceTestPolyLine::setupOpenPolygon() +{ + initialSetup(21, 21, constBackgroundColor); + + mpVirtualDevice->SetLineColor(constLineColor); + mpVirtualDevice->SetFillColor(); + + mpVirtualDevice->DrawPolyLine( + tools::Polygon(OutputDeviceTestCommon::createOpenPolygon(maVDRectangle))); + mpVirtualDevice->DrawPolyLine( + tools::Polygon(OutputDeviceTestCommon::createOpenPolygon(maVDRectangle, 7))); + + return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); +} + } // end namespace vcl::test /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/backendtest/outputdevice/polyline_b2d.cxx b/vcl/backendtest/outputdevice/polyline_b2d.cxx index cef4c6e66aeb..1284a3fa8074 100644 --- a/vcl/backendtest/outputdevice/polyline_b2d.cxx +++ b/vcl/backendtest/outputdevice/polyline_b2d.cxx @@ -162,6 +162,19 @@ Bitmap OutputDeviceTestPolyLineB2D::setupRectangleOnSize4096() return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); } +Bitmap OutputDeviceTestPolyLineB2D::setupOpenPolygon() +{ + initialSetup(21, 21, constBackgroundColor); + + mpVirtualDevice->SetLineColor(constLineColor); + mpVirtualDevice->SetFillColor(); + + mpVirtualDevice->DrawPolyLine(OutputDeviceTestCommon::createOpenPolygon(maVDRectangle)); + mpVirtualDevice->DrawPolyLine(OutputDeviceTestCommon::createOpenPolygon(maVDRectangle, 7)); + + return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); +} + } // end namespace vcl::test /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/backendtest/outputdevice/polypolygon.cxx b/vcl/backendtest/outputdevice/polypolygon.cxx index 8c96f2d33447..e1abb2f9014b 100644 --- a/vcl/backendtest/outputdevice/polypolygon.cxx +++ b/vcl/backendtest/outputdevice/polypolygon.cxx @@ -190,6 +190,23 @@ Bitmap OutputDeviceTestPolyPolygon::setupRectangleOnSize4096() return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); } +Bitmap OutputDeviceTestPolyPolygon::setupOpenPolygon() +{ + initialSetup(21, 21, constBackgroundColor); + + mpVirtualDevice->SetLineColor(constLineColor); + mpVirtualDevice->SetFillColor(); + + tools::PolyPolygon aPolyPolygon; + aPolyPolygon.Insert(tools::Polygon(OutputDeviceTestCommon::createOpenPolygon(maVDRectangle))); + aPolyPolygon.Insert( + tools::Polygon(OutputDeviceTestCommon::createOpenPolygon(maVDRectangle, 7))); + + mpVirtualDevice->DrawPolyPolygon(aPolyPolygon); + + return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); +} + } // end namespace vcl::test /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/backendtest/outputdevice/polypolygon_b2d.cxx b/vcl/backendtest/outputdevice/polypolygon_b2d.cxx index 432fc429b6e5..59391abe1922 100644 --- a/vcl/backendtest/outputdevice/polypolygon_b2d.cxx +++ b/vcl/backendtest/outputdevice/polypolygon_b2d.cxx @@ -178,6 +178,22 @@ Bitmap OutputDeviceTestPolyPolygonB2D::setupRectangleOnSize4096() return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); } +Bitmap OutputDeviceTestPolyPolygonB2D::setupOpenPolygon() +{ + initialSetup(21, 21, constBackgroundColor); + + mpVirtualDevice->SetLineColor(constLineColor); + mpVirtualDevice->SetFillColor(); + + basegfx::B2DPolyPolygon aPolyPolygon; + aPolyPolygon.append(OutputDeviceTestCommon::createOpenPolygon(maVDRectangle)); + aPolyPolygon.append(OutputDeviceTestCommon::createOpenPolygon(maVDRectangle, 7)); + + mpVirtualDevice->DrawPolyPolygon(aPolyPolygon); + + return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); +} + } // end namespace vcl::test /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |