1515
1616#include " qgscompositionchecker.h"
1717#include " qgscomposition.h"
18+ #include < QDebug>
1819#include < QDir>
1920#include < QFileInfo>
2021#include < QImage>
2122#include < QPainter>
2223
23- QgsCompositionChecker::QgsCompositionChecker ( QgsComposition* composition, const QString& expectedImageFile ): mComposition( composition ), mExpectedImageFile( expectedImageFile )
24+ QgsCompositionChecker::QgsCompositionChecker ( const QString& testName, QgsComposition* composition, const QString& expectedImageFile ): mTestName( testName ),
25+ mComposition( composition ), mExpectedImageFile( expectedImageFile )
2426{
2527}
2628
@@ -73,19 +75,33 @@ bool QgsCompositionChecker::testComposition()
7375 mComposition ->render ( &p, targetArea, sourceArea );
7476 p.end ();
7577
78+ QString renderedFilePath = QDir::tempPath () + QDir::separator () + QFileInfo ( mExpectedImageFile ).baseName () + " _rendered.png" ;
79+ outputImage.save ( renderedFilePath, " PNG" );
80+
7681 QString diffFilePath = QDir::tempPath () + QDir::separator () + QFileInfo ( mExpectedImageFile ).baseName () + " _diff.png" ;
77- return compareImages ( expectedImage, outputImage, diffFilePath );
82+ bool testResult = compareImages ( expectedImage, outputImage, diffFilePath );
83+
84+ QString myDashMessage = " <DartMeasurementFile name=\" Rendered Image " + mTestName + " \" "
85+ " type=\" image/png\" >" + renderedFilePath +
86+ " </DartMeasurementFile>"
87+ " <DartMeasurementFile name=\" Expected Image " + mTestName + " \" type=\" image/png\" >" +
88+ mExpectedImageFile + " </DartMeasurementFile>"
89+ " <DartMeasurementFile name=\" Difference Image " + mTestName + " \" type=\" image/png\" >" +
90+ diffFilePath + " </DartMeasurementFile>" ;
91+ qDebug ( ) << myDashMessage;
92+
93+ return testResult;
7894}
7995
80- bool QgsCompositionChecker::compareImages ( const QImage& img1 , const QImage& img2 , const QString& differenceImagePath ) const
96+ bool QgsCompositionChecker::compareImages ( const QImage& imgExpected , const QImage& imgRendered , const QString& differenceImagePath ) const
8197{
82- if ( img1 .width () != img2 .width () || img1 .height () != img2 .height () )
98+ if ( imgExpected .width () != imgRendered .width () || imgExpected .height () != imgRendered .height () )
8399 {
84100 return false ;
85101 }
86102
87- int imageWidth = img1 .width ();
88- int imageHeight = img1 .height ();
103+ int imageWidth = imgExpected .width ();
104+ int imageHeight = imgExpected .height ();
89105 int mismatchCount = 0 ;
90106
91107 QImage differenceImage ( imageWidth, imageHeight, QImage::Format_ARGB32_Premultiplied );
@@ -96,8 +112,8 @@ bool QgsCompositionChecker::compareImages( const QImage& img1, const QImage& img
96112 {
97113 for ( int j = 0 ; j < imageWidth; ++j )
98114 {
99- pixel1 = img1 .pixel ( j, i );
100- pixel2 = img2 .pixel ( j, i );
115+ pixel1 = imgExpected .pixel ( j, i );
116+ pixel2 = imgRendered .pixel ( j, i );
101117 if ( pixel1 != pixel2 )
102118 {
103119 ++mismatchCount;
0 commit comments