16 #ifndef QGSRENDERCHECKER_H 17 #define QGSRENDERCHECKER_H 19 #include "qgis_core.h" 47 QString controlImagePath()
const;
53 return static_cast<float>( mMismatchCount ) /
54 static_cast<float>( mMatchTarget ) * 100;
67 void setControlName(
const QString &name );
75 void setControlPathSuffix(
const QString &name );
78 QString imageToHash(
const QString &imageFile );
80 void setRenderedImage(
const QString &imageFileName ) { mRenderedImageFile = imageFileName; }
108 void setSizeTolerance(
int xTolerance,
int yTolerance ) { mMaxSizeDifferenceX = xTolerance; mMaxSizeDifferenceY = yTolerance; }
120 bool runTest(
const QString &testName,
unsigned int mismatchCount = 0 );
133 bool compareImages(
const QString &testName,
unsigned int mismatchCount = 0,
const QString &renderedImageFile = QString() );
143 bool isKnownAnomaly(
const QString &diffImageFile );
149 static void drawBackground( QImage *image );
178 unsigned int mMatchTarget = 0;
179 int mElapsedTime = 0;
187 QString mControlName;
188 unsigned int mMismatchCount = 0;
189 unsigned int mColorTolerance = 0;
190 int mMaxSizeDifferenceX = 0;
191 int mMaxSizeDifferenceY = 0;
192 int mElapsedTimeTarget = 0;
194 QString mControlPathPrefix;
195 QString mControlPathSuffix;
196 QVector<QgsDartMeasurement> mDashMessages;
197 bool mBufferDashMessages =
false;
209 inline bool compareWkt(
const QString &a,
const QString &b,
double tolerance = 0.000001 )
211 QgsDebugMsg( QString(
"a:%1 b:%2 tol:%3" ).arg( a, b ).arg( tolerance ) );
212 QRegExp re(
"-?\\d+(?:\\.\\d+)?(?:[eE]\\d+)?" );
214 QString a0( a ), b0( b );
215 a0.replace( re, QStringLiteral(
"#" ) );
216 b0.replace( re, QStringLiteral(
"#" ) );
218 QgsDebugMsg( QString(
"a0:%1 b0:%2" ).arg( a0, b0 ) );
223 QList<double> al, bl;
226 for ( pos = 0; ( pos = re.indexIn( a, pos ) ) != -1; pos += re.matchedLength() )
228 al << re.cap( 0 ).toDouble();
230 for ( pos = 0; ( pos = re.indexIn( b, pos ) ) != -1; pos += re.matchedLength() )
232 bl << re.cap( 0 ).toDouble();
235 if ( al.size() != bl.size() )
238 for (
int i = 0; i < al.size(); i++ )
void enableDashBuffering(bool enable)
Call this to enable internal buffering of dash messages.
QString expectedImageFile() const
Returns the path to the expected image file.
void setRenderedImage(const QString &imageFileName)
QString renderedImage()
The path of the rendered image can be retrieved through that method.
This is a helper class for unit tests that need to write an image and compare it to an expected resul...
void setSizeTolerance(int xTolerance, int yTolerance)
Sets the largest allowable difference in size between the rendered and the expected image...
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
The QgsMapSettings class contains configuration for rendering of the map.
void setControlPathPrefix(const QString &name)
Prefix where the control images are kept.
bool compareWkt(const QString &a, const QString &b, double tolerance=0.000001)
Compare two WKT strings with some tolerance.
unsigned int matchTarget()
QString mRenderedImageFile
QVector< QgsDartMeasurement > dartMeasurements() const
Get access to buffered dash messages.
QString mExpectedImageFile
void setColorTolerance(unsigned int colorTolerance)
Set tolerance for color components used by runTest() and compareImages().
void setElapsedTimeTarget(int target)
unsigned int mismatchCount()