Skip to content
Permalink
Browse files

Write results of compositionchecker to dash

  • Loading branch information
mhugent committed Jul 12, 2012
1 parent 7073ac2 commit 75d68cd09353ce5bfa3b7c3ae379d34b979ab963
@@ -15,12 +15,14 @@

#include "qgscompositionchecker.h"
#include "qgscomposition.h"
#include <QDebug>
#include <QDir>
#include <QFileInfo>
#include <QImage>
#include <QPainter>

QgsCompositionChecker::QgsCompositionChecker( QgsComposition* composition, const QString& expectedImageFile ): mComposition( composition ), mExpectedImageFile( expectedImageFile )
QgsCompositionChecker::QgsCompositionChecker( const QString& testName, QgsComposition* composition, const QString& expectedImageFile ): mTestName( testName ),
mComposition( composition ), mExpectedImageFile( expectedImageFile )
{
}

@@ -73,19 +75,33 @@ bool QgsCompositionChecker::testComposition()
mComposition->render( &p, targetArea, sourceArea );
p.end();

QString renderedFilePath = QDir::tempPath() + QDir::separator() + QFileInfo( mExpectedImageFile ).baseName() + "_rendered.png";
outputImage.save( renderedFilePath, "PNG" );

QString diffFilePath = QDir::tempPath() + QDir::separator() + QFileInfo( mExpectedImageFile ).baseName() + "_diff.png";
return compareImages( expectedImage, outputImage, diffFilePath );
bool testResult = compareImages( expectedImage, outputImage, diffFilePath );

QString myDashMessage = "<DartMeasurementFile name=\"Rendered Image " + mTestName + "\""
" type=\"image/png\">" + renderedFilePath +
"</DartMeasurementFile>"
"<DartMeasurementFile name=\"Expected Image " + mTestName + "\" type=\"image/png\">" +
mExpectedImageFile + "</DartMeasurementFile>"
"<DartMeasurementFile name=\"Difference Image " + mTestName + "\" type=\"image/png\">" +
diffFilePath + "</DartMeasurementFile>";
qDebug( ) << myDashMessage;

return testResult;
}

bool QgsCompositionChecker::compareImages( const QImage& img1, const QImage& img2, const QString& differenceImagePath ) const
bool QgsCompositionChecker::compareImages( const QImage& imgExpected, const QImage& imgRendered, const QString& differenceImagePath ) const
{
if ( img1.width() != img2.width() || img1.height() != img2.height() )
if ( imgExpected.width() != imgRendered.width() || imgExpected.height() != imgRendered.height() )
{
return false;
}

int imageWidth = img1.width();
int imageHeight = img1.height();
int imageWidth = imgExpected.width();
int imageHeight = imgExpected.height();
int mismatchCount = 0;

QImage differenceImage( imageWidth, imageHeight, QImage::Format_ARGB32_Premultiplied );
@@ -96,8 +112,8 @@ bool QgsCompositionChecker::compareImages( const QImage& img1, const QImage& img
{
for ( int j = 0; j < imageWidth; ++j )
{
pixel1 = img1.pixel( j, i );
pixel2 = img2.pixel( j, i );
pixel1 = imgExpected.pixel( j, i );
pixel2 = imgRendered.pixel( j, i );
if ( pixel1 != pixel2 )
{
++mismatchCount;
@@ -24,15 +24,16 @@ class QImage;
class QgsCompositionChecker
{
public:
QgsCompositionChecker( QgsComposition* composition, const QString& expectedImageFile );
QgsCompositionChecker( const QString& testName, QgsComposition* composition, const QString& expectedImageFile );
~QgsCompositionChecker();

bool testComposition();

private:
QgsCompositionChecker(); //forbidden
bool compareImages( const QImage& img1, const QImage& img2, const QString& differenceImagePath = QString() ) const;
bool compareImages( const QImage& imgExpected, const QImage& imgRendered, const QString& differenceImagePath = QString() ) const;

QString mTestName;
QgsComposition* mComposition;
QString mExpectedImageFile;
};
@@ -88,7 +88,7 @@ void TestQgsComposerMap::cleanup()
void TestQgsComposerMap::render()
{
mComposerMap->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3345223.125 ) );
QgsCompositionChecker checker( mComposition, QString( QString( TEST_DATA_DIR ) + QDir::separator() +
QgsCompositionChecker checker( "Composer map render", mComposition, QString( QString( TEST_DATA_DIR ) + QDir::separator() +
"control_images" + QDir::separator() + "composermap_landsat_render.png" ) );
QVERIFY( checker.testComposition() );
}
@@ -108,7 +108,7 @@ void TestQgsComposerMap::grid()
mComposerMap->setGridAnnotationPosition( QgsComposerMap::OutsideMapFrame, QgsComposerMap::Bottom );
mComposerMap->setGridAnnotationDirection( QgsComposerMap::Horizontal, QgsComposerMap::Right );
mComposerMap->setGridAnnotationDirection( QgsComposerMap::Horizontal, QgsComposerMap::Bottom );
QgsCompositionChecker checker( mComposition, QString( QString( TEST_DATA_DIR ) + QDir::separator() +
QgsCompositionChecker checker( "Composer map grid", mComposition, QString( QString( TEST_DATA_DIR ) + QDir::separator() +
"control_images" + QDir::separator() + "composermap_landsat_grid.png" ) );
QVERIFY( checker.testComposition() );
}

0 comments on commit 75d68cd

Please sign in to comment.
You can’t perform that action at this time.