include/vcl/test/GraphicsRenderTests.hxx      |    2 
 vcl/backendtest/GraphicsRenderTests.cxx       |   42 ++++++++++++++++++
 vcl/backendtest/VisualBackendTest.cxx         |    4 -
 vcl/backendtest/outputdevice/common.cxx       |   59 ++++++++++++++++++++++++--
 vcl/backendtest/outputdevice/polyline.cxx     |   12 +++++
 vcl/backendtest/outputdevice/polyline_b2d.cxx |   12 +++++
 vcl/inc/test/outputdevice.hxx                 |    4 +
 vcl/qa/cppunit/BackendTest.cxx                |   23 ++++++++++
 8 files changed, 152 insertions(+), 6 deletions(-)

New commits:
commit f90159697506e28ebbfb436047e52db1b65bd9a7
Author:     homeboy445 <akshitsa...@gmail.com>
AuthorDate: Fri Aug 13 16:05:18 2021 +0530
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Thu Nov 4 14:36:03 2021 +0100

    backendtest: Open Cubic-Bezier Curve Draw Test
    
    Change-Id: I1f41ab6d9dca4589da466caca1dfcbfdd15a5b5c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120425
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/include/vcl/test/GraphicsRenderTests.hxx 
b/include/vcl/test/GraphicsRenderTests.hxx
index 718674b1cc5e..f1adcc6bb721 100644
--- a/include/vcl/test/GraphicsRenderTests.hxx
+++ b/include/vcl/test/GraphicsRenderTests.hxx
@@ -148,6 +148,8 @@ class VCL_PLUGIN_PUBLIC GraphicsRenderTests
     void testDrawOpenPolygonWithPolygon();
     void testDrawOpenPolygonWithPolyPolygon();
     void testDrawOpenPolygonWithPolyPolygonB2D();
+    void testDrawOpenBezierWithPolyLine();
+    void testDrawOpenBezierWithPolyLineB2D();
     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 0f360f2ae9c0..fa48087fa03e 100644
--- a/vcl/backendtest/GraphicsRenderTests.cxx
+++ b/vcl/backendtest/GraphicsRenderTests.cxx
@@ -2115,6 +2115,46 @@ void 
GraphicsRenderTests::testDrawOpenPolygonWithPolyPolygonB2D()
     }
 }
 
