QGIS API Documentation  2.3.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Protected Attributes | Private Attributes | List of all members
QgsRenderChecker Class Reference

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>

Collaboration diagram for QgsRenderChecker:
Collaboration graph
[legend]

Public Member Functions

 QgsRenderChecker ()
 
 ~QgsRenderChecker ()
 Destructor. More...
 
QString controlImagePath () const
 
QString report ()
 
float matchPercent ()
 
unsigned int mismatchCount ()
 
unsigned int matchTarget ()
 
int elapsedTime ()
 
void setElapsedTimeTarget (int theTarget)
 
void setControlName (const QString theName)
 Base directory name for the control image (with control image path suffixed) the path to the image will be constructed like this: controlImagePath + '/' + mControlName + '/' + mControlName + '.png'. More...
 
void setControlPathPrefix (const QString theName)
 Prefix where the control images are kept. More...
 
QString imageToHash (QString theImageFile)
 Get an md5 hash that uniquely identifies an image. More...
 
void setRenderedImage (QString theImageFileName)
 
Q_DECL_DEPRECATED void setMapRenderer (QgsMapRenderer *thepMapRenderer)
 
void setMapSettings (const QgsMapSettings &mapSettings)
 
void setColorTolerance (unsigned int theColorTolerance)
 Set tolerance for color components used by runTest() and compareImages(). More...
 
bool runTest (QString theTestName, unsigned int theMismatchCount=0)
 Test using renderer to generate the image to be compared. More...
 
bool compareImages (QString theTestName, unsigned int theMismatchCount=0, QString theRenderedImageFile="")
 Test using two arbitary images (map renderer will not be used) More...
 
bool isKnownAnomaly (QString theDiffImageFile)
 Get a list of all the anomalies. More...
 
QString expectedImageFile ()
 

Protected Attributes

QString mReport
 
unsigned int mMatchTarget
 
int mElapsedTime
 
QString mRenderedImageFile
 
QString mExpectedImageFile
 

Private Attributes

QString mControlName
 
unsigned int mMismatchCount
 
unsigned int mColorTolerance
 
int mElapsedTimeTarget
 
QgsMapSettings mMapSettings
 
QString mControlPathPrefix
 

Detailed Description

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 36 of file qgsrenderchecker.h.

Constructor & Destructor Documentation

QgsRenderChecker::QgsRenderChecker ( )

Definition at line 30 of file qgsrenderchecker.cpp.

QgsRenderChecker::~QgsRenderChecker ( )
inline

Destructor.

Definition at line 43 of file qgsrenderchecker.h.

Member Function Documentation

bool QgsRenderChecker::compareImages ( QString  theTestName,
unsigned int  theMismatchCount = 0,
QString  theRenderedImageFile = "" 
)

Test using two arbitary images (map renderer will not be used)

Parameters
theTestName- to be used as the basis for writing a file to e.g. /tmp/theTestName.png
theMismatchCount- 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.
theRenderedImageFileto optionally override the output filename
Note
: make sure to call setExpectedImage and setRenderedImage first.

Definition at line 197 of file qgsrenderchecker.cpp.

References isKnownAnomaly(), mColorTolerance, mElapsedTime, mElapsedTimeTarget, mExpectedImageFile, mMatchTarget, mMismatchCount, mRenderedImageFile, and mReport.

Referenced by runTest().

QString QgsRenderChecker::controlImagePath ( ) const

Definition at line 43 of file qgsrenderchecker.cpp.

References mControlPathPrefix.

Referenced by isKnownAnomaly(), and setControlName().

int QgsRenderChecker::elapsedTime ( )
inline

Definition at line 56 of file qgsrenderchecker.h.

QString QgsRenderChecker::expectedImageFile ( )
inline

Definition at line 118 of file qgsrenderchecker.h.

QString QgsRenderChecker::imageToHash ( QString  theImageFile)

Get an md5 hash that uniquely identifies an image.

Definition at line 58 of file qgsrenderchecker.cpp.

Referenced by isKnownAnomaly().

bool QgsRenderChecker::isKnownAnomaly ( QString  theDiffImageFile)

Get 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 acceptible. If the render diff matches one of these anomalies we will still consider it to be acceptible.

Returns
a bool indicating if the diff matched one of the anomaly files

Definition at line 81 of file qgsrenderchecker.cpp.

References controlImagePath(), imageToHash(), mControlName, mExpectedImageFile, and mReport.

Referenced by compareImages().

float QgsRenderChecker::matchPercent ( )
inline

Definition at line 48 of file qgsrenderchecker.h.

unsigned int QgsRenderChecker::matchTarget ( )
inline

Definition at line 54 of file qgsrenderchecker.h.

unsigned int QgsRenderChecker::mismatchCount ( )
inline

