22 if ( qgetenv(
"QGIS_CONTINUOUS_INTEGRATION_RUN" ) == QStringLiteral(
"true" ) )
33 mControlPathPrefix = prefix;
38 mMapSettings = mapSettings;
45 mReport +=
"<h2>" + testName +
"</h2>\n";
49 QStringList subDirs = QDir( baseDir ).entryList( QDir::Dirs | QDir::NoDotAndDotDot );
51 if ( subDirs.isEmpty() )
56 QVector<QgsDartMeasurement> dartMeasurements;
58 for (
const QString &suffix : std::as_const( subDirs ) )
60 if ( subDirs.count() > 1 )
62 qDebug() <<
"Checking subdir " << suffix;
74 if ( !mRenderedImage.isNull() )
89 mReport += checker.
report(
false );
92 if ( !mResult && !mExpectFail && mIsCiRun )
94 const auto constDartMeasurements = dartMeasurements;
99 "If this is a rendering inconsistency, please add another control image folder, add an anomaly image or increase the color tolerance." );
102 #if DUMP_BASE64_IMAGES
103 QFile fileSource( mRenderedImage );
104 fileSource.open( QIODevice::ReadOnly );
106 const QByteArray blob = fileSource.readAll();
107 const QByteArray encoded = blob.toBase64();
108 qDebug() <<
"Dumping rendered image " << mRenderedImage <<
" as base64\n";
109 qDebug() <<
"################################################################";
111 qDebug() <<
"################################################################";
112 qDebug() <<
"End dump";
116 if ( !mResult && !mExpectFail )
119 if ( !reportDir.exists() )
121 if ( !QDir().mkpath( reportDir.path() ) )
123 qDebug() <<
"!!!!! cannot create " << reportDir.path();
126 if ( QFile::exists( mRenderedImage ) )
128 QFileInfo fi( mRenderedImage );
129 const QString destPath = reportDir.filePath( fi.fileName() );
130 if ( !QFile::copy( mRenderedImage, destPath ) )
132 qDebug() <<
"!!!!! could not copy " << mRenderedImage <<
" to " << destPath;
142 return !mResult ? mReport : QString();
147 QString myDataDir( TEST_DATA_DIR );
148 QString myControlImageDir = myDataDir + QDir::separator() +
"control_images" +
149 QDir::separator() + mControlPathPrefix + QDir::separator() + mControlName + QDir::separator();
150 return myControlImageDir;
159 QgsLayoutChecker::QgsLayoutChecker(
const QString &testName,
QgsLayout *layout )
160 : mTestName( testName )
163 , mDotsPerMeter( 96 / 25.4 * 1000 )
169 bool QgsLayoutChecker::testLayout( QString &checkedReport,
int page,
int pixelDiff,
bool createReferenceImage )
179 setControlName(
"expected_" + mTestName );
182 if ( createReferenceImage )
188 QImage _outputImage( mSize, QImage::Format_RGB32 );
189 _outputImage.setDotsPerMeterX( 96 / 25.4 * 1000 );
190 _outputImage.setDotsPerMeterY( 96 / 25.4 * 1000 );
191 QPainter _p( &_outputImage );
193 _exporter.renderPage( &_p, page );
196 if ( ! QDir( controlImagePath() ).exists() )
198 QDir().mkdir( controlImagePath() );
200 _outputImage.save( controlImagePath() + QDir::separator() +
"expected_" + mTestName +
".png",
"PNG" );
201 qDebug( ) <<
"Reference image saved to : " + controlImagePath() + QDir::separator() +
"expected_" + mTestName +
".png";
205 QImage outputImage( mSize, QImage::Format_RGB32 );
206 outputImage.setDotsPerMeterX( mDotsPerMeter );
207 outputImage.setDotsPerMeterY( mDotsPerMeter );
208 drawBackground( &outputImage );
209 QPainter p( &outputImage );
211 exporter.renderPage( &p, page );
214 QString renderedFilePath = QDir::tempPath() +
'/' + QFileInfo( mTestName ).baseName() +
"_rendered.png";
215 outputImage.save( renderedFilePath,
"PNG" );
217 setRenderedImage( renderedFilePath );
219 bool testResult = runTest( mTestName, pixelDiff );
221 checkedReport += report();
224 #endif // QT_NO_PRINTER