16#ifndef QGSRENDERCHECKER_H
17#define QGSRENDERCHECKER_H
27#include <QRegularExpression>
32#define DUMP_BASE64_IMAGES 0
91 QString
report(
bool ignoreSuccess =
true )
const;
109 return static_cast<float>( mMismatchCount ) /
138 void setControlName(
const QString &name );
152 void setControlPathSuffix(
const QString &name );
155 QString imageToHash(
const QString &imageFile );
191 void setSizeTolerance(
int xTolerance,
int yTolerance ) { mMaxSizeDifferenceX = xTolerance; mMaxSizeDifferenceY = yTolerance; }
200 AvoidExportingRenderedImage = 1 << 0,
296 static QString sourcePath();
313#if DUMP_BASE64_IMAGES
314 void dumpRenderedImageAsBase64();
317 void performPostTestActions(
Flags flags );
319 bool mResult =
false;
320 bool mExpectFail =
false;
324 QString mControlName;
325 unsigned int mMismatchCount = 0;
326 unsigned int mColorTolerance = 0;
327 int mMaxSizeDifferenceX = 0;
328 int mMaxSizeDifferenceY = 0;
329 int mElapsedTimeTarget = 0;
331 QString mControlExtension = QStringLiteral(
"png" );
332 QString mControlPathPrefix;
333 QString mControlPathSuffix;
334 bool mIsCiRun =
false;
335 QVector<QgsDartMeasurement> mDashMessages;
336 bool mBufferDashMessages =
false;
337 QString mDiffImageFile;
352inline
bool compareWkt( const QString &a, const QString &b,
double tolerance = 0.000001 )
354 QgsDebugMsgLevel( QStringLiteral(
"a:%1 b:%2 tol:%3" ).arg( a, b ).arg( tolerance ), 2 );
355 const thread_local QRegularExpression re(
"-?\\d+(?:\\.\\d+)?(?:[eE]\\d+)?" );
357 QString a0( a ), b0( b );
358 a0.replace( re, QStringLiteral(
"#" ) );
359 b0.replace( re, QStringLiteral(
"#" ) );
366 QList<double> al, bl;
369 QRegularExpressionMatch match = re.match( a );
370 while ( match.hasMatch() )
372 al << match.captured( 0 ).toDouble();
373 pos = match.capturedStart( 0 ) + match.capturedLength( 0 );
374 match = re.match( a, pos );
376 match = re.match( b );
377 while ( match.hasMatch() )
379 bl << match.captured( 0 ).toDouble();
380 pos = match.capturedStart( 0 ) + match.capturedLength( 0 );
381 match = re.match( b, pos );
384 if ( al.size() != bl.size() )
387 for (
int i = 0; i < al.size(); i++ )
Emits dart measurements for display in CDash reports.
Contains configuration for rendering maps.
Q_DECL_DEPRECATED bool isKnownAnomaly(const QString &diffImageFile)
Gets a list of all the anomalies.
static QDir testReportDir()
Returns the directory to use for generating a test report.
QString markdownReport(bool ignoreSuccess=true) const
Returns the markdown report describing the results of the test run.
void setControlExtension(const QString &extension)
Sets file extension for the control image.
friend class QgsMultiRenderChecker
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 mReport
HTML format report.
static bool shouldGenerateReport()
Returns true if a test report should be generated given the current environment.
unsigned int mMatchTarget
void setControlImagePath(const QString &path)
Sets the base path containing the reference images.
bool runTest(const QString &testName, unsigned int mismatchCount=0, QgsRenderChecker::Flags flags=QgsRenderChecker::Flags())
Test using renderer to generate the image to be compared.
QFlags< Flag > Flags
Render checker flags.
Flag
Render checker flags.
int elapsedTime() const
Returns the total elapsed time for the rendering test.
QString mRenderedImageFile
QString mMarkdownReport
Markdown report.
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.
QString report(bool ignoreSuccess=true) const
Returns the HTML report describing the results of the test run.
static void drawBackground(QImage *image)
Draws a checkboard pattern for image backgrounds, so that opacity is visible without requiring a tran...
bool compareImages(const QString &testName, unsigned int mismatchCount=0, const QString &renderedImageFile=QString(), QgsRenderChecker::Flags flags=QgsRenderChecker::Flags())
Test using two arbitrary images (map renderer will not be used).
void setRenderedImage(const QString &imageFileName)
Sets the file name of the rendered image generated by the test.
QgsRenderChecker()
Constructor for QgsRenderChecker.
QString mExpectedImageFile
QString controlImagePath() const
Returns the base path containing the reference images.
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).
#define SIP_ENUM_BASETYPE(type)
#define QgsDebugMsgLevel(str, level)
bool compareWkt(const QString &a, const QString &b, double tolerance=0.000001)
Compare two WKT strings with some tolerance.