16 #ifndef QGSRENDERCHECKER_H
17 #define QGSRENDERCHECKER_H
19 #include "qgis_core.h"
28 #include <QRegularExpression>
55 QString controlImagePath()
const;
63 void setControlImagePath(
const QString &path );
75 return static_cast<float>( mMismatchCount ) /
76 static_cast<float>( mMatchTarget ) * 100;
104 void setControlName(
const QString &name );
118 void setControlPathSuffix(
const QString &name );
121 QString imageToHash(
const QString &imageFile );
126 void setRenderedImage(
const QString &imageFileName ) { mRenderedImageFile = imageFileName; }
153 void setSizeTolerance(
int xTolerance,
int yTolerance ) { mMaxSizeDifferenceX = xTolerance; mMaxSizeDifferenceY = yTolerance; }
165 bool runTest(
const QString &testName,
unsigned int mismatchCount = 0 );
178 bool compareImages(
const QString &testName,
unsigned int mismatchCount = 0,
const QString &renderedImageFile = QString() );
185 bool compareImages(
const QString &testName,
const QString &referenceImageFile,
const QString &renderedImageFile,
unsigned int mismatchCount = 0 );
195 bool isKnownAnomaly(
const QString &diffImageFile );
201 static void drawBackground( QImage *image );
229 unsigned int mMatchTarget = 0;
230 int mElapsedTime = 0;
240 QString mControlName;
241 unsigned int mMismatchCount = 0;
242 unsigned int mColorTolerance = 0;
243 int mMaxSizeDifferenceX = 0;
244 int mMaxSizeDifferenceY = 0;
245 int mElapsedTimeTarget = 0;
247 QString mControlExtension = QStringLiteral(
"png" );
248 QString mControlPathPrefix;
249 QString mControlPathSuffix;
250 QVector<QgsDartMeasurement> mDashMessages;
251 bool mBufferDashMessages =
false;
263 inline bool compareWkt(
const QString &a,
const QString &b,
double tolerance = 0.000001 )
265 QgsDebugMsg( QStringLiteral(
"a:%1 b:%2 tol:%3" ).arg( a, b ).arg( tolerance ) );
266 const QRegularExpression re(
"-?\\d+(?:\\.\\d+)?(?:[eE]\\d+)?" );
268 QString a0( a ), b0( b );
269 a0.replace( re, QStringLiteral(
"#" ) );
270 b0.replace( re, QStringLiteral(
"#" ) );
272 QgsDebugMsg( QStringLiteral(
"a0:%1 b0:%2" ).arg( a0, b0 ) );
277 QList<double> al, bl;
280 QRegularExpressionMatch match = re.match( a );
281 while ( match.hasMatch() )
283 al << match.captured( 0 ).toDouble();
284 pos = match.capturedStart( 0 ) + match.capturedLength( 0 );
285 match = re.match( a, pos );
288 match = re.match( b );
289 while ( match.hasMatch() )
291 bl << match.captured( 0 ).toDouble();
292 pos = match.capturedStart( 0 ) + match.capturedLength( 0 );
293 match = re.match( b, pos );
296 if ( al.size() != bl.size() )
299 for (
int i = 0; i < al.size(); i++ )
The QgsMapSettings class contains configuration for rendering of the map.
This is a helper class for unit tests that need to write an image and compare it to an expected resul...
void setControlExtension(const QString &extension)
Sets file extension for the control image.
int elapsedTime()
Returns the total elapsed time for the rendering test.
float matchPercent() const
Returns the percent of pixels which matched the control image.
unsigned int matchTarget() const
Returns the total number of pixels in the control image.
QString mRenderedImageFile
QString renderedImage() const
Returns the path of the rendered image generated by the test.
QVector< QgsDartMeasurement > dartMeasurements() const
Gets access to buffered dash messages.
void setElapsedTimeTarget(int target)
void setControlPathPrefix(const QString &name)
Sets the path prefix where the control images are kept.
void setRenderedImage(const QString &imageFileName)
Sets the file name of the rendered image generated by the test.
QString mExpectedImageFile
void setSizeTolerance(int xTolerance, int yTolerance)
Sets the largest allowable difference in size between the rendered and the expected image.
void enableDashBuffering(bool enable)
Call this to enable internal buffering of dash messages.
unsigned int mismatchCount() const
Returns the number of pixels which did not match the control image.
void setColorTolerance(unsigned int colorTolerance)
Set tolerance for color components used by runTest() and compareImages().
QString report()
Returns the HTML report describing the results of the test run.
QString expectedImageFile() const
Returns the path to the expected image file.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
bool compareWkt(const QString &a, const QString &b, double tolerance=0.000001)
Compare two WKT strings with some tolerance.