+void GraphicsRenderTests::testDrawOpenBezierWithPolyLine()
+{
+    vcl::test::OutputDeviceTestPolyLine aOutDevTest;
+    Bitmap aBitmap = aOutDevTest.setupOpenBezier();
+    OUString aTestName = "testDrawOpenBezierWithPolyLine";
+    if (!SHOULD_ASSERT)
+    {
+        appendTestResult(aTestName, "SKIPPED");
+        return;
+    }
+    vcl::test::TestResult eResult = 
vcl::test::OutputDeviceTestCommon::checkOpenBezier(aBitmap);
+    appendTestResult(aTestName, returnTestStatus(eResult),
+                     (m_aStoreResultantBitmap ? aBitmap : Bitmap()));
+    if (m_aStoreResultantBitmap)
+    {
+        BitmapEx aBitmapEx(aBitmap);
+        exportBitmapExToImage(m_aUserInstallPath + aTestName + ".png", 
aBitmapEx);
+    }
+}
+
+void GraphicsRenderTests::testDrawOpenBezierWithPolyLineB2D()
+{
+    vcl::test::OutputDeviceTestPolyLine aOutDevTest;
+    Bitmap aBitmap = aOutDevTest.setupOpenBezier();
+    OUString aTestName = "testDrawOpenBezierWithPolyLineB2D";
+    if (!SHOULD_ASSERT)
+    {
+        appendTestResult(aTestName, "SKIPPED");
+        return;
+    }
+    vcl::test::TestResult eResult = 
vcl::test::OutputDeviceTestCommon::checkOpenBezier(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();
@@ -2217,6 +2257,8 @@ void GraphicsRenderTests::runALLTests()
     testDrawOpenPolygonWithPolygon();
     testDrawOpenPolygonWithPolyPolygon();
     testDrawOpenPolygonWithPolyPolygonB2D();
+    testDrawOpenBezierWithPolyLine();
+    testDrawOpenBezierWithPolyLineB2D();
 }
 
 void GraphicsRenderTests::appendTestResult(OUString aTestName, OUString 
aTestStatus,
diff --git a/vcl/backendtest/VisualBackendTest.cxx 
b/vcl/backendtest/VisualBackendTest.cxx
index 7d0edb6aa69b..4ab745c73af0 100644
--- a/vcl/backendtest/VisualBackendTest.cxx
+++ b/vcl/backendtest/VisualBackendTest.cxx
@@ -346,8 +346,8 @@ public:
         aRectangle = aRegions[index++];
         {
             vcl::test::OutputDeviceTestPolyLineB2D aOutDevTest;
-            Bitmap aBitmap = aOutDevTest.setupBezier();
-            
assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkBezier(aBitmap), 
aRectangle, rRenderContext);
+            Bitmap aBitmap = aOutDevTest.setupOpenBezier();
+            
assertAndSetBackground(vcl::test::OutputDeviceTestCommon::checkOpenBezier(aBitmap),
 aRectangle, rRenderContext);
             drawBitmapScaledAndCentered(aRectangle, aBitmap, rRenderContext);
         }
         aRectangle = aRegions[index++];
diff --git a/vcl/backendtest/outputdevice/common.cxx 
b/vcl/backendtest/outputdevice/common.cxx
index c8e291f787ec..4e36293b1d70 100644
--- a/vcl/backendtest/outputdevice/common.cxx
+++ b/vcl/backendtest/outputdevice/common.cxx
@@ -142,11 +142,12 @@ std::map<Color, int> collectColors(Bitmap& bitmap, const 
tools::Rectangle& recta
     return colors;
 }
 
-bool checkConvexHullProperty(Bitmap& bitmap, Color constLineColor, int nOffset)
+bool checkConvexHullProperty(Bitmap& bitmap, Color constLineColor, int 
nWidthOffset,
+                             int nHeightOffset)
 {
     BitmapScopedWriteAccess pAccess(bitmap);
-    tools::Long thresholdWidth = pAccess->Width() - nOffset;
-    tools::Long thresholdHeight = pAccess->Height() - nOffset;
+    tools::Long thresholdWidth = pAccess->Width() - nWidthOffset;
+    tools::Long thresholdHeight = pAccess->Height() - nHeightOffset;
     for (tools::Long y = 0; y < pAccess->Height(); ++y)
     {
         for (tools::Long x = 0; x < pAccess->Width(); ++x)
@@ -733,6 +734,19 @@ basegfx::B2DPolygon 
OutputDeviceTestCommon::createOpenPolygon(const tools::Recta
     return aPolygon;
 }
 
+basegfx::B2DPolygon OutputDeviceTestCommon::createOpenBezier()
+{
+    basegfx::B2DPolygon aPolygon;
+
+    aPolygon.append({ 5.0, 2.0 });
+    aPolygon.append({ 3.0, 14.0 });
+    aPolygon.setClosed(false);
+
+    aPolygon.setControlPoints(0, { 15.0, 2.0 }, { 15.0, 15.0 });
+
+    return aPolygon;
+}
+
 TestResult OutputDeviceTestCommon::checkDropShape(Bitmap& rBitmap, bool 
aEnableAA)
 {
     BitmapScopedWriteAccess pAccess(rBitmap);
@@ -899,7 +913,44 @@ TestResult 
OutputDeviceTestCommon::checkClosedBezier(Bitmap& rBitmap)
 
     if (nNumberOfQuirks > 0)
         aResult = TestResult::PassedWithQuirks;
-    if (nNumberOfErrors > 0 || !checkConvexHullProperty(rBitmap, 
constLineColor, 2))
+    if (nNumberOfErrors > 0 || !checkConvexHullProperty(rBitmap, 
constLineColor, 2, 2))
+        aResult = TestResult::Failed;
+    return aResult;
+}
+
+TestResult OutputDeviceTestCommon::checkOpenBezier(Bitmap& rBitmap)
+{
+    BitmapScopedWriteAccess pAccess(rBitmap);
+
+    TestResult aResult = TestResult::Passed;
+    int nNumberOfQuirks = 0;
+    int nNumberOfErrors = 0;
+
+    std::map<std::pair<int, int>, bool> SetPixels
+        = { { { 14, 3 }, true }, { { 14, 4 }, true }, { { 14, 5 }, true }, { { 
3, 6 }, true },
+            { { 4, 6 }, true },  { { 14, 6 }, true }, { { 4, 7 }, true },  { { 
5, 7 }, true },
+            { { 13, 7 }, true }, { { 6, 8 }, true },  { { 7, 8 }, true },  { { 
12, 8 }, true },
+            { { 13, 8 }, true }, { { 8, 9 }, true },  { { 9, 9 }, true },  { { 
10, 9 }, true },
+            { { 11, 9 }, true }, { { 12, 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, 5))
         aResult = TestResult::Failed;
     return aResult;
 }
diff --git a/vcl/backendtest/outputdevice/polyline.cxx 
b/vcl/backendtest/outputdevice/polyline.cxx
index da5a4a6474c6..d187d4addd3b 100644
--- a/vcl/backendtest/outputdevice/polyline.cxx
+++ b/vcl/backendtest/outputdevice/polyline.cxx
@@ -228,6 +228,18 @@ Bitmap OutputDeviceTestPolyLine::setupOpenPolygon()
     return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), 
maVDRectangle.GetSize());
 }
 
+Bitmap OutputDeviceTestPolyLine::setupOpenBezier()
+{
+    initialSetup(21, 21, constBackgroundColor);
+
+    mpVirtualDevice->SetLineColor(constLineColor);
+    mpVirtualDevice->SetFillColor();
+
+    
mpVirtualDevice->DrawPolyLine(tools::Polygon(OutputDeviceTestCommon::createOpenBezier()));
+
+    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 1284a3fa8074..1fa603d1eaa9 100644
--- a/vcl/backendtest/outputdevice/polyline_b2d.cxx
+++ b/vcl/backendtest/outputdevice/polyline_b2d.cxx
@@ -175,6 +175,18 @@ Bitmap OutputDeviceTestPolyLineB2D::setupOpenPolygon()
     return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), 
maVDRectangle.GetSize());
 }
 
