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();
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;
}
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 );
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;
}