2012-09-04 20:31:59 +02:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Render checker for tests in python */
|
2012-09-04 20:31:59 +02:00
|
|
|
|
|
|
|
class QgsRenderChecker
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsrenderchecker.h>
|
|
|
|
%End
|
|
|
|
public:
|
|
|
|
|
|
|
|
QgsRenderChecker();
|
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
//! Destructor
|
2012-09-04 20:31:59 +02:00
|
|
|
~QgsRenderChecker();
|
|
|
|
|
|
|
|
QString controlImagePath() const;
|
|
|
|
|
|
|
|
QString report();
|
|
|
|
float matchPercent();
|
|
|
|
unsigned int mismatchCount();
|
|
|
|
unsigned int matchTarget();
|
2014-01-26 18:35:21 +01:00
|
|
|
//only records time for actual render part
|
2012-09-04 20:31:59 +02:00
|
|
|
int elapsedTime();
|
2017-02-21 18:14:58 +01:00
|
|
|
void setElapsedTimeTarget( int target );
|
2014-11-20 14:17:51 +01:00
|
|
|
|
2014-01-27 09:22:24 +01:00
|
|
|
/** Base directory name for the control image (with control image path
|
2016-02-14 03:50:23 +01:00
|
|
|
* suffixed) the path to the image will be constructed like this:
|
|
|
|
* controlImagePath + '/' + mControlName + '/' + mControlName + '.png'
|
|
|
|
*/
|
2017-02-21 18:14:58 +01:00
|
|
|
void setControlName( const QString &name );
|
2014-11-20 14:17:51 +01:00
|
|
|
|
2014-01-27 09:22:24 +01:00
|
|
|
/** Prefix where the control images are kept.
|
|
|
|
* This will be appended to controlImagePath
|
2016-02-14 03:50:23 +01:00
|
|
|
*/
|
2017-02-21 18:14:58 +01:00
|
|
|
void setControlPathPrefix( const QString &name );
|
2014-11-20 14:17:51 +01:00
|
|
|
|
2017-02-21 18:14:58 +01:00
|
|
|
void setControlPathSuffix( const QString& name );
|
2014-11-20 14:17:51 +01:00
|
|
|
|
2014-01-27 09:22:24 +01:00
|
|
|
/** Get an md5 hash that uniquely identifies an image */
|
2017-02-21 18:14:58 +01:00
|
|
|
QString imageToHash( const QString& imageFile );
|
2012-09-04 20:31:59 +02:00
|
|
|
|
2017-02-21 18:14:58 +01:00
|
|
|
void setRenderedImage( const QString& imageFileName );
|
2014-11-20 14:17:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The path of the rendered image can be retrieved through that method.
|
|
|
|
* Will return the path set with setRenderedImage() or generated in runTest()
|
|
|
|
*
|
|
|
|
* @return The path to the rendered image
|
|
|
|
*/
|
2015-10-27 14:03:00 +11:00
|
|
|
QString renderedImage();
|
2014-11-20 14:17:51 +01:00
|
|
|
|
2014-05-27 23:22:50 +02:00
|
|
|
//! @note added in 2.4
|
2013-12-11 16:21:35 +07:00
|
|
|
void setMapSettings( const QgsMapSettings& mapSettings );
|
2014-03-22 23:02:41 -06:00
|
|
|
|
|
|
|
/** Set tolerance for color components used by runTest() and compareImages().
|
|
|
|
* Default value is 0.
|
2017-02-21 18:14:58 +01:00
|
|
|
* @param colorTolerance is maximum difference for each color component
|
2014-03-22 23:02:41 -06:00
|
|
|
* including alpha to be considered correct.
|
|
|
|
* @note added in 2.1
|
|
|
|
*/
|
2017-02-21 18:14:58 +01:00
|
|
|
void setColorTolerance( unsigned int colorTolerance );
|
2015-07-10 16:52:52 +10:00
|
|
|
|
|
|
|
/** Sets the largest allowable difference in size between the rendered and the expected image.
|
|
|
|
* @param xTolerance x tolerance in pixels
|
|
|
|
* @param yTolerance y tolerance in pixels
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
void setSizeTolerance( int xTolerance, int yTolerance );
|
|
|
|
|
2014-01-26 18:35:21 +01:00
|
|
|
/**
|
|
|
|
* Test using renderer to generate the image to be compared.
|
2017-02-21 18:14:58 +01:00
|
|
|
* @param testName - to be used as the basis for writing a file to
|
2014-01-26 18:35:21 +01:00
|
|
|
* e.g. /tmp/theTestName.png
|
2017-02-21 18:14:58 +01:00
|
|
|
* @param mismatchCount - defaults to 0 - the number of pixels that
|
2014-01-26 18:35:21 +01:00
|
|
|
* 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
|
|
|
|
*/
|
2017-02-21 18:14:58 +01:00
|
|
|
bool runTest( const QString& testName, unsigned int mismatchCount = 0 );
|
2012-09-04 20:31:59 +02:00
|
|
|
|
2014-01-26 18:35:21 +01:00
|
|
|
/**
|
2017-01-12 22:01:50 +01:00
|
|
|
* Test using two arbitrary images (map renderer will not be used)
|
2017-02-21 18:14:58 +01:00
|
|
|
* @param testName - to be used as the basis for writing a file to
|
2014-01-26 18:35:21 +01:00
|
|
|
* e.g. /tmp/theTestName.png
|
2017-02-21 18:14:58 +01:00
|
|
|
* @param mismatchCount - defaults to 0 - the number of pixels that
|
2014-01-26 18:35:21 +01:00
|
|
|
* 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.
|
2017-02-21 18:14:58 +01:00
|
|
|
* @param renderedImageFile to optionally override the output filename
|
2014-01-26 18:35:21 +01:00
|
|
|
* @note: make sure to call setExpectedImage and setRenderedImage first.
|
|
|
|
*/
|
2017-02-21 18:14:58 +01:00
|
|
|
bool compareImages( const QString& testName, unsigned int mismatchCount = 0, const QString& renderedImageFile = "" );
|
2014-01-26 18:35:21 +01:00
|
|
|
/** Get a list of all the anomalies. An anomaly is a rendered difference
|
2016-02-14 03:50:23 +01:00
|
|
|
* file where there is some red pixel content (indicating a render check
|
2017-01-12 22:01:50 +01:00
|
|
|
* mismatch), but where the output was still acceptable. If the render
|
2016-02-14 03:50:23 +01:00
|
|
|
* diff matches one of these anomalies we will still consider it to be
|
2017-01-12 22:01:50 +01:00
|
|
|
* acceptable.
|
2016-02-14 03:50:23 +01:00
|
|
|
* @return a bool indicating if the diff matched one of the anomaly files
|
|
|
|
*/
|
2017-02-21 18:14:58 +01:00
|
|
|
bool isKnownAnomaly( const QString& diffImageFile );
|
2014-01-26 18:35:21 +01:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Draws a checkboard pattern for image backgrounds, so that transparency is visible
|
2014-11-14 22:25:57 +11:00
|
|
|
* without requiring a transparent background for the image
|
|
|
|
*/
|
2014-11-20 14:17:51 +01:00
|
|
|
static void drawBackground( QImage* image );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the path to the expected image file
|
|
|
|
*
|
|
|
|
* @return Path to the expected image file
|
|
|
|
*/
|
2015-10-27 14:03:00 +11:00
|
|
|
QString expectedImageFile() const;
|
2014-11-20 14:17:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param enable Enable or disable buffering
|
|
|
|
*/
|
|
|
|
void enableDashBuffering( bool enable );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get access to buffered dash messages.
|
|
|
|
* Only will return something if you call enableDashBuffering( true ); before.
|
|
|
|
*
|
|
|
|
* @return buffered dash messages
|
|
|
|
* @note not available in python bindings
|
|
|
|
*/
|
|
|
|
// const QVector<QgsDartMeasurement>& dartMeasurements() const;
|
2012-09-04 20:31:59 +02:00
|
|
|
};
|