mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
[tests] Add method for setting size tolerance to render checker,
add some size tolerance to legend renderer test
This commit is contained in:
parent
78c2db627f
commit
405688ea49
@ -62,6 +62,14 @@ class QgsRenderChecker
|
||||
* @note added in 2.1
|
||||
*/
|
||||
void setColorTolerance( unsigned int theColorTolerance );
|
||||
|
||||
/** Sets the largest allowable difference in size between the rendered and the expected image.
|
||||
* @param xTolerance x tolerance in pixels
|
||||
* @param yTolerance y tolerance in pixels
|
||||
* @note added in QGIS 2.12
|
||||
*/
|
||||
void setSizeTolerance( int xTolerance, int yTolerance );
|
||||
|
||||
/**
|
||||
* Test using renderer to generate the image to be compared.
|
||||
* @param theTestName - to be used as the basis for writing a file to
|
||||
|
@ -37,6 +37,8 @@ QgsRenderChecker::QgsRenderChecker()
|
||||
, mExpectedImageFile( "" )
|
||||
, mMismatchCount( 0 )
|
||||
, mColorTolerance( 0 )
|
||||
, mMaxSizeDifferenceX( 0 )
|
||||
, mMaxSizeDifferenceY( 0 )
|
||||
, mElapsedTimeTarget( 0 )
|
||||
, mBufferDashMessages( false )
|
||||
{
|
||||
@ -374,13 +376,24 @@ bool QgsRenderChecker::compareImages( QString theTestName,
|
||||
|
||||
if ( mMatchTarget != myPixelCount )
|
||||
{
|
||||
qDebug( "Test image and result image for %s are different dimensions - FAILING!", theTestName.toLocal8Bit().constData() );
|
||||
mReport += "<tr><td colspan=3>";
|
||||
mReport += "<font color=red>Expected image and result image for " + theTestName + " are different dimensions - FAILING!</font>";
|
||||
mReport += "</td></tr>";
|
||||
mReport += myImagesString;
|
||||
delete maskImage;
|
||||
return false;
|
||||
qDebug( "Test image and result image for %s are different dimensions", theTestName.toLocal8Bit().constData() );
|
||||
|
||||
if ( qAbs( myExpectedImage.width() - myResultImage.width() ) > mMaxSizeDifferenceX ||
|
||||
qAbs( myExpectedImage.height() - myResultImage.height() ) > mMaxSizeDifferenceY )
|
||||
{
|
||||
mReport += "<tr><td colspan=3>";
|
||||
mReport += "<font color=red>Expected image and result image for " + theTestName + " are different dimensions - FAILING!</font>";
|
||||
mReport += "</td></tr>";
|
||||
mReport += myImagesString;
|
||||
delete maskImage;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
mReport += "<tr><td colspan=3>";
|
||||
mReport += "Expected image and result image for " + theTestName + " are different dimensions, but within tolerance";
|
||||
mReport += "</td></tr>";
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@ -388,16 +401,19 @@ bool QgsRenderChecker::compareImages( QString theTestName,
|
||||
// dissimilar pixel values there are
|
||||
//
|
||||
|
||||
int maxHeight = qMin( myExpectedImage.height(), myResultImage.height() );
|
||||
int maxWidth = qMin( myExpectedImage.width(), myResultImage.width() );
|
||||
|
||||
mMismatchCount = 0;
|
||||
int colorTolerance = ( int ) mColorTolerance;
|
||||
for ( int y = 0; y < myExpectedImage.height(); ++y )
|
||||
for ( int y = 0; y < maxHeight; ++y )
|
||||
{
|
||||
const QRgb* expectedScanline = ( const QRgb* )myExpectedImage.constScanLine( y );
|
||||
const QRgb* resultScanline = ( const QRgb* )myResultImage.constScanLine( y );
|
||||
const QRgb* maskScanline = hasMask ? ( const QRgb* )maskImage->constScanLine( y ) : 0;
|
||||
QRgb* diffScanline = ( QRgb* )myDifferenceImage.scanLine( y );
|
||||
|
||||
for ( int x = 0; x < myExpectedImage.width(); ++x )
|
||||
for ( int x = 0; x < maxWidth; ++x )
|
||||
{
|
||||
int maskTolerance = hasMask ? qRed( maskScanline[ x ] ) : 0;
|
||||
int pixelTolerance = qMax( colorTolerance, maskTolerance );
|
||||
|
@ -41,11 +41,12 @@ class CORE_EXPORT QgsRenderChecker
|
||||
QgsRenderChecker();
|
||||
|
||||
//! Destructor
|
||||
~QgsRenderChecker() {};
|
||||
~QgsRenderChecker() {}
|
||||
|
||||
QString controlImagePath() const;
|
||||
|
||||
QString report() { return mReport; };
|
||||
QString report() { return mReport; }
|
||||
|
||||
float matchPercent()
|
||||
{
|
||||
return static_cast<float>( mMismatchCount ) /
|
||||
@ -55,7 +56,7 @@ class CORE_EXPORT QgsRenderChecker
|
||||
unsigned int matchTarget() { return mMatchTarget; }
|
||||
//only records time for actual render part
|
||||
int elapsedTime() { return mElapsedTime; }
|
||||
void setElapsedTimeTarget( int theTarget ) { mElapsedTimeTarget = theTarget; };
|
||||
void setElapsedTimeTarget( int theTarget ) { mElapsedTimeTarget = theTarget; }
|
||||
|
||||
/** Base directory name for the control image (with control image path
|
||||
* suffixed) the path to the image will be constructed like this:
|
||||
@ -96,6 +97,14 @@ class CORE_EXPORT QgsRenderChecker
|
||||
* @note added in 2.1
|
||||
*/
|
||||
void setColorTolerance( unsigned int theColorTolerance ) { mColorTolerance = theColorTolerance; }
|
||||
|
||||
/** Sets the largest allowable difference in size between the rendered and the expected image.
|
||||
* @param xTolerance x tolerance in pixels
|
||||
* @param yTolerance y tolerance in pixels
|
||||
* @note added in QGIS 2.12
|
||||
*/
|
||||
void setSizeTolerance( int xTolerance, int yTolerance ) { mMaxSizeDifferenceX = xTolerance; mMaxSizeDifferenceY = yTolerance; }
|
||||
|
||||
/**
|
||||
* Test using renderer to generate the image to be compared.
|
||||
* @param theTestName - to be used as the basis for writing a file to
|
||||
@ -173,6 +182,8 @@ class CORE_EXPORT QgsRenderChecker
|
||||
QString mControlName;
|
||||
unsigned int mMismatchCount;
|
||||
unsigned int mColorTolerance;
|
||||
int mMaxSizeDifferenceX;
|
||||
int mMaxSizeDifferenceY;
|
||||
int mElapsedTimeTarget;
|
||||
QgsMapSettings mMapSettings;
|
||||
QString mControlPathPrefix;
|
||||
|
@ -67,6 +67,7 @@ static bool _verifyImage( const QString& testName, QString &report )
|
||||
QgsRenderChecker checker;
|
||||
checker.setControlName( "expected_" + testName );
|
||||
checker.setRenderedImage( _fileNameForTest( testName ) );
|
||||
checker.setSizeTolerance( 3, 3 );
|
||||
bool equal = checker.compareImages( testName, 500 );
|
||||
report += checker.report();
|
||||
return equal;
|
||||
|
Loading…
x
Reference in New Issue
Block a user