27 mControlPathPrefix = prefix;
32 mMapSettings = mapSettings;
37 bool successful =
false;
41 QStringList subDirs = QDir( baseDir ).entryList( QDir::Dirs | QDir::NoDotAndDotDot );
43 if ( subDirs.isEmpty() )
48 QVector<QgsDartMeasurement> dartMeasurements;
50 Q_FOREACH (
const QString &suffix, subDirs )
52 qDebug() <<
"Checking subdir " << suffix;
63 if ( !mRenderedImage.isNull() )
66 result = checker.
compareImages( testName, mismatchCount, mRenderedImage );
70 result = checker.
runTest( testName, mismatchCount );
78 mReport += checker.
report();
87 "If this is a rendering inconsistency, please add another control image folder, add an anomaly image or increase the color tolerance." );
96 QString myDataDir( TEST_DATA_DIR );
97 QString myControlImageDir = myDataDir + QDir::separator() +
"control_images" +
98 QDir::separator() + mControlPathPrefix + QDir::separator() + mControlName + QDir::separator();
99 return myControlImageDir;
108 QgsLayoutChecker::QgsLayoutChecker(
const QString &testName,
QgsLayout *layout )
109 : mTestName( testName )
112 , mDotsPerMeter( 96 / 25.4 * 1000 )
118 bool QgsLayoutChecker::testLayout( QString &checkedReport,
int page,
int pixelDiff,
bool createReferenceImage )
128 if ( createReferenceImage )
134 QImage _outputImage( mSize, QImage::Format_RGB32 );
135 _outputImage.setDotsPerMeterX( 96 / 25.4 * 1000 );
136 _outputImage.setDotsPerMeterY( 96 / 25.4 * 1000 );
137 QPainter _p( &_outputImage );
146 _outputImage.save(
controlImagePath() + QDir::separator() +
"expected_" + mTestName +
".png",
"PNG" );
147 qDebug( ) <<
"Reference image saved to : " +
controlImagePath() + QDir::separator() +
"expected_" + mTestName +
".png";
151 QImage outputImage( mSize, QImage::Format_RGB32 );
152 outputImage.setDotsPerMeterX( mDotsPerMeter );
153 outputImage.setDotsPerMeterY( mDotsPerMeter );
155 QPainter p( &outputImage );
160 QString renderedFilePath = QDir::tempPath() +
'/' + QFileInfo( mTestName ).baseName() +
"_rendered.png";
161 outputImage.save( renderedFilePath,
"PNG" );
165 bool testResult =
runTest( mTestName, pixelDiff );
167 checkedReport +=
report();
void setColorTolerance(unsigned int colorTolerance)
Set tolerance for color components used by runTest() Default value is 0.
QVector< QgsDartMeasurement > dartMeasurements() const
Gets access to buffered dash messages.
void enableDashBuffering(bool enable)
Call this to enable internal buffering of dash messages.
void setRenderedImage(const QString &imageFileName)
QString renderedImage()
The path of the rendered image can be retrieved through that method.
This is a helper class for unit tests that need to write an image and compare it to an expected resul...
void setMapSettings(const QgsMapSettings &mapSettings)
void setSizeTolerance(int xTolerance, int yTolerance)
Sets the largest allowable difference in size between the rendered and the expected image...
The QgsMapSettings class contains configuration for rendering of the map.
void setControlName(const QString &name)
Base directory name for the control image (with control image path suffixed) the path to the image wi...
QString report() const
Returns a report for this test.
void setControlPathPrefix(const QString &name)
Prefix where the control images are kept.
void setMapSettings(const QgsMapSettings &mapSettings)
Set the map settings to use to render the image.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
void setControlPathPrefix(const QString &prefix)
bool runTest(const QString &testName, unsigned int mismatchCount=0)
Test using renderer to generate the image to be compared.
bool compareImages(const QString &testName, unsigned int mismatchCount=0, const QString &renderedImageFile=QString())
Test using two arbitrary images (map renderer will not be used)
Handles rendering and exports of layouts to various formats.
bool runTest(const QString &testName, unsigned int mismatchCount=0)
Test using renderer to generate the image to be compared.
void setColorTolerance(unsigned int colorTolerance)
Set tolerance for color components used by runTest() and compareImages().
void renderPage(QPainter *painter, int page) const
Renders a full page to a destination painter.
void setControlPathSuffix(const QString &name)
QString controlImagePath() const
Returns the path to the control images.
static void drawBackground(QImage *image)
Draws a checkboard pattern for image backgrounds, so that opacity is visible without requiring a tran...
void setRenderedImage(const QString &renderedImagePath)
Set the path to the rendered image.
void setControlName(const QString &name)
Base directory name for the control image (with control image path suffixed) the path to the image wi...