QGIS API Documentation
3.22.4-Białowieża (ce8e65e95e)
|
This is a helper class for unit tests that need to write an image and compare it to an expected result or render time. More...
#include <qgsrenderchecker.h>
Public Member Functions | |
QgsRenderChecker () | |
Constructor for QgsRenderChecker. More... | |
bool | compareImages (const QString &testName, const QString &referenceImageFile, const QString &renderedImageFile, unsigned int mismatchCount=0) |
Test using two arbitrary images at the specified paths for equality. More... | |
bool | compareImages (const QString &testName, unsigned int mismatchCount=0, const QString &renderedImageFile=QString()) |
Test using two arbitrary images (map renderer will not be used) More... | |
QString | controlImagePath () const |
Returns the base path containing the reference images. More... | |
QVector< QgsDartMeasurement > | dartMeasurements () const |
Gets access to buffered dash messages. More... | |
int | elapsedTime () |
Returns the total elapsed time for the rendering test. More... | |
void | enableDashBuffering (bool enable) |
Call this to enable internal buffering of dash messages. More... | |
QString | expectedImageFile () const |
Returns the path to the expected image file. More... | |
QString | imageToHash (const QString &imageFile) |
Gets an md5 hash that uniquely identifies an image. More... | |
bool | isKnownAnomaly (const QString &diffImageFile) |
Gets a list of all the anomalies. More... | |
float | matchPercent () const |
Returns the percent of pixels which matched the control image. More... | |
unsigned int | matchTarget () const |
Returns the total number of pixels in the control image. More... | |
unsigned int | mismatchCount () const |
Returns the number of pixels which did not match the control image. More... | |
QString | renderedImage () const |
Returns the path of the rendered image generated by the test. More... | |
QString | report () |
Returns the HTML report describing the results of the test run. More... | |
bool | runTest (const QString &testName, unsigned int mismatchCount=0) |
Test using renderer to generate the image to be compared. More... | |
void | setColorTolerance (unsigned int colorTolerance) |
Set tolerance for color components used by runTest() and compareImages(). More... | |
void | setControlExtension (const QString &extension) |
Sets file extension for the control image. More... | |
void | setControlImagePath (const QString &path) |
Sets the base path containing the reference images. More... | |
void | setControlName (const QString &name) |
Sets the base directory name for the control image (with control image path suffixed). More... | |
void | setControlPathPrefix (const QString &name) |
Sets the path prefix where the control images are kept. More... | |
void | setControlPathSuffix (const QString &name) |
void | setElapsedTimeTarget (int target) |
void | setMapSettings (const QgsMapSettings &mapSettings) |
void | setRenderedImage (const QString &imageFileName) |
Sets the file name of the rendered image generated by the test. More... | |
void | setSizeTolerance (int xTolerance, int yTolerance) |
Sets the largest allowable difference in size between the rendered and the expected image. More... | |
Static Public Member Functions | |
static void | drawBackground (QImage *image) |
Draws a checkboard pattern for image backgrounds, so that opacity is visible without requiring a transparent background for the image. More... | |
Protected Attributes | |
int | mElapsedTime = 0 |
QString | mExpectedImageFile |
unsigned int | mMatchTarget = 0 |
QString | mRenderedImageFile |
QString | mReport |
This is a helper class for unit tests that need to write an image and compare it to an expected result or render time.
Definition at line 39 of file qgsrenderchecker.h.
QgsRenderChecker::QgsRenderChecker | ( | ) |
Constructor for QgsRenderChecker.
Definition at line 31 of file qgsrenderchecker.cpp.
bool QgsRenderChecker::compareImages | ( | const QString & | testName, |
const QString & | referenceImageFile, | ||
const QString & | renderedImageFile, | ||
unsigned int | mismatchCount = 0 |
||
) |
Test using two arbitrary images at the specified paths for equality.
Definition at line 258 of file qgsrenderchecker.cpp.
bool QgsRenderChecker::compareImages | ( | const QString & | testName, |
unsigned int | mismatchCount = 0 , |
||
const QString & | renderedImageFile = QString() |
||
) |
Test using two arbitrary images (map renderer will not be used)
testName | - to be used as the basis for writing a file to e.g. /tmp/theTestName.png |
mismatchCount | - defaults to 0 - the number of pixels that are allowed to be different from the control image. In some cases rendering may be non-deterministic. This parameter allows you to account for that by providing a tolerance. |
renderedImageFile | to optionally override the output filename |
Definition at line 241 of file qgsrenderchecker.cpp.
QString QgsRenderChecker::controlImagePath | ( | ) | const |
Returns the base path containing the reference images.
This defaults to an internal QGIS test data path, but can be changed via setControlImagePath().
Definition at line 36 of file qgsrenderchecker.cpp.
|
inline |
Gets access to buffered dash messages.
Only will return something if you call enableDashBuffering( true
); before.
Definition at line 225 of file qgsrenderchecker.h.
|
static |
Draws a checkboard pattern for image backgrounds, so that opacity is visible without requiring a transparent background for the image.
Definition at line 78 of file qgsrenderchecker.cpp.
|
inline |
Returns the total elapsed time for the rendering test.
Definition at line 94 of file qgsrenderchecker.h.
|
inline |
Call this to enable internal buffering of dash messages.
You may later call dashMessages() to get access to the buffered messages. If disabled (default) dash messages will be sent immediately.
enable | Enable or disable buffering |
Definition at line 217 of file qgsrenderchecker.h.
|
inline |
Returns the path to the expected image file.
Definition at line 208 of file qgsrenderchecker.h.
QString QgsRenderChecker::imageToHash | ( | const QString & | imageFile | ) |
Gets an md5 hash that uniquely identifies an image.
Definition at line 60 of file qgsrenderchecker.cpp.
bool QgsRenderChecker::isKnownAnomaly | ( | const QString & | diffImageFile | ) |
Gets a list of all the anomalies.
An anomaly is a rendered difference file where there is some red pixel content (indicating a render check mismatch), but where the output was still acceptable. If the render diff matches one of these anomalies we will still consider it to be acceptable.
Definition at line 99 of file qgsrenderchecker.cpp.
|
inline |
Returns the percent of pixels which matched the control image.
Definition at line 73 of file qgsrenderchecker.h.
|
inline |
Returns the total number of pixels in the control image.
Definition at line 87 of file qgsrenderchecker.h.
|
inline |
Returns the number of pixels which did not match the control image.
Definition at line 82 of file qgsrenderchecker.h.
|
inline |
Returns the path of the rendered image generated by the test.
This method will return either the path set with setRenderedImage() or generated in runTest().
Definition at line 133 of file qgsrenderchecker.h.
|
inline |
Returns the HTML report describing the results of the test run.
Definition at line 68 of file qgsrenderchecker.h.
bool QgsRenderChecker::runTest | ( | const QString & | testName, |
unsigned int | mismatchCount = 0 |
||
) |
Test using renderer to generate the image to be compared.
testName | - to be used as the basis for writing a file to e.g. /tmp/theTestName.png |
mismatchCount | - defaults to 0 - the number of pixels that are allowed to be different from the control image. In some cases rendering may be non-deterministic. This parameter allows you to account for that by providing a tolerance. |
Definition at line 159 of file qgsrenderchecker.cpp.
|
inline |
Set tolerance for color components used by runTest() and compareImages().
Default value is 0.
colorTolerance | is maximum difference for each color component including alpha to be considered correct. |
Definition at line 145 of file qgsrenderchecker.h.
|
inline |
Sets file extension for the control image.
By default it is "png"
Definition at line 110 of file qgsrenderchecker.h.
void QgsRenderChecker::setControlImagePath | ( | const QString & | path | ) |
Sets the base path containing the reference images.
Definition at line 41 of file qgsrenderchecker.cpp.
void QgsRenderChecker::setControlName | ( | const QString & | name | ) |
Sets the base directory name for the control image (with control image path suffixed).
The path to the image will be constructed like this: controlImagePath() + '/' + control name + '/' + control name + '.' + extension ('png' by default)
Definition at line 46 of file qgsrenderchecker.cpp.
|
inline |
Sets the path prefix where the control images are kept.
This will be appended to controlImagePath().
Definition at line 116 of file qgsrenderchecker.h.
void QgsRenderChecker::setControlPathSuffix | ( | const QString & | name | ) |
Definition at line 52 of file qgsrenderchecker.cpp.
|
inline |
Definition at line 95 of file qgsrenderchecker.h.
void QgsRenderChecker::setMapSettings | ( | const QgsMapSettings & | mapSettings | ) |
Definition at line 73 of file qgsrenderchecker.cpp.
|
inline |
Sets the file name of the rendered image generated by the test.
Definition at line 126 of file qgsrenderchecker.h.
|
inline |
Sets the largest allowable difference in size between the rendered and the expected image.
xTolerance | x tolerance in pixels |
yTolerance | y tolerance in pixels |
Definition at line 153 of file qgsrenderchecker.h.
|
protected |
Definition at line 230 of file qgsrenderchecker.h.
|
protected |
Definition at line 232 of file qgsrenderchecker.h.
|
protected |
Definition at line 229 of file qgsrenderchecker.h.
|
protected |
Definition at line 231 of file qgsrenderchecker.h.
|
protected |
Definition at line 228 of file qgsrenderchecker.h.