[Libreoffice-commits] core.git: include/vcl vcl/backendtest vcl/inc vcl/qa

homeboy445 (via logerrit) logerrit at kemper.freedesktop.org
Thu Aug 12 11:45:24 UTC 2021


 include/vcl/test/GraphicsRenderTests.hxx  |    2 
 vcl/backendtest/GraphicsRenderTests.cxx   |   42 ++++++++++++++
 vcl/backendtest/outputdevice/common.cxx   |   86 ++++++++++++++++++++++++++++++
 vcl/backendtest/outputdevice/polygon.cxx  |   12 ++++
 vcl/backendtest/outputdevice/polyline.cxx |   12 ++++
 vcl/inc/test/outputdevice.hxx             |    4 +
 vcl/qa/cppunit/BackendTest.cxx            |   23 ++++++++
 7 files changed, 181 insertions(+)

New commits:
commit 260ebddf284b34336d6ab82b1726d01b2bacd66c
Author:     homeboy445 <akshitsan13 at gmail.com>
AuthorDate: Mon Jul 12 20:26:35 2021 +0530
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Thu Aug 12 13:44:39 2021 +0200

    backendtest: Closed Bezier loop test using various drawing methods
    
    Change-Id: Ib2ddc8475e2476ce377f3541caa0d48e7c57241a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118783
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/include/vcl/test/GraphicsRenderTests.hxx b/include/vcl/test/GraphicsRenderTests.hxx
index eacf07c6f312..27c760c8b837 100644
--- a/include/vcl/test/GraphicsRenderTests.hxx
+++ b/include/vcl/test/GraphicsRenderTests.hxx
@@ -114,6 +114,8 @@ class VCL_PLUGIN_PUBLIC GraphicsRenderTests
     void testHalfEllipseAAWithPolyLineB2D();
     void testHalfEllipseWithPolygon();
     void testHalfEllipseAAWithPolygon();
+    void testClosedBezierWithPolyline();
+    void testClosedBezierWithPolygon();
     static OUString returnTestStatus(vcl::test::TestResult const result);
     void runALLTests();
     void appendTestResult(OUString aTestName, OUString aTestStatus, Bitmap aTestBitmap = Bitmap());
diff --git a/vcl/backendtest/GraphicsRenderTests.cxx b/vcl/backendtest/GraphicsRenderTests.cxx
index 707938cb1902..987a28459f2e 100644
--- a/vcl/backendtest/GraphicsRenderTests.cxx
+++ b/vcl/backendtest/GraphicsRenderTests.cxx
@@ -1406,6 +1406,46 @@ void GraphicsRenderTests::testHalfEllipseWithPolygon()
     }
 }
 
