16 #ifndef QGSRENDERCHECKER_H
17 #define QGSRENDERCHECKER_H
44 QString controlImagePath()
const;
46 QString
report() {
return mReport; };
49 return static_cast<float>( mMismatchCount ) /
50 static_cast<float>( mMatchTarget ) * 100;
61 void setControlName(
const QString theName );
67 QString imageToHash( QString theImageFile );
69 void setRenderedImage( QString theImageFileName ) { mRenderedImageFile = theImageFileName; }
78 void setColorTolerance(
unsigned int theColorTolerance ) { mColorTolerance = theColorTolerance; }
89 bool runTest( QString theTestName,
unsigned int theMismatchCount = 0 );
102 bool compareImages( QString theTestName,
unsigned int theMismatchCount = 0, QString theRenderedImageFile =
"" );
110 bool isKnownAnomaly( QString theDiffImageFile );
112 QString expectedImageFile() {
return mExpectedImageFile; };
141 inline bool compareWkt( QString a, QString b,
double tolerance = 0.000001 )
143 QgsDebugMsg( QString(
"a:%1 b:%2 tol:%3" ).arg( a ).arg( b ).arg( tolerance ) );
144 QRegExp re(
"-?\\d+(?:\\.\\d+)?(?:[eE]\\d+)?" );
146 QString a0( a ), b0( b );
147 a0.replace( re,
"#" );
148 b0.replace( re,
"#" );
150 QgsDebugMsg( QString(
"a0:%1 b0:%2" ).arg( a0 ).arg( b0 ) );
155 QList<double> al, bl;
158 for ( pos = 0; ( pos = re.indexIn( a, pos ) ) != -1; pos += re.matchedLength() )
160 al << re.cap( 0 ).toDouble();
162 for ( pos = 0; ( pos = re.indexIn( b, pos ) ) != -1; pos += re.matchedLength() )
164 bl << re.cap( 0 ).toDouble();
167 if ( al.size() != bl.size() )
170 for (
int i = 0; i < al.size(); i++ )
void setColorTolerance(unsigned int theColorTolerance)
Set tolerance for color components used by runTest() and compareImages().
QgsMapRenderer * mpMapRenderer
This is a helper class for unit tests that need to write an image and compare it to an expected resul...
void setMapRenderer(QgsMapRenderer *thepMapRenderer)
A non GUI class for rendering a map layer set onto a QPainter.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
unsigned int mMismatchCount
~QgsRenderChecker()
Destructor.
void setControlPathPrefix(const QString theName)
Prefix where the control images are kept.
unsigned int mMatchTarget
QString mControlPathPrefix
unsigned int matchTarget()
QString mRenderedImageFile
unsigned int mColorTolerance
void setRenderedImage(QString theImageFileName)
QString mExpectedImageFile
unsigned int mismatchCount()
void setElapsedTimeTarget(int theTarget)
bool compareWkt(QString a, QString b, double tolerance=0.000001)
Compare two WKT strings with some tolerance.