16 #ifndef QGSRENDERCHECKER_H
17 #define QGSRENDERCHECKER_H
19 #include "qgis_core.h"
54 QString controlImagePath()
const;
62 void setControlImagePath(
const QString &path );
74 return static_cast<float>( mMismatchCount ) /
75 static_cast<float>( mMatchTarget ) * 100;
103 void setControlName(
const QString &name );
117 void setControlPathSuffix(
const QString &name );
120 QString imageToHash(
const QString &imageFile );
125 void setRenderedImage(
const QString &imageFileName ) { mRenderedImageFile = imageFileName; }
152 void setSizeTolerance(
int xTolerance,
int yTolerance ) { mMaxSizeDifferenceX = xTolerance; mMaxSizeDifferenceY = yTolerance; }
164 bool runTest(
const QString &testName,
unsigned int mismatchCount = 0 );
177 bool compareImages(
const QString &testName,
unsigned int mismatchCount = 0,
const QString &renderedImageFile = QString() );
184 bool compareImages(
const QString &testName,
const QString &referenceImageFile,
const QString &renderedImageFile,
unsigned int mismatchCount = 0 );
194 bool isKnownAnomaly(
const QString &diffImageFile );
200 static void drawBackground( QImage *image );
228 unsigned int mMatchTarget = 0;
229 int mElapsedTime = 0;
239 QString mControlName;
240 unsigned int mMismatchCount = 0;
241 unsigned int mColorTolerance = 0;
242 int mMaxSizeDifferenceX = 0;
243 int mMaxSizeDifferenceY = 0;
244 int mElapsedTimeTarget = 0;
246 QString mControlExtension = QStringLiteral(
"png" );
247 QString mControlPathPrefix;
248 QString mControlPathSuffix;
249 QVector<QgsDartMeasurement> mDashMessages;
250 bool mBufferDashMessages =
false;
262 inline bool compareWkt(
const QString &a,
const QString &b,
double tolerance = 0.000001 )
264 QgsDebugMsg( QStringLiteral(
"a:%1 b:%2 tol:%3" ).arg( a, b ).arg( tolerance ) );
265 QRegExp re(
"-?\\d+(?:\\.\\d+)?(?:[eE]\\d+)?" );
267 QString a0( a ), b0( b );
268 a0.replace( re, QStringLiteral(
"#" ) );
269 b0.replace( re, QStringLiteral(
"#" ) );
271 QgsDebugMsg( QStringLiteral(
"a0:%1 b0:%2" ).arg( a0, b0 ) );
276 QList<double> al, bl;
279 for ( pos = 0; ( pos = re.indexIn( a, pos ) ) != -1; pos += re.matchedLength() )
281 al << re.cap( 0 ).toDouble();
283 for ( pos = 0; ( pos = re.indexIn( b, pos ) ) != -1; pos += re.matchedLength() )
285 bl << re.cap( 0 ).toDouble();
288 if ( al.size() != bl.size() )
291 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.