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 const auto constSubDirs = subDirs;
51 for (
const QString &suffix : constSubDirs )
53 qDebug() <<
"Checking subdir " << suffix;
64 if ( !mRenderedImage.isNull() )
67 result = checker.
compareImages( testName, mismatchCount, mRenderedImage );
71 result = checker.
runTest( testName, mismatchCount );
79 mReport += checker.
report();
84 const auto constDartMeasurements = dartMeasurements;
89 "If this is a rendering inconsistency, please add another control image folder, add an anomaly image or increase the color tolerance." );
98 QString myDataDir( TEST_DATA_DIR );
99 QString myControlImageDir = myDataDir + QDir::separator() +
"control_images" +
100 QDir::separator() + mControlPathPrefix + QDir::separator() + mControlName + QDir::separator();
101 return myControlImageDir;
110 QgsLayoutChecker::QgsLayoutChecker(
const QString &testName,
QgsLayout *layout )
111 : mTestName( testName )
114 , mDotsPerMeter( 96 / 25.4 * 1000 )
120 bool QgsLayoutChecker::testLayout( QString &checkedReport,
int page,
int pixelDiff,
bool createReferenceImage )
130 if ( createReferenceImage )
136 QImage _outputImage( mSize, QImage::Format_RGB32 );
137 _outputImage.setDotsPerMeterX( 96 / 25.4 * 1000 );
138 _outputImage.setDotsPerMeterY( 96 / 25.4 * 1000 );
139 QPainter _p( &_outputImage );
148 _outputImage.save(
controlImagePath() + QDir::separator() +
"expected_" + mTestName +
".png",
"PNG" );
149 qDebug( ) <<
"Reference image saved to : " +
controlImagePath() + QDir::separator() +
"expected_" + mTestName +
".png";
153 QImage outputImage( mSize, QImage::Format_RGB32 );
154 outputImage.setDotsPerMeterX( mDotsPerMeter );
155 outputImage.setDotsPerMeterY( mDotsPerMeter );
157 QPainter p( &outputImage );
162 QString renderedFilePath = QDir::tempPath() +
'/' + QFileInfo( mTestName ).baseName() +
"_rendered.png";
163 outputImage.save( renderedFilePath,
"PNG" );
167 bool testResult =
runTest( mTestName, pixelDiff );
169 checkedReport +=
report();
void setColorTolerance(unsigned int colorTolerance)
Set tolerance for color components used by runTest() Default value is 0.
void enableDashBuffering(bool enable)
Call this to enable internal buffering of dash messages.
void setRenderedImage(const QString &imageFileName)
QString report() const
Returns a report for this test.
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 controlImagePath() const
Returns the path to the control images.
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.
QVector< QgsDartMeasurement > dartMeasurements() const
Gets access to buffered dash messages.
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 setControlPathSuffix(const QString &name)
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...
void renderPage(QPainter *painter, int page) const
Renders a full page to a destination painter.