Browse Source

ENH: Rename testing utility function

Rename testing utility function CompareImages() to CheckImagesEqual().
Max Smolens 7 years ago
parent
commit
66c9c93b95

+ 1 - 1
Libs/Widgets/Testing/Cpp/ctkCrosshairLabelTest2.cpp

@@ -41,7 +41,7 @@ bool imageCompare(ctkCrosshairLabel& crosshair, QString baselineDirectory,
   QImage output = QPixmap::grabWidget(&crosshair).toImage();
   QImage baseline(baselineDirectory + "/" + baselineFilename);
   const float percentThreshold = 1.5f;
-  return ctkWidgetsTestingUtilities::CompareImages(output, baseline, percentThreshold);
+  return ctkWidgetsTestingUtilities::CheckImagesEqual(output, baseline, percentThreshold);
 }
 
 //-----------------------------------------------------------------------------

+ 35 - 35
Libs/Widgets/Testing/Cpp/ctkWidgetsTestingUtilitiesTest.cpp

@@ -31,26 +31,26 @@
 using namespace ctkWidgetsTestingUtilities;
 
 //----------------------------------------------------------------------------
-bool TestCheckCompareImages();
+bool TestCheckImagesEqual();
 
 //----------------------------------------------------------------------------
 int ctkWidgetsTestingUtilitiesTest(int , char * [])
 {
   bool res = true;
-  res = res && TestCheckCompareImages();
+  res = res && TestCheckImagesEqual();
   return res ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
 //----------------------------------------------------------------------------
-bool TestCheckCompareImages()
+bool TestCheckImagesEqual()
 {
   {
     // Invalid format
     QImage a(1, 1, QImage::Format_Invalid);
     QImage b(1, 1, QImage::Format_Invalid);
-    if (CompareImages(a, b))
+    if (CheckImagesEqual(a, b))
       {
-      std::cerr << "Line " << __LINE__ << " - CompareImages failed" << std::endl;
+      std::cerr << "Line " << __LINE__ << " - CheckImagesEqual failed" << std::endl;
       return false;
       }
   }
@@ -59,9 +59,9 @@ bool TestCheckCompareImages()
     // Unsupported format
     QImage a(1, 1, QImage::Format_ARGB32);
     QImage b(1, 1, QImage::Format_ARGB32);
-    if (CompareImages(a, b))
+    if (CheckImagesEqual(a, b))
       {
-      std::cerr << "Line " << __LINE__ << " - CompareImages failed" << std::endl;
+      std::cerr << "Line " << __LINE__ << " - CheckImagesEqual failed" << std::endl;
       return false;
       }
   }
@@ -70,17 +70,17 @@ bool TestCheckCompareImages()
     // One image in unsupported format
     QImage a(1, 1, QImage::Format_RGB32);
     QImage b(1, 1, QImage::Format_ARGB32);
-    if (CompareImages(a, b))
+    if (CheckImagesEqual(a, b))
       {
-      std::cerr << "Line " << __LINE__ << " - CompareImages failed" << std::endl;
+      std::cerr << "Line " << __LINE__ << " - CheckImagesEqual failed" << std::endl;
       return false;
       }
 
     QImage c(1, 1, QImage::Format_ARGB32);
     QImage d(1, 1, QImage::Format_RGB32);
-    if (CompareImages(c, d))
+    if (CheckImagesEqual(c, d))
       {
-      std::cerr << "Line " << __LINE__ << " - CompareImages failed" << std::endl;
+      std::cerr << "Line " << __LINE__ << " - CheckImagesEqual failed" << std::endl;
       return false;
       }
   }
@@ -89,17 +89,17 @@ bool TestCheckCompareImages()
     // Images of different size
     QImage a(1, 1, QImage::Format_RGB32);
     QImage b(2, 1, QImage::Format_RGB32);
-    if (CompareImages(a, b))
+    if (CheckImagesEqual(a, b))
       {
-      std::cerr << "Line " << __LINE__ << " - CompareImages failed" << std::endl;
+      std::cerr << "Line " << __LINE__ << " - CheckImagesEqual failed" << std::endl;
       return false;
       }
 
     QImage c(1, 2, QImage::Format_ARGB32);
     QImage d(1, 1, QImage::Format_RGB32);
-    if (CompareImages(c, d))
+    if (CheckImagesEqual(c, d))
       {
-      std::cerr << "Line " << __LINE__ << " - CompareImages failed" << std::endl;
+      std::cerr << "Line " << __LINE__ << " - CheckImagesEqual failed" << std::endl;
       return false;
       }
   }
@@ -110,63 +110,63 @@ bool TestCheckCompareImages()
     a.fill(Qt::green);
     QImage b(10, 10, QImage::Format_RGB32);
     b.fill(Qt::green);