Definition at line 53 of file qgsrenderchecker.h.

QString QgsRenderChecker::report ( )
inline

Definition at line 47 of file qgsrenderchecker.h.

bool QgsRenderChecker::runTest ( QString  theTestName,
unsigned int  theMismatchCount = 0 
)

Test using renderer to generate the image to be compared.

Parameters
theTestName- to be used as the basis for writing a file to e.g. /tmp/theTestName.png
theMismatchCount- 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.
Note
make sure to call setExpectedImage and setMapRenderer first

Definition at line 132 of file qgsrenderchecker.cpp.

References QgsMapSettings::Antialiasing, compareImages(), QgsMapSettings::extent(), QgsMapSettings::mapUnitsPerPixel(), mElapsedTime, mExpectedImageFile, mMapSettings, mMatchTarget, mRenderedImageFile, mReport, qgsDoubleToString(), QgsMapRendererSequentialJob::renderedImage(), QgsMapSettings::setBackgroundColor(), QgsMapSettings::setFlag(), QgsMapSettings::setOutputSize(), QgsMapRendererSequentialJob::start(), QgsMapRendererSequentialJob::waitForFinished(), QgsRectangle::xMinimum(), and QgsRectangle::yMaximum().

void QgsRenderChecker::setColorTolerance ( unsigned int  theColorTolerance)
inline

Set tolerance for color components used by runTest() and compareImages().

Default value is 0.

Parameters
theColorToleranceis maximum difference for each color component including alpha to be considered correct.
Note
added in 2.1

Definition at line 84 of file qgsrenderchecker.h.

void QgsRenderChecker::setControlName ( const QString  theName)

Base directory name for the control image (with control image path suffixed) the path to the image will be constructed like this: controlImagePath + '/' + mControlName + '/' + mControlName + '.png'.

Definition at line 51 of file qgsrenderchecker.cpp.

References controlImagePath(), mControlName, and mExpectedImageFile.

void QgsRenderChecker::setControlPathPrefix ( const QString  theName)
inline

Prefix where the control images are kept.

This will be appended to controlImagePath

Definition at line 66 of file qgsrenderchecker.h.

void QgsRenderChecker::setElapsedTimeTarget ( int  theTarget)
inline

Definition at line 57 of file qgsrenderchecker.h.

void QgsRenderChecker::setMapRenderer ( QgsMapRenderer thepMapRenderer)
Deprecated:
since 2.4 - use setMapSettings()

Definition at line 71 of file qgsrenderchecker.cpp.

References QgsMapRenderer::mapSettings(), and mMapSettings.

void QgsRenderChecker::setMapSettings ( const QgsMapSettings mapSettings)
Note
added in 2.4

Definition at line 76 of file qgsrenderchecker.cpp.

References mMapSettings.

void QgsRenderChecker::setRenderedImage ( QString  theImageFileName)
inline

Definition at line 70 of file qgsrenderchecker.h.

Member Data Documentation

unsigned int QgsRenderChecker::mColorTolerance
private

Definition at line 132 of file qgsrenderchecker.h.

Referenced by compareImages().

QString QgsRenderChecker::mControlName
private

Definition at line 130 of file qgsrenderchecker.h.

Referenced by isKnownAnomaly(), and setControlName().

QString QgsRenderChecker::mControlPathPrefix
private

Definition at line 135 of file qgsrenderchecker.h.

Referenced by controlImagePath().

int QgsRenderChecker::mElapsedTime
protected

Definition at line 124 of file qgsrenderchecker.h.

Referenced by compareImages(), and runTest().

int QgsRenderChecker::mElapsedTimeTarget
private

Definition at line 133 of file qgsrenderchecker.h.

Referenced by compareImages().

QString QgsRenderChecker::mExpectedImageFile
protected

Definition at line 126 of file qgsrenderchecker.h.

Referenced by compareImages(), isKnownAnomaly(), runTest(), and setControlName().

QgsMapSettings QgsRenderChecker::mMapSettings
private

Definition at line 134 of file qgsrenderchecker.h.

Referenced by runTest(), setMapRenderer(), and setMapSettings().

unsigned int QgsRenderChecker::mMatchTarget
protected

Definition at line 123 of file qgsrenderchecker.h.

Referenced by compareImages(), and runTest().

unsigned int QgsRenderChecker::mMismatchCount
private

Definition at line 131 of file qgsrenderchecker.h.

Referenced by compareImages().

QString QgsRenderChecker::mRenderedImageFile
protected

Definition at line 125 of file qgsrenderchecker.h.

Referenced by compareImages(), and runTest().

QString QgsRenderChecker::mReport
protected

Definition at line 118 of file qgsrenderchecker.h.

Referenced by compareImages(), isKnownAnomaly(), and runTest().


The documentation for this class was generated from the following files: