From bfed092c471d53b817057f691a8f0f555530e21f Mon Sep 17 00:00:00 2001 From: isn Date: Fri, 16 Oct 2015 12:53:03 +0300 Subject: [PATCH] image comparison takes into account a tolerance --- src/HYDRO_tests/TestViewer.cxx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/HYDRO_tests/TestViewer.cxx b/src/HYDRO_tests/TestViewer.cxx index cf15eea6..7f891922 100644 --- a/src/HYDRO_tests/TestViewer.cxx +++ b/src/HYDRO_tests/TestViewer.cxx @@ -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 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; } -- 2.39.2