Skip to content
Permalink
Browse files
Add QgsDartMeasurement
  • Loading branch information
m-kuhn committed Nov 14, 2014
1 parent fd95930 commit 4b843e4
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 34 deletions.
@@ -69,6 +69,7 @@ SET(QGIS_CORE_SRCS
qgscoordinatereferencesystem.cpp
qgscoordinatetransform.cpp
qgscredentials.cpp
qgsdartmeasurement.cpp
qgscrscache.cpp
qgsdatadefined.cpp
qgsdatasourceuri.cpp
@@ -470,6 +471,7 @@ SET(QGIS_CORE_HDRS
qgscredentials.h
qgscrscache.h
qgscsexception.h
qgsdartmeasurement.h
qgsdatadefined.h
qgsdatasourceuri.h
qgsdataitem.h
@@ -0,0 +1,68 @@
/***************************************************************************
qgsdartmeasurement.cpp
--------------------------------------
Date : 8.11.2014
Copyright : (C) 2014 Matthias Kuhn
Email : matthias dot kuhn at gmx dot ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsdartmeasurement.h"

#include <QDebug>

QgsDartMeasurement::QgsDartMeasurement( const QString& name, Type type, const QString& value )
: mName( name )
, mType( type )
, mValue( value )
{
}

const QString QgsDartMeasurement::toString() const
{
QString elementName = "DartMeasurement";
if ( mType == ImagePng )
{
elementName = "DartMeasurementFile";
}

QString dashMessage = QString( "<%1 name=\"%2\" type=\"%3\">%4</%1>" )
.arg( elementName )
.arg( mName )
.arg( typeToString( mType ) )
.arg( mValue );
return dashMessage;
}

void QgsDartMeasurement::send() const
{
qDebug() << toString() + "\n";
}

const QString QgsDartMeasurement::typeToString( QgsDartMeasurement::Type type )
{
QString str;

switch ( type )
{
case Text:
str = "text/text";
break;

case ImagePng:
str = "image/png";
break;

case Integer:
str = "numeric/integer";
break;
}

return str;
}
@@ -0,0 +1,49 @@
/***************************************************************************
qgsdartmeasurement.h
--------------------------------------
Date : 8.11.2014
Copyright : (C) 2014 Matthias Kuhn
Email : matthias dot kuhn at gmx dot ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSDARTMEASUREMENT_H
#define QGSDARTMEASUREMENT_H

#include <QString>

class QgsDartMeasurement
{
public:
enum Type
{
Text,
ImagePng,
Integer
};

QgsDartMeasurement()
: mType( Text )
{}

QgsDartMeasurement( const QString& name, Type type, const QString& value );

const QString toString() const;

void send() const;

static const QString typeToString( Type type );

private:
QString mName;
Type mType;
QString mValue;
};

#endif // QGSDARTMEASUREMENT_H
@@ -49,11 +49,14 @@ bool QgsMultiRenderChecker::runTest( const QString& theTestName, unsigned int th
subDirs << "";
}

QVector<QgsDartMeasurement> dartMeasurements;

Q_FOREACH( const QString& suffix, subDirs )
{
qDebug() << "Checking subdir " << suffix;
bool result;
QgsRenderChecker checker;
checker.enableDashBuffering( true );
checker.setColorTolerance( mColorTolerance );
checker.setControlPathPrefix( mControlPathPrefix );
checker.setControlPathSuffix( suffix );
@@ -71,14 +74,22 @@ bool QgsMultiRenderChecker::runTest( const QString& theTestName, unsigned int th
mRenderedImage = checker.renderedImage();
}

qDebug() << " * Subdir check " << suffix << ": " << result;
successful |= result;

dartMeasurements << checker.dartMeasurements();

mReport += checker.report();
}

if ( !successful )
qDebug() << "No matching image found. If you think that this result should be considered ok, please copy it into a new subdirectory inside " << baseDir;
{
Q_FOREACH( const QgsDartMeasurement& measurement, dartMeasurements )
measurement.send();

QgsDartMeasurement msg( "Image not accepted by test", QgsDartMeasurement::Text, "This may be caused because the test is supposed to fail or rendering inconsistencies."
"If this is a rendering inconsistency, please add another control image folder, add an anomaly image or increase the color tolerance." );
msg.send();
}

return successful;
}
@@ -35,8 +35,7 @@ QgsRenderChecker::QgsRenderChecker() :
mExpectedImageFile( "" ),
mMismatchCount( 0 ),
mColorTolerance( 0 ),
mElapsedTimeTarget( 0 ),
mControlPathPrefix( "" )
mElapsedTimeTarget( 0 )
{
}

@@ -131,10 +130,8 @@ bool QgsRenderChecker::isKnownAnomaly( QString theDiffImageFile )
.arg( theDiffImageFile )
.arg( myImageHash );
//foo CDash
QString myMeasureMessage = "<DartMeasurement name=\"Anomaly check"
"\" type=\"text/text\">" + myHashMessage +
"</DartMeasurement>";
qDebug() << myMeasureMessage;
emitDashMessage( "Anomaly check", QgsDartMeasurement::Text, myHashMessage );

mReport += "<tr><td colspan=3>" + myHashMessage + "</td></tr>";
if ( myImageHash == myAnomalyHash )
{
@@ -150,6 +147,19 @@ bool QgsRenderChecker::isKnownAnomaly( QString theDiffImageFile )
return false;
}

void QgsRenderChecker::emitDashMessage( const QgsDartMeasurement& dashMessage )
{
if ( mBufferDashMessages )
mDashMessages << dashMessage;
else
dashMessage.send();
}

void QgsRenderChecker::emitDashMessage( const QString& name, QgsDartMeasurement::Type type, const QString& value )
{
emitDashMessage( QgsDartMeasurement( name, type, value ) );
}

bool QgsRenderChecker::runTest( QString theTestName,
unsigned int theMismatchCount )
{
@@ -300,17 +310,18 @@ bool QgsRenderChecker::compareImages( QString theTestName,
" src=\"file://" +
myDiffImageFile +
"\"></td>\n</tr>\n</table>";

QString prefix;
if ( !mControlPathPrefix.isNull() )
{
prefix = QString( " (prefix %1)" ).arg( mControlPathPrefix );
}
//
// To get the images into CDash
//
QString myDashMessage = "<DartMeasurementFile name=\"Rendered Image " + theTestName + "\""
" type=\"image/png\">" + mRenderedImageFile +
"</DartMeasurementFile>\n"
"<DartMeasurementFile name=\"Expected Image " + theTestName + "\" type=\"image/png\">" +
mExpectedImageFile + "</DartMeasurementFile>\n"
"<DartMeasurementFile name=\"Difference Image " + theTestName + "\" type=\"image/png\">" +
myDiffImageFile + "</DartMeasurementFile>\n";
qDebug() << myDashMessage;
emitDashMessage( "Rendered Image " + theTestName + prefix, QgsDartMeasurement::ImagePng, mRenderedImageFile );
emitDashMessage( "Expected Image " + theTestName + prefix, QgsDartMeasurement::ImagePng, mExpectedImageFile );
emitDashMessage( "Difference Image " + theTestName + prefix, QgsDartMeasurement::ImagePng, myDiffImageFile );

//
// Put the same info to debug too
@@ -388,12 +399,7 @@ bool QgsRenderChecker::compareImages( QString theTestName,
//
// And send it to CDash
//
myDashMessage = "<DartMeasurement name=\"Mismatch Count "
"\" type=\"numeric/integer\">" +
QString::number( mMismatchCount ) + "/" +
QString::number( mMatchTarget ) +
"</DartMeasurement>";
qDebug() << myDashMessage;
emitDashMessage( "Mismatch Count", QgsDartMeasurement::Integer, QString( "%1/%2" ).arg( mMismatchCount ).arg( mMatchTarget ) );

bool myAnomalyMatchFlag = isKnownAnomaly( myDiffImageFile );

@@ -406,17 +412,13 @@ bool QgsRenderChecker::compareImages( QString theTestName,
}
else
{
QString myMessage = "Difference image did not match any known anomaly.";
mReport += "<tr><td colspan=3>"
"</td></tr>";
QString myMeasureMessage = "<DartMeasurement name=\"No Anomalies Match"
"\" type=\"text/text\">" + myMessage +
" If you feel the difference image should be considered an anomaly "
"you can do something like this\n"
"cp " + myDiffImageFile + " ../tests/testdata/control_images/" + theTestName +
"/<imagename>.{wld,png}"
"</DartMeasurement>";
qDebug() << myMeasureMessage;
emitDashMessage( "No Anomalies Match", QgsDartMeasurement::Text, "Difference image did not match any known anomaly."
" If you feel the difference image should be considered an anomaly "
"you can do something like this\n"
"cp " + myDiffImageFile + " ../tests/testdata/control_images/" + theTestName +
"/<imagename>.{wld,png}" );
}

if ( mMismatchCount <= theMismatchCount )
@@ -25,6 +25,7 @@
#include <qgsmaprenderer.h>
#include <qgslogger.h>
#include <qgsmapsettings.h>
#include "qgsdartmeasurement.h"

class QImage;

@@ -127,13 +128,35 @@ class CORE_EXPORT QgsRenderChecker
*/
bool isKnownAnomaly( QString theDiffImageFile );

QString expectedImageFile() { return mExpectedImageFile; }

/**Draws a checkboard pattern for image backgrounds, so that transparency is visible
* without requiring a transparent background for the image
*/
static void drawBackround( QImage* image );

/**
* Returns the path to the expected image file
*
* @return Path to the expected image file
*/
const QString& expectedImageFile() const { return mExpectedImageFile; }

/**
* Call this to enable internal buffering of dash messages. You may later call
* dashMessages() to get access to the buffered messages. If disabled (default)
* dash messages will be sent immediately.
*
* @param enable Enable or disable buffering
*/
void enableDashBuffering( bool enable ) { mBufferDashMessages = enable; }

/**
* Get access to buffered dash messages.
* Only will return something if you call enableDashBuffering( true ); before.
*
* @return buffered dash messages
*/
const QVector<QgsDartMeasurement>& dartMeasurements() const { return mDashMessages; }

protected:
QString mReport;
unsigned int mMatchTarget;
@@ -142,14 +165,18 @@ class CORE_EXPORT QgsRenderChecker
QString mExpectedImageFile;

private:
void emitDashMessage( const QgsDartMeasurement& dashMessage );
void emitDashMessage( const QString& name, QgsDartMeasurement::Type type, const QString& value );

QString mControlName;
unsigned int mMismatchCount;
unsigned int mColorTolerance;
int mElapsedTimeTarget;
QgsMapSettings mMapSettings;
QString mControlPathPrefix;
QString mControlPathSuffix;

QVector<QgsDartMeasurement> mDashMessages;
bool mBufferDashMessages;
}; // class QgsRenderChecker


0 comments on commit 4b843e4

Please sign in to comment.