+void GraphicsRenderTests::testClosedBezierWithPolyline()
+{
+    vcl::test::OutputDeviceTestPolygon aOutDevTest;
+    Bitmap aBitmap = aOutDevTest.setupClosedBezier();
+    OUString aTestName = "testClosedBezierWithPolyline";
+    if (!SHOULD_ASSERT)
+    {
+        appendTestResult(aTestName, "SKIPPED");
+        return;
+    }
+    vcl::test::TestResult eResult = vcl::test::OutputDeviceTestCommon::checkClosedBezier(aBitmap);
+    appendTestResult(aTestName, returnTestStatus(eResult),
+                     (m_aStoreResultantBitmap ? aBitmap : Bitmap()));
+    if (m_aStoreResultantBitmap)
+    {
+        BitmapEx aBitmapEx(aBitmap);
+        exportBitmapExToImage(m_aUserInstallPath + aTestName + ".png", aBitmapEx);
+    }
+}
+
+void GraphicsRenderTests::testClosedBezierWithPolygon()
+{
+    vcl::test::OutputDeviceTestPolygon aOutDevTest;
+    Bitmap aBitmap = aOutDevTest.setupClosedBezier();
+    OUString aTestName = "testClosedBezierWithPolygon";
+    if (!SHOULD_ASSERT)
+    {
+        appendTestResult(aTestName, "SKIPPED");
+        return;
+    }
+    vcl::test::TestResult eResult = vcl::test::OutputDeviceTestCommon::checkClosedBezier(aBitmap);
+    appendTestResult(aTestName, returnTestStatus(eResult),
+                     (m_aStoreResultantBitmap ? aBitmap : Bitmap()));
+    if (m_aStoreResultantBitmap)
+    {
+        BitmapEx aBitmapEx(aBitmap);
+        exportBitmapExToImage(m_aUserInstallPath + aTestName + ".png", aBitmapEx);
+    }
+}
+
 void GraphicsRenderTests::testHalfEllipseAAWithPolygon()
 {
     vcl::test::OutputDeviceTestPolygon aOutDevTest;
@@ -1495,6 +1535,8 @@ void GraphicsRenderTests::runALLTests()
     testHalfEllipseAAWithPolyLineB2D();
     testHalfEllipseWithPolygon();
     testHalfEllipseAAWithPolygon();
+    testClosedBezierWithPolyline();
+    testClosedBezierWithPolygon();
 }
 
 void GraphicsRenderTests::appendTestResult(OUString aTestName, OUString aTestStatus,
diff --git a/vcl/backendtest/outputdevice/common.cxx b/vcl/backendtest/outputdevice/common.cxx
index 570ddb49c544..b5654c5c45e3 100644
--- a/vcl/backendtest/outputdevice/common.cxx
+++ b/vcl/backendtest/outputdevice/common.cxx
@@ -141,6 +141,30 @@ std::map<Color, int> collectColors(Bitmap& bitmap, const tools::Rectangle& recta
     return colors;
 }
 
+bool checkConvexHullProperty(Bitmap& bitmap, Color constLineColor, int nOffset)
+{
+    BitmapScopedWriteAccess pAccess(bitmap);
+    tools::Long thresholdWidth = pAccess->Width() - nOffset;
+    tools::Long thresholdHeight = pAccess->Height() - nOffset;
+    for (tools::Long y = 0; y < pAccess->Height(); ++y)
+    {
+        for (tools::Long x = 0; x < pAccess->Width(); ++x)
+        {
+            /*
+                If the shape exceeds the threshold limit of height or width or both,
+                this would indicate that the bezier curve is not within its convex polygon and
+                hence is faulty.
+            */
+            if (pAccess->GetPixel(y, x) == constLineColor
+                && (thresholdHeight < y || thresholdWidth < x))
+            {
+                return false;
+            }
+        }
+    }
+    return true;
+}
+
 TestResult checkRect(Bitmap& rBitmap, int aLayerNumber, Color aExpectedColor)
 {
     BitmapScopedWriteAccess pAccess(rBitmap);
@@ -593,6 +617,28 @@ basegfx::B2DPolygon OutputDeviceTestCommon::createHalfEllipsePolygon()
     return aPolygon;
 }
 
+tools::Polygon OutputDeviceTestCommon::createClosedBezierLoop(tools::Rectangle& rRect)
+{
+    tools::Long minX = rRect.Left();
+    tools::Long maxX = rRect.Right() - 2;
+    tools::Long minY = rRect.Top();
+    tools::Long maxY = rRect.Bottom() - 2;
+
+    tools::Polygon aPolygon(4);
+
+    aPolygon.SetPoint(Point((maxX / 2.0), maxY), 0);
+    aPolygon.SetFlags(0, PolyFlags::Normal);
+    aPolygon.SetPoint(Point(maxX, minY), 1);
+    aPolygon.SetFlags(1, PolyFlags::Control);
+    aPolygon.SetPoint(Point(minX, minY), 2);
+    aPolygon.SetFlags(2, PolyFlags::Control);
+    aPolygon.SetPoint(Point((maxX / 2.0), maxY), 3);
+    aPolygon.SetFlags(3, PolyFlags::Normal);
+
+    aPolygon.Optimize(PolyOptimizeFlags::CLOSE);
+
+    return aPolygon;
+}
 
 TestResult OutputDeviceTestCommon::checkDropShape(Bitmap& rBitmap, bool aEnableAA)
 {
@@ -723,6 +769,46 @@ TestResult OutputDeviceTestCommon::checkHalfEllipse(Bitmap& rBitmap, bool aEnabl
     return aResult;
 }
 
+TestResult OutputDeviceTestCommon::checkClosedBezier(Bitmap& rBitmap)
+{
+    BitmapScopedWriteAccess pAccess(rBitmap);
+
+    TestResult aResult = TestResult::Passed;
+    int nNumberOfQuirks = 0;
+    int nNumberOfErrors = 0;
+
+    std::map<std::pair<tools::Long, tools::Long>, bool> SetPixels
+        = { { { 3, 8 }, true },  { { 3, 9 }, true },   { { 3, 10 }, true },  { { 4, 7 }, true },
+            { { 4, 8 }, true },  { { 4, 9 }, true },   { { 4, 10 }, true },  { { 4, 11 }, true },
+            { { 5, 7 }, true },  { { 5, 11 }, true },  { { 6, 6 }, true },   { { 6, 12 }, true },
+            { { 7, 6 }, true },  { { 7, 12 }, true },  { { 8, 7 }, true },   { { 8, 11 }, true },
+            { { 9, 7 }, true },  { { 9, 11 }, true },  { { 10, 7 }, true },  { { 10, 11 }, true },
+            { { 11, 8 }, true }, { { 11, 9 }, true },  { { 11, 10 }, true }, { { 12, 8 }, true },
+            { { 12, 9 }, true }, { { 12, 10 }, true }, { { 13, 9 }, true } };
+
+    for (tools::Long x = 0; x < pAccess->Width(); x++)
+    {
+        for (tools::Long y = 0; y < pAccess->Height(); ++y)
+        {
+            if (SetPixels[{ y, x }])
+            {
+                checkValue(pAccess, x, y, constLineColor, nNumberOfQuirks, nNumberOfErrors, true);
+            }
+            else
+            {
+                checkValue(pAccess, x, y, constBackgroundColor, nNumberOfQuirks, nNumberOfErrors,
+                           true);
+            }
+        }
+    }
+
+    if (nNumberOfQuirks > 0)
+        aResult = TestResult::PassedWithQuirks;
+    if (nNumberOfErrors > 0 || !checkConvexHullProperty(rBitmap, constLineColor, 2))
+        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 9562dfecb290..a94bf0a6f306 100644
--- a/vcl/backendtest/outputdevice/polygon.cxx
+++ b/vcl/backendtest/outputdevice/polygon.cxx
@@ -188,6 +188,18 @@ Bitmap OutputDeviceTestPolygon::setupHalfEllipse(bool aEnableAA)
 
     return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
 }
+
+Bitmap OutputDeviceTestPolygon::setupClosedBezier()
+{
+    initialSetup(21, 16, constBackgroundColor);
+
+    mpVirtualDevice->SetLineColor(constLineColor);
+    mpVirtualDevice->SetFillColor();
+
+    mpVirtualDevice->DrawPolyLine(OutputDeviceTestCommon::createClosedBezierLoop(maVDRectangle));
+
+    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 edaf1bf428c5..41468ccee263 100644
--- a/vcl/backendtest/outputdevice/polyline.cxx
+++ b/vcl/backendtest/outputdevice/polyline.cxx
@@ -173,6 +173,18 @@ Bitmap OutputDeviceTestPolyLine::setupHalfEllipse(bool aEnableAA)
 
     return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
 }
+
+Bitmap OutputDeviceTestPolyLine::setupClosedBezier()
+{
+    initialSetup(21, 16, constBackgroundColor);
+
+    mpVirtualDevice->SetLineColor(constLineColor);
+    mpVirtualDevice->SetFillColor();
+
+    mpVirtualDevice->DrawPolyLine(OutputDeviceTestCommon::createClosedBezierLoop(maVDRectangle));
+
+    return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
+}
 } // 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 6e3943ef6fd6..ca79ddce7eea 100644
--- a/vcl/inc/test/outputdevice.hxx
+++ b/vcl/inc/test/outputdevice.hxx
@@ -69,6 +69,7 @@ public:
 
     static tools::Polygon createDropShapePolygon();
     static basegfx::B2DPolygon createHalfEllipsePolygon();
+    static tools::Polygon createClosedBezierLoop(tools::Rectangle& rRect);
 
     static void createHorizontalVerticalDiagonalLinePoints(tools::Rectangle rRect,
                                 Point& rHorizontalLinePoint1, Point& rHorizontalLinePoint2,
@@ -89,6 +90,7 @@ public:
     static TestResult checkLineJoinNone(Bitmap& rBitmap) { return checkLineJoin(rBitmap, basegfx::B2DLineJoin::NONE); }
     static TestResult checkDropShape(Bitmap& rBitmap, bool aEnableAA = false);
     static TestResult checkHalfEllipse(Bitmap& rBitmap, bool aEnableAA = false);
+    static TestResult checkClosedBezier(Bitmap& rBitmap);
 private:
     static TestResult checkLineCap(Bitmap& rBitmap, css::drawing::LineCap lineCap);
     static TestResult checkLineJoin(Bitmap& rBitmap, basegfx::B2DLineJoin lineJoin);
@@ -169,6 +171,7 @@ public:
     Bitmap setupDropShape();
     Bitmap setupAADropShape();
     Bitmap setupHalfEllipse(bool aEnableAA = false);
+    Bitmap setupClosedBezier();
 };
 
 class VCL_DLLPUBLIC OutputDeviceTestPolyLineB2D : public OutputDeviceTestCommon
@@ -208,6 +211,7 @@ public:
     Bitmap setupDropShape();
     Bitmap setupAADropShape();
     Bitmap setupHalfEllipse(bool aEnableAA = false);
+    Bitmap setupClosedBezier();
 };
 
 class VCL_DLLPUBLIC OutputDeviceTestPolyPolygon : public OutputDeviceTestCommon