+Bitmap OutputDeviceTestPolyLineB2D::setupOpenBezier()
+{
+    initialSetup(21, 21, constBackgroundColor);
+
+    mpVirtualDevice->SetLineColor(constLineColor);
+    mpVirtualDevice->SetFillColor();
+
+    mpVirtualDevice->DrawPolyLine(OutputDeviceTestCommon::createOpenBezier());
+
+    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 e205dfb80909..d4ae96788736 100644
--- a/vcl/inc/test/outputdevice.hxx
+++ b/vcl/inc/test/outputdevice.hxx
@@ -72,6 +72,7 @@ public:
     static basegfx::B2DPolygon createHalfEllipsePolygon();
     static tools::Polygon createClosedBezierLoop(const tools::Rectangle& 
rRect);
     static basegfx::B2DPolygon createOpenPolygon(const tools::Rectangle& 
rRect, int nOffset = 4);
+    static basegfx::B2DPolygon createOpenBezier();
 
     static void createHorizontalVerticalDiagonalLinePoints(tools::Rectangle 
rRect,
                                 Point& rHorizontalLinePoint1, Point& 
rHorizontalLinePoint2,
@@ -98,6 +99,7 @@ public:
     static TestResult checkEvenOddRuleInIntersectingRecs(Bitmap &rBitmap);
     static TestResult checkIntersectingRecs(Bitmap& rBitmap,int aLayerNumber, 
Color aExpectedColor);
     static TestResult checkOpenPolygon(Bitmap& rBitmap, bool aEnableAA = 
false);
+    static TestResult checkOpenBezier(Bitmap& rBitmap);
 private:
     static TestResult checkLineCap(Bitmap& rBitmap, css::drawing::LineCap 
lineCap);
     static TestResult checkLineJoin(Bitmap& rBitmap, basegfx::B2DLineJoin 
lineJoin);
@@ -189,6 +191,7 @@ public:
     Bitmap setupRectangleOnSize1028();
     Bitmap setupRectangleOnSize4096();
     Bitmap setupOpenPolygon();
+    Bitmap setupOpenBezier();
 };
 
 class VCL_DLLPUBLIC OutputDeviceTestPolyLineB2D : public OutputDeviceTestCommon
@@ -204,6 +207,7 @@ public:
     Bitmap setupRectangleOnSize1028();
     Bitmap setupRectangleOnSize4096();
     Bitmap setupOpenPolygon();
+    Bitmap setupOpenBezier();
 };
 
 class VCL_DLLPUBLIC OutputDeviceTestRect : public OutputDeviceTestCommon
diff --git a/vcl/qa/cppunit/BackendTest.cxx b/vcl/qa/cppunit/BackendTest.cxx
index ffb44b5fe3c1..922c6ba1ca0f 100644
--- a/vcl/qa/cppunit/BackendTest.cxx
+++ b/vcl/qa/cppunit/BackendTest.cxx
@@ -1273,6 +1273,26 @@ public:
             CPPUNIT_ASSERT(eResult != vcl::test::TestResult::Failed);
     }
 
+    void testDrawOpenBezierWithPolyLine()
+    {
+        vcl::test::OutputDeviceTestPolyLine aOutDevTest;
+        Bitmap aBitmap = aOutDevTest.setupOpenBezier();
+        auto eResult = 
vcl::test::OutputDeviceTestCommon::checkOpenBezier(aBitmap);
+        exportImage("19-01_open_bezier-polyline.png", aBitmap);
+        if (SHOULD_ASSERT)
+            CPPUNIT_ASSERT(eResult != vcl::test::TestResult::Failed);
+    }
+
+    void testDrawOpenBezierWithPolyLineB2D()
+    {
+        vcl::test::OutputDeviceTestPolyLineB2D aOutDevTest;
+        Bitmap aBitmap = aOutDevTest.setupOpenBezier();
+        auto eResult = 
vcl::test::OutputDeviceTestCommon::checkOpenBezier(aBitmap);
+        exportImage("19-01_open_bezier-polyline_b2d.png", aBitmap);
+        if (SHOULD_ASSERT)
+            CPPUNIT_ASSERT(eResult != vcl::test::TestResult::Failed);
+    }
+
     void testTdf124848()
     {
 // TODO: This unit test is not executed for macOS unless bitmap scaling is 
implemented
@@ -1451,6 +1471,9 @@ public:
     CPPUNIT_TEST(testDrawOpenPolygonWithPolyPolygon);
     CPPUNIT_TEST(testDrawOpenPolygonWithPolyPolygonB2D);
 
+    CPPUNIT_TEST(testDrawOpenBezierWithPolyLine);
+    CPPUNIT_TEST(testDrawOpenBezierWithPolyLineB2D);
+
     CPPUNIT_TEST(testTdf124848);
     CPPUNIT_TEST(testTdf136171);
 

Reply via email to