16#ifndef QGSRENDERCHECKER_H
17#define QGSRENDERCHECKER_H
28#include <QRegularExpression>
33#define DUMP_BASE64_IMAGES 0
57 static QDir testReportDir();
65 static bool shouldGenerateReport();
74 QString controlImagePath()
const;
82 void setControlImagePath(
const QString &path );
90 QString report(
bool ignoreSuccess =
true )
const;
97 return static_cast<float>( mMismatchCount ) /
98 static_cast<float>( mMatchTarget ) * 100;
126 void setControlName(
const QString &name );
140 void setControlPathSuffix(
const QString &name );
143 QString imageToHash(
const QString &imageFile );
148 void setRenderedImage(
const QString &imageFileName ) { mRenderedImageFile = imageFileName; }
182 void setSizeTolerance(
int xTolerance,
int yTolerance ) { mMaxSizeDifferenceX = xTolerance; mMaxSizeDifferenceY = yTolerance; }
191 AvoidExportingRenderedImage = 1 << 0,
200 Q_DECLARE_FLAGS( Flags, Flag )
214 bool runTest(
const QString &testName,
unsigned int mismatchCount = 0, QgsRenderChecker::Flags flags = QgsRenderChecker::Flags() );
228 bool compareImages(
const QString &testName,
unsigned int mismatchCount = 0,
const QString &renderedImageFile = QString(), QgsRenderChecker::Flags flags = QgsRenderChecker::Flags() );
235 bool compareImages(
const QString &testName,
const QString &referenceImageFile,
const QString &renderedImageFile,
unsigned int mismatchCount = 0, QgsRenderChecker::Flags flags = QgsRenderChecker::Flags() );
247 Q_DECL_DEPRECATED
bool isKnownAnomaly(
const QString &diffImageFile )
SIP_DEPRECATED;
253 static void drawBackground( QImage *image );
281 unsigned int mMatchTarget = 0;
282 int mElapsedTime = 0;
290#if DUMP_BASE64_IMAGES
291 void dumpRenderedImageAsBase64();
294 void performPostTestActions( Flags flags );
296 bool mResult =
false;
297 bool mExpectFail =
false;
301 QString mControlName;
302 unsigned int mMismatchCount = 0;
303 unsigned int mColorTolerance = 0;
304 int mMaxSizeDifferenceX = 0;
305 int mMaxSizeDifferenceY = 0;
306 int mElapsedTimeTarget = 0;
308 QString mControlExtension = QStringLiteral(
"png" );
309 QString mControlPathPrefix;
310 QString mControlPathSuffix;
311 bool mIsCiRun =
false;
312 QVector<QgsDartMeasurement> mDashMessages;
313 bool mBufferDashMessages =
false;
314 QString mDiffImageFile;
329inline
bool compareWkt( const QString &a, const QString &b,
double tolerance = 0.000001 )
331 QgsDebugMsg( QStringLiteral(
"a:%1 b:%2 tol:%3" ).arg( a, b ).arg( tolerance ) );
332 const thread_local QRegularExpression re(
"-?\\d+(?:\\.\\d+)?(?:[eE]\\d+)?" );
334 QString a0( a ), b0( b );
335 a0.replace( re, QStringLiteral(
"#" ) );
336 b0.replace( re, QStringLiteral(
"#" ) );
338 QgsDebugMsg( QStringLiteral(
"a0:%1 b0:%2" ).arg( a0, b0 ) );
343 QList<double> al, bl;
346 QRegularExpressionMatch match = re.match( a );
347 while ( match.hasMatch() )
349 al << match.captured( 0 ).toDouble();
350 pos = match.capturedStart( 0 ) + match.capturedLength( 0 );
351 match = re.match( a, pos );
353 match = re.match( b );
354 while ( match.hasMatch() )
356 bl << match.captured( 0 ).toDouble();
357 pos = match.capturedStart( 0 ) + match.capturedLength( 0 );
358 match = re.match( b, pos );
361 if ( al.size() != bl.size() )
364 for (
int i = 0; i < al.size(); i++ )
The QgsMapSettings class contains configuration for rendering of the map.
This class allows checking rendered images against comparison images.
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.
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.
Flag
Render checker flags.
int elapsedTime() const
Returns the total elapsed time for the rendering test.
QString mRenderedImageFile
QString renderedImage() const
Returns the path of the rendered image generated by the test.
void setElapsedTimeTarget(int target)
QVector< QgsDartMeasurement > dartMeasurements() const
Gets access to buffered dash messages.
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 setExpectFail(bool expectFail)
Sets whether the comparison is expected to fail.
void setColorTolerance(unsigned int colorTolerance)
Set tolerance for color components used by runTest() and compareImages().
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)
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.
bool compareWkt(const QString &a, const QString &b, double tolerance=0.000001)
Compare two WKT strings with some tolerance.