diff --git a/vcl/qa/cppunit/BackendTest.cxx b/vcl/qa/cppunit/BackendTest.cxx
index 4e26d4aabc0d..6955da09565b 100644
--- a/vcl/qa/cppunit/BackendTest.cxx
+++ b/vcl/qa/cppunit/BackendTest.cxx
@@ -962,6 +962,26 @@ public:
             CPPUNIT_ASSERT(eResult != vcl::test::TestResult::Failed);
     }
 
+    void testClosedBezierWithPolyline()
+    {
+        vcl::test::OutputDeviceTestPolyLine aOutDevTest;
+        Bitmap aBitmap = aOutDevTest.setupClosedBezier();
+        auto eResult = vcl::test::OutputDeviceTestCommon::checkClosedBezier(aBitmap);
+        exportImage("18-01_closed_bezier-polyline.png", aBitmap);
+        if (SHOULD_ASSERT)
+            CPPUNIT_ASSERT(eResult != vcl::test::TestResult::Failed);
+    }
+
+    void testClosedBezierWithPolygon()
+    {
+        vcl::test::OutputDeviceTestPolygon aOutDevTest;
+        Bitmap aBitmap = aOutDevTest.setupClosedBezier();
+        auto eResult = vcl::test::OutputDeviceTestCommon::checkClosedBezier(aBitmap);
+        exportImage("18-02_closed_bezier-polygon.png", aBitmap);
+        if (SHOULD_ASSERT)
+            CPPUNIT_ASSERT(eResult != vcl::test::TestResult::Failed);
+    }
+
     // Test SalGraphics::blendBitmap() and blendAlphaBitmap() calls.
     void testDrawBlendExtended()
     {
@@ -1194,6 +1214,9 @@ public:
     CPPUNIT_TEST(testDrawHaflEllipseWithPolygon);
     CPPUNIT_TEST(testDrawHaflEllipseAAWithPolygon);
 
+    CPPUNIT_TEST(testClosedBezierWithPolyline);
+    CPPUNIT_TEST(testClosedBezierWithPolygon);
+
     CPPUNIT_TEST(testDrawBitmap);
     CPPUNIT_TEST(testDrawTransformedBitmap);
     CPPUNIT_TEST(testDrawBitmapExWithAlpha);


More information about the Libreoffice-commits mailing list