vcl/qa/cppunit/BitmapScaleTest.cxx |   21 +++++----------------
 vcl/qa/cppunit/BitmapTest.cxx      |    9 +--------
 2 files changed, 6 insertions(+), 24 deletions(-)

New commits:
commit 772460f5cc61035a5b10bdf55a71f2a03f88af73
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Wed Feb 2 18:57:07 2022 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Feb 3 17:39:44 2022 +0100

    vcl: simplify assertColorsAreSimilar
    
    Change-Id: Ifd25bf75c5e173a7db4778713f1d371e9ee24ac1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129381
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/vcl/qa/cppunit/BitmapScaleTest.cxx 
b/vcl/qa/cppunit/BitmapScaleTest.cxx
index 0cf65ca798da..ce8f67437d9d 100644
--- a/vcl/qa/cppunit/BitmapScaleTest.cxx
+++ b/vcl/qa/cppunit/BitmapScaleTest.cxx
@@ -55,28 +55,17 @@ bool checkBitmapColor(Bitmap const& rBitmap, Color const& 
rExpectedColor)
     return bResult;
 }
 
-void assertColorsAreSimilar(int maxDifference, const std::string& message,
-                            const BitmapColor& expected, const BitmapColor& 
actual)
+void assertColorsAreSimilar(int maxDifference, int line, const BitmapColor& 
expected,
+                            const BitmapColor& actual)
 {
     // Check that the two colors match or are reasonably similar.
-    if (expected == actual)
+    if (expected.GetColorError(actual) <= maxDifference)
         return;
-    if (abs(expected.GetRed() - actual.GetRed()) <= maxDifference
-        && abs(expected.GetGreen() - actual.GetGreen()) <= maxDifference
-        && abs(expected.GetBlue() - actual.GetBlue()) <= maxDifference
-        && abs(expected.GetAlpha() - actual.GetAlpha()) <= maxDifference)
-    {
-        return;
-    }
-    CPPUNIT_ASSERT_EQUAL_MESSAGE(message, expected, actual);
-}
 
-void assertColorsAreSimilar(int maxDifference, int line, const BitmapColor& 
expected,
-                            const BitmapColor& actual)
-{
     std::stringstream stream;
     stream << "Line: " << line;
-    assertColorsAreSimilar(maxDifference, stream.str(), expected, actual);
+
+    CPPUNIT_ASSERT_EQUAL_MESSAGE(stream.str(), expected, actual);
 }
 
 void BitmapScaleTest::testScale()
diff --git a/vcl/qa/cppunit/BitmapTest.cxx b/vcl/qa/cppunit/BitmapTest.cxx
index 9d4cbb592f68..79f779f2a809 100644
--- a/vcl/qa/cppunit/BitmapTest.cxx
+++ b/vcl/qa/cppunit/BitmapTest.cxx
@@ -73,15 +73,8 @@ void assertColorsAreSimilar(int maxDifference, const 
std::string& message,
                             const BitmapColor& expected, const BitmapColor& 
actual)
 {
     // Check that the two colors match or are reasonably similar.
-    if (expected == actual)
+    if (expected.GetColorError(actual) <= maxDifference)
         return;
-    if (abs(expected.GetRed() - actual.GetRed()) <= maxDifference
-        && abs(expected.GetGreen() - actual.GetGreen()) <= maxDifference
-        && abs(expected.GetBlue() - actual.GetBlue()) <= maxDifference
-        && abs(expected.GetAlpha() - actual.GetAlpha()) <= maxDifference)
-    {
-        return;
-    }
     CPPUNIT_ASSERT_EQUAL_MESSAGE(message, expected, actual);
 }
 

Reply via email to