-    if (!CompareImages(a, b, 0.0f))
+    if (!CheckImagesEqual(a, b, 0.0f))
       {
-      std::cerr << "Line " << __LINE__ << " - CompareImages failed" << std::endl;
+      std::cerr << "Line " << __LINE__ << " - CheckImagesEqual failed" << std::endl;
       return false;
       }
 
     // Change one pixel in first image
     a.setPixel(2, 3, qRgb(255, 0, 0));
-    if (CompareImages(a, b, 0.f))
+    if (CheckImagesEqual(a, b, 0.f))
       {
-      std::cerr << "Line " << __LINE__ << " - CompareImages failed" << std::endl;
+      std::cerr << "Line " << __LINE__ << " - CheckImagesEqual failed" << std::endl;
       return false;
       }
 
-    // Compare with percent threshold not met
-    if (CompareImages(a, b, 0.5f))
+    // Percent threshold not met
+    if (CheckImagesEqual(a, b, 0.5f))
       {
-      std::cerr << "Line " << __LINE__ << " - CompareImages failed" << std::endl;
+      std::cerr << "Line " << __LINE__ << " - CheckImagesEqual failed" << std::endl;
       return false;
       }
 
-    // Compare with percent threshold met
-    if (!CompareImages(a, b, 1.f))
+    // Percent threshold met
+    if (!CheckImagesEqual(a, b, 1.f))
       {
-      std::cerr << "Line " << __LINE__ << " - CompareImages failed" << std::endl;
+      std::cerr << "Line " << __LINE__ << " - CheckImagesEqual failed" << std::endl;
       return false;
       }
 
     // Change one pixel in other image
-    // Compare with percent threshold not met
+    // Percent threshold not met
     b.setPixel(4, 5, qRgb(255, 255, 0));
-    if (CompareImages(a, b, 1.f))
+    if (CheckImagesEqual(a, b, 1.f))
       {
-      std::cerr << "Line " << __LINE__ << " - CompareImages failed" << std::endl;
+      std::cerr << "Line " << __LINE__ << " - CheckImagesEqual failed" << std::endl;
       return false;
       }
 
-    // Compare with percent threshold met
-    if (!CompareImages(a, b, 2.f))
+    // Percent threshold met
+    if (!CheckImagesEqual(a, b, 2.f))
       {
-      std::cerr << "Line " << __LINE__ << " - CompareImages failed" << std::endl;
+      std::cerr << "Line " << __LINE__ << " - CheckImagesEqual failed" << std::endl;
       return false;
       }
 
     // Change one pixel in first image to match second image
     a.setPixel(4, 5, qRgb(255, 255, 0));
-    if (!CompareImages(a, b, 1.f))
+    if (!CheckImagesEqual(a, b, 1.f))
       {
-      std::cerr << "Line " << __LINE__ << " - CompareImages failed" << std::endl;
+      std::cerr << "Line " << __LINE__ << " - CheckImagesEqual failed" << std::endl;
       return false;
       }
 
     // Identical images
     b.setPixel(2, 3, qRgb(255, 0, 0));
-    if (!CompareImages(a, b, 0.f))
+    if (!CheckImagesEqual(a, b, 0.f))
       {
-      std::cerr << "Line " << __LINE__ << " - CompareImages failed" << std::endl;
+      std::cerr << "Line " << __LINE__ << " - CheckImagesEqual failed" << std::endl;
       return false;
       }
   }

+ 3 - 3
Libs/Widgets/ctkWidgetsTestingUtilities.cpp

@@ -10,8 +10,8 @@
 namespace ctkWidgetsTestingUtilities
 {
 //---------------------------------------------------------------------------- */
-bool CompareImages(const QImage& current, const QImage& expected,
-                   float percentThreshold)
+bool CheckImagesEqual(const QImage& current, const QImage& expected,
+                      float percentThreshold)
 {
   if (current.width() != expected.width() ||
       current.height() != expected.height() ||
@@ -22,7 +22,7 @@ bool CompareImages(const QImage& current, const QImage& expected,
 
   if (current.format() != QImage::Format_RGB32)
     {
-    std::cerr << "ERROR: CompareImages: Unsupported QImage::Format: "
+    std::cerr << "ERROR: CheckImagesEqual: Unsupported QImage::Format: "
               << static_cast<int>(current.format()) << std::endl;
     return false;
     }

+ 4 - 4
Libs/Widgets/ctkWidgetsTestingUtilities.h

@@ -31,11 +31,11 @@ class QImage;
 namespace ctkWidgetsTestingUtilities
 {
 
-/// Compare two images for pixel-level similarity. Allow for the specified
-/// percentage of pixels to be different.
+/// Check that two images are equal. Allow for the specified percentage of
+/// pixels to be different.
 CTK_WIDGETS_EXPORT
-bool CompareImages(const QImage& current, const QImage& expected,
-                   float percentThreshold=0.f);
+bool CheckImagesEqual(const QImage& current, const QImage& expected,
+                      float percentThreshold=0.f);
 
 } // namespace ctkWidgetsTestingUtilities