summaryrefslogtreecommitdiff
path: root/vcl/backendtest
diff options
context:
space:
mode:
authorhomeboy445 <akshitsan13@gmail.com>2021-07-17 17:46:10 +0530
committerTomaž Vajngerl <quikee@gmail.com>2021-08-26 07:07:46 +0200
commitdbca6679aa40f65a67264f416d20d1434f6a926d (patch)
tree0c92c373cde28eff98c43e5c4c37263f4dab4b7d /vcl/backendtest
parentc3a7edad85ec22fa4dac372da9e0b36d02efbfc4 (diff)
backendtest: Intersecting Rectangles Drawing test
This test intends to test the even-odd filling rule by testing if the intersecting rectangles have been filled accordingly to the rule or not. Change-Id: I0fb7f115a25476cc38e8bec5cd02737aea3c0316 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119098 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/backendtest')
-rw-r--r--vcl/backendtest/GraphicsRenderTests.cxx44
-rw-r--r--vcl/backendtest/outputdevice/common.cxx48
-rw-r--r--vcl/backendtest/outputdevice/polypolygon.cxx87
-rw-r--r--vcl/backendtest/outputdevice/polypolygon_b2d.cxx77
4 files changed, 256 insertions, 0 deletions
diff --git a/vcl/backendtest/GraphicsRenderTests.cxx b/vcl/backendtest/GraphicsRenderTests.cxx
index 1b98dead0264..263d37cf6d3f 100644
--- a/vcl/backendtest/GraphicsRenderTests.cxx
+++ b/vcl/backendtest/GraphicsRenderTests.cxx
@@ -1503,6 +1503,48 @@ void GraphicsRenderTests::testTextDrawing()
}
}
+void GraphicsRenderTests::testEvenOddRuleInIntersectingRectsWithPolyPolygon()
+{
+ vcl::test::OutputDeviceTestPolyPolygon aOutDevTest;
+ Bitmap aBitmap = aOutDevTest.setupIntersectingRectangles();
+ OUString aTestName = "testEvenOddRuleInIntersectingRectsWithPolyPolygon";
+ if (!SHOULD_ASSERT)
+ {
+ appendTestResult(aTestName, "SKIPPED");
+ return;
+ }
+ vcl::test::TestResult eResult
+ = vcl::test::OutputDeviceTestLine::checkEvenOddRuleInIntersectingRecs(aBitmap);
+ appendTestResult(aTestName, returnTestStatus(eResult),
+ (m_aStoreResultantBitmap ? aBitmap : Bitmap()));
+ if (m_aStoreResultantBitmap)
+ {
+ BitmapEx aBitmapEx(aBitmap);
+ exportBitmapExToImage(m_aUserInstallPath + aTestName + ".png", aBitmapEx);
+ }
+}
+
+void GraphicsRenderTests::testEvenOddRuleInIntersectingRectsWithPolyPolygonB2D()
+{
+ vcl::test::OutputDeviceTestPolyPolygonB2D aOutDevTest;
+ Bitmap aBitmap = aOutDevTest.setupIntersectingRectangles();
+ OUString aTestName = "testEvenOddRuleInIntersectingRectsWithPolyPolygonB2D";
+ if (!SHOULD_ASSERT)
+ {
+ appendTestResult(aTestName, "SKIPPED");
+ return;
+ }
+ vcl::test::TestResult eResult
+ = vcl::test::OutputDeviceTestLine::checkEvenOddRuleInIntersectingRecs(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();
@@ -1575,6 +1617,8 @@ void GraphicsRenderTests::runALLTests()
testClosedBezierWithPolygon();
testFilledAsymmetricalDropShape();
testTextDrawing();
+ testEvenOddRuleInIntersectingRectsWithPolyPolygon();
+ testEvenOddRuleInIntersectingRectsWithPolyPolygonB2D();
}
void GraphicsRenderTests::appendTestResult(OUString aTestName, OUString aTestStatus,
diff --git a/vcl/backendtest/outputdevice/common.cxx b/vcl/backendtest/outputdevice/common.cxx
index b548571e22bb..2aa7de78a294 100644
--- a/vcl/backendtest/outputdevice/common.cxx
+++ b/vcl/backendtest/outputdevice/common.cxx
@@ -968,6 +968,54 @@ TestResult OutputDeviceTestCommon::checkTextLocation(Bitmap& rBitmap)
return aResult;
}
+TestResult OutputDeviceTestCommon::checkIntersectingRecs(Bitmap& rBitmap, int aLayerNumber,
+ Color aExpected)
+{
+ BitmapScopedWriteAccess pAccess(rBitmap);
+
+ TestResult aResult = TestResult::Passed;
+ int nNumberOfQuirks = 0;
+ int nNumberOfErrors = 0;
+
+ for (int x = 4; x <= 19; ++x)
+ {
+ checkValue(pAccess, x, aLayerNumber, aExpected, nNumberOfQuirks, nNumberOfErrors, true);
+ }
+
+ if (nNumberOfQuirks > 0)
+ aResult = TestResult::PassedWithQuirks;
+ if (nNumberOfErrors > 0)
+ aResult = TestResult::Failed;
+ return aResult;
+}
+
+TestResult OutputDeviceTestCommon::checkEvenOddRuleInIntersectingRecs(Bitmap& rBitmap)
+{
+ /*
+ The even-odd rule would be tested via the below pattern as layers both of the
+ constFillColor & constBackgroundColor appears in an even-odd fashion.
+ */
+ std::vector<Color> aExpectedColors
+ = { constBackgroundColor, constBackgroundColor, constLineColor, constFillColor,
+ constFillColor, constLineColor, constBackgroundColor, constBackgroundColor,
+ constLineColor, constFillColor, constFillColor, constLineColor,
+ constBackgroundColor, constBackgroundColor, constLineColor, constFillColor,
+ constFillColor, constLineColor, constBackgroundColor, constBackgroundColor,
+ constLineColor, constFillColor, constLineColor };
+
+ TestResult aReturnValue = TestResult::Passed;
+ for (size_t i = 0; i < aExpectedColors.size(); i++)
+ {
+ TestResult eResult = checkIntersectingRecs(rBitmap, i, aExpectedColors[i]);
+
+ if (eResult == TestResult::Failed)
+ aReturnValue = TestResult::Failed;
+ if (eResult == TestResult::PassedWithQuirks && aReturnValue != TestResult::Failed)
+ aReturnValue = TestResult::PassedWithQuirks;
+ }
+ return aReturnValue;
+}
+
// 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/polypolygon.cxx b/vcl/backendtest/outputdevice/polypolygon.cxx
index 9151bd28ff3f..642e0ce8fc61 100644
--- a/vcl/backendtest/outputdevice/polypolygon.cxx
+++ b/vcl/backendtest/outputdevice/polypolygon.cxx
@@ -65,6 +65,93 @@ Bitmap OutputDeviceTestPolyPolygon::setupFilledRectangle(bool useLineColor)
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
+Bitmap OutputDeviceTestPolyPolygon::setupIntersectingRectangles()
+{
+ initialSetup(24, 24, constBackgroundColor);
+
+ mpVirtualDevice->SetLineColor(constLineColor);
+ mpVirtualDevice->SetFillColor(constFillColor);
+
+ tools::PolyPolygon aPolyPolygon(4);
+
+ int nOffset = 2, nFix = 1;
+ tools::Polygon aPolygon1(4), aPolygon2(4), aPolygon3(4), aPolygon4(4);
+
+ /*
+ The intersection between different rectangles has been
+ acheived by stacking them on top of each other and decreasing and
+ increasing the top and bottom offset accordingly to the rectangle
+ keeping the left and the right offset intact which in turn coalesced
+ them to each other helping in acheiving multiple intersecting rectangles.
+ The desired color fill pattern is then achieved by setting the fill
+ color which in turn would fill the shape with the provided color
+ in accordance to the even-odd filling rule.
+ */
+
+ //Rect - 1
+ aPolygon1.SetPoint(
+ Point(maVDRectangle.Left() + nOffset + nFix, maVDRectangle.Top() + (nOffset - 1) + nFix),
+ 0);
+ aPolygon1.SetPoint(Point(maVDRectangle.Right() - (nOffset + 2) + nFix,
+ maVDRectangle.Top() + (nOffset - 1) + nFix),
+ 1);
+ aPolygon1.SetPoint(Point(maVDRectangle.Right() - (nOffset + 2) + nFix,
+ maVDRectangle.Bottom() - (nOffset + 8) + nFix),
+ 2);
+ aPolygon1.SetPoint(
+ Point(maVDRectangle.Left() + nOffset + nFix, maVDRectangle.Bottom() - (nOffset + 8) + nFix),
+ 3);
+ aPolyPolygon.Insert(aPolygon1);
+
+ //Rect - 2
+ aPolygon2.SetPoint(
+ Point(maVDRectangle.Left() + nOffset + nFix, maVDRectangle.Top() + (nOffset + 2) + nFix),
+ 0);
+ aPolygon2.SetPoint(Point(maVDRectangle.Right() - (nOffset + 2) + nFix,
+ maVDRectangle.Top() + (nOffset + 2) + nFix),
+ 1);
+ aPolygon2.SetPoint(Point(maVDRectangle.Right() - (nOffset + 2) + nFix,
+ maVDRectangle.Bottom() - (nOffset + 5) + nFix),
+ 2);
+ aPolygon2.SetPoint(
+ Point(maVDRectangle.Left() + nOffset + nFix, maVDRectangle.Bottom() - (nOffset + 5) + nFix),
+ 3);
+ aPolyPolygon.Insert(aPolygon2);
+
+ //Rect - 3
+ aPolygon3.SetPoint(
+ Point(maVDRectangle.Left() + nOffset + nFix, maVDRectangle.Top() + (nOffset + 5) + nFix),
+ 0);
+ aPolygon3.SetPoint(Point(maVDRectangle.Right() - (nOffset + 2) + nFix,
+ maVDRectangle.Top() + (nOffset + 5) + nFix),
+ 1);
+ aPolygon3.SetPoint(Point(maVDRectangle.Right() - (nOffset + 2) + nFix,
+ maVDRectangle.Bottom() - (nOffset + 2) + nFix),
+ 2);
+ aPolygon3.SetPoint(
+ Point(maVDRectangle.Left() + nOffset + nFix, maVDRectangle.Bottom() - (nOffset + 2) + nFix),
+ 3);
+ aPolyPolygon.Insert(aPolygon3);
+
+ //Rect - 4
+ aPolygon4.SetPoint(
+ Point(maVDRectangle.Left() + nOffset + nFix, maVDRectangle.Top() + (nOffset + 8) + nFix),
+ 0);
+ aPolygon4.SetPoint(Point(maVDRectangle.Right() - (nOffset + 2) + nFix,
+ maVDRectangle.Top() + (nOffset + 8) + nFix),
+ 1);
+ aPolygon4.SetPoint(Point(maVDRectangle.Right() - (nOffset + 2) + nFix,
+ maVDRectangle.Bottom() - nOffset + nFix),
+ 2);
+ aPolygon4.SetPoint(
+ Point(maVDRectangle.Left() + nOffset + nFix, maVDRectangle.Bottom() - nOffset + nFix), 3);
+ aPolyPolygon.Insert(aPolygon4);
+
+ 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 737cfae195f2..ef8ee6f0390e 100644
--- a/vcl/backendtest/outputdevice/polypolygon_b2d.cxx
+++ b/vcl/backendtest/outputdevice/polypolygon_b2d.cxx
@@ -65,6 +65,83 @@ Bitmap OutputDeviceTestPolyPolygonB2D::setupFilledRectangle(bool useLineColor)
return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
}
+
+Bitmap OutputDeviceTestPolyPolygonB2D::setupIntersectingRectangles()
+{
+ initialSetup(24, 24, constBackgroundColor);
+
+ mpVirtualDevice->SetLineColor(constLineColor);
+ mpVirtualDevice->SetFillColor(constFillColor);
+
+ basegfx::B2DPolyPolygon aPolyPolygon;
+
+ int nOffset = 2, nFix = 1;
+ basegfx::B2DPolygon aPolygon1, aPolygon2, aPolygon3, aPolygon4;
+
+ /*
+ The intersection between different rectangles has been
+ acheived by stacking them on top of each other and decreasing and
+ increasing the top and bottom offset accordingly to the rectangle
+ keeping the left and the right offset intact which in turn coalesced
+ them to each other helping in acheiving multiple intersecting rectangles.
+ The desired color fill pattern is then achieved by setting the fill
+ color which in turn would fill the shape with the provided color
+ in accordance to the even-odd filling rule.
+ */
+
+ //Rect - 1
+ aPolygon1.append(basegfx::B2DPoint(maVDRectangle.Left() + nOffset + nFix,
+ maVDRectangle.Top() + (nOffset - 1) + nFix));
+ aPolygon1.append(basegfx::B2DPoint(maVDRectangle.Right() - (nOffset + 2) + nFix,
+ maVDRectangle.Top() + (nOffset - 1) + nFix));
+ aPolygon1.append(basegfx::B2DPoint(maVDRectangle.Right() - (nOffset + 2) + nFix,
+ maVDRectangle.Bottom() - (nOffset + 8) + nFix));
+ aPolygon1.append(basegfx::B2DPoint(maVDRectangle.Left() + nOffset + nFix,
+ maVDRectangle.Bottom() - (nOffset + 8) + nFix));
+ aPolygon1.setClosed(true);
+ aPolyPolygon.append(aPolygon1);
+
+ //Rect - 2
+ aPolygon2.append(basegfx::B2DPoint(maVDRectangle.Left() + nOffset + nFix,
+ maVDRectangle.Top() + (nOffset + 2) + nFix));
+ aPolygon2.append(basegfx::B2DPoint(maVDRectangle.Right() - (nOffset + 2) + nFix,
+ maVDRectangle.Top() + (nOffset + 2) + nFix));
+ aPolygon2.append(basegfx::B2DPoint(maVDRectangle.Right() - (nOffset + 2) + nFix,
+ maVDRectangle.Bottom() - (nOffset + 5) + nFix));
+ aPolygon2.append(basegfx::B2DPoint(maVDRectangle.Left() + nOffset + nFix,
+ maVDRectangle.Bottom() - (nOffset + 5) + nFix));
+ aPolygon2.setClosed(true);
+ aPolyPolygon.append(aPolygon2);
+
+ //Rect - 3
+ aPolygon3.append(basegfx::B2DPoint(maVDRectangle.Left() + nOffset + nFix,
+ maVDRectangle.Top() + (nOffset + 5) + nFix));
+ aPolygon3.append(basegfx::B2DPoint(maVDRectangle.Right() - (nOffset + 2) + nFix,
+ maVDRectangle.Top() + (nOffset + 5) + nFix));
+ aPolygon3.append(basegfx::B2DPoint(maVDRectangle.Right() - (nOffset + 2) + nFix,
+ maVDRectangle.Bottom() - (nOffset + 2) + nFix));
+ aPolygon3.append(basegfx::B2DPoint(maVDRectangle.Left() + nOffset + nFix,
+ maVDRectangle.Bottom() - (nOffset + 2) + nFix));
+ aPolygon3.setClosed(true);
+ aPolyPolygon.append(aPolygon3);
+
+ //Rect - 4
+ aPolygon4.append(basegfx::B2DPoint(maVDRectangle.Left() + nOffset + nFix,
+ maVDRectangle.Top() + (nOffset + 8) + nFix));
+ aPolygon4.append(basegfx::B2DPoint(maVDRectangle.Right() - (nOffset + 2) + nFix,
+ maVDRectangle.Top() + (nOffset + 8) + nFix));
+ aPolygon4.append(basegfx::B2DPoint(maVDRectangle.Right() - (nOffset + 2) + nFix,
+ maVDRectangle.Bottom() - nOffset + nFix));
+ aPolygon4.append(basegfx::B2DPoint(maVDRectangle.Left() + nOffset + nFix,
+ maVDRectangle.Bottom() - nOffset + nFix));
+ aPolygon4.setClosed(true);
+ aPolyPolygon.append(aPolygon4);
+
+ mpVirtualDevice->DrawPolyPolygon(aPolyPolygon);
+
+ return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
+}
+
} // end namespace vcl::test
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */