]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
image comparison takes into account a tolerance
authorisn <isn@opencascade.com>
Fri, 16 Oct 2015 09:53:03 +0000 (12:53 +0300)
committerisn <isn@opencascade.com>
Fri, 16 Oct 2015 09:53:03 +0000 (12:53 +0300)
src/HYDRO_tests/TestViewer.cxx

index cf15eea6c4225e0adabb53779dedb5f27fe8dbaf..7f891922ce71ed235ff56c2de38143bdea297d17 100644 (file)
@@ -84,7 +84,7 @@ void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll
   viewWindow()->onFitAll();
 }
 
-bool AreImagesEqual( const QImage& theImage1, const QImage& theImage2, double theTolerance = 0.0 )
+bool AreImagesEqual( const QImage& theImage1, const QImage& theImage2, double theTolerance )
 {
   if( theImage1.isNull() || theImage2.isNull() )
     return theImage1.isNull() == theImage2.isNull();
@@ -95,9 +95,13 @@ bool AreImagesEqual( const QImage& theImage1, const QImage& theImage2, double th
   int aBytesCount = theImage1.byteCount();
   const uchar *aBytes1 = theImage1.constBits();
   const uchar *aBytes2 = theImage2.constBits();
+  int aBytesCountE = 0;
   for( int i=0; i<aBytesCount; i++ )
     if( aBytes1[i] != aBytes2[i] )
-      return false;
+      aBytesCountE++;
+
+  if ((double)aBytesCountE / (double)aBytesCount > theTolerance)
+    return false;
 
   return true;
 }
@@ -111,14 +115,13 @@ bool TestViewer::AssertEqual( const QString& theUseCaseName )
   QImage anExpectedRefImage; 
   anExpectedRefImage.load( anExpectedRefFilePath );
 
-  if( AreImagesEqual( anActualImage, anExpectedRefImage ) )
+  if( AreImagesEqual( anActualImage, anExpectedRefImage, 0.2 ) )
     return true;
 
   QString aPath = QDir::tempPath() + "/" + theUseCaseName + ".png";
   anActualImage.save( aPath );
   std::string aMessage = "The viewer contents does not correspond to the reference image: " + theUseCaseName.toStdString();
-  CPPUNIT_FAIL( aMessage.c_str() );
-
+  
   QImage aDiff( anExpectedRefImage.width(), anExpectedRefImage.height(), QImage::Format_ARGB32 );
   QPainter aPainter( &aDiff );
   aPainter.drawImage( 0, 0, anExpectedRefImage );
@@ -126,7 +129,8 @@ bool TestViewer::AssertEqual( const QString& theUseCaseName )
   aPainter.drawImage( 0, 0, anActualImage );
 
   QString aDiffFilePath = QDir::tempPath() + "/" + theUseCaseName + "_diff.png";
-  aDiff.save( aPath );
+  aDiff.save( aDiffFilePath );
+  CPPUNIT_FAIL( aMessage.c_str() );
 
   return false;
 }