Skip to content

Commit 4b843e4

Browse files
committedNov 14, 2014
Add QgsDartMeasurement
1 parent fd95930 commit 4b843e4

File tree

6 files changed

+193
-34
lines changed

6 files changed

+193
-34
lines changed
 

‎src/core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ SET(QGIS_CORE_SRCS
6969
qgscoordinatereferencesystem.cpp
7070
qgscoordinatetransform.cpp
7171
qgscredentials.cpp
72+
qgsdartmeasurement.cpp
7273
qgscrscache.cpp
7374
qgsdatadefined.cpp
7475
qgsdatasourceuri.cpp
@@ -470,6 +471,7 @@ SET(QGIS_CORE_HDRS
470471
qgscredentials.h
471472
qgscrscache.h
472473
qgscsexception.h
474+
qgsdartmeasurement.h
473475
qgsdatadefined.h
474476
qgsdatasourceuri.h
475477
qgsdataitem.h

‎src/core/qgsdartmeasurement.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/***************************************************************************
2+
qgsdartmeasurement.cpp
3+
--------------------------------------
4+
Date : 8.11.2014
5+
Copyright : (C) 2014 Matthias Kuhn
6+
Email : matthias dot kuhn at gmx dot ch
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qgsdartmeasurement.h"
17+
18+
#include <QDebug>
19+
20+
QgsDartMeasurement::QgsDartMeasurement( const QString& name, Type type, const QString& value )
21+
: mName( name )
22+
, mType( type )
23+
, mValue( value )
24+
{
25+
}
26+
27+
const QString QgsDartMeasurement::toString() const
28+
{
29+
QString elementName = "DartMeasurement";
30+
if ( mType == ImagePng )
31+
{
32+
elementName = "DartMeasurementFile";
33+
}
34+
35+
QString dashMessage = QString( "<%1 name=\"%2\" type=\"%3\">%4</%1>" )
36+
.arg( elementName )
37+
.arg( mName )
38+
.arg( typeToString( mType ) )
39+
.arg( mValue );
40+
return dashMessage;
41+
}
42+
43+
void QgsDartMeasurement::send() const
44+
{
45+
qDebug() << toString() + "\n";
46+
}
47+
48+
const QString QgsDartMeasurement::typeToString( QgsDartMeasurement::Type type )
49+
{
50+
QString str;
51+
52+
switch ( type )
53+
{
54+
case Text:
55+
str = "text/text";
56+
break;
57+
58+
case ImagePng:
59+
str = "image/png";
60+
break;
61+
62+
case Integer:
63+
str = "numeric/integer";
64+
break;
65+
}
66+
67+
return str;
68+
}

‎src/core/qgsdartmeasurement.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/***************************************************************************
2+
qgsdartmeasurement.h
3+
--------------------------------------
4+
Date : 8.11.2014
5+
Copyright : (C) 2014 Matthias Kuhn
6+
Email : matthias dot kuhn at gmx dot ch
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#ifndef QGSDARTMEASUREMENT_H
17+
#define QGSDARTMEASUREMENT_H
18+
19+
#include <QString>
20+
21+
class QgsDartMeasurement
22+
{
23+
public:
24+
enum Type
25+
{
26+
Text,
27+
ImagePng,
28+
Integer
29+
};
30+
31+
QgsDartMeasurement()
32+
: mType( Text )
33+
{}
34+
35+
QgsDartMeasurement( const QString& name, Type type, const QString& value );
36+
37+
const QString toString() const;
38+
39+
void send() const;
40+
41+
static const QString typeToString( Type type );
42+
43+
private:
44+
QString mName;
45+
Type mType;
46+
QString mValue;
47+
};
48+
49+
#endif // QGSDARTMEASUREMENT_H

‎src/core/qgsmultirenderchecker.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,14 @@ bool QgsMultiRenderChecker::runTest( const QString& theTestName, unsigned int th
4949
subDirs << "";
5050
}
5151

52+
QVector<QgsDartMeasurement> dartMeasurements;
53+
5254
Q_FOREACH( const QString& suffix, subDirs )
5355
{
5456
qDebug() << "Checking subdir " << suffix;
5557
bool result;
5658
QgsRenderChecker checker;
59+
checker.enableDashBuffering( true );
5760
checker.setColorTolerance( mColorTolerance );
5861
checker.setControlPathPrefix( mControlPathPrefix );
5962
checker.setControlPathSuffix( suffix );
@@ -71,14 +74,22 @@ bool QgsMultiRenderChecker::runTest( const QString& theTestName, unsigned int th
7174
mRenderedImage = checker.renderedImage();
7275
}
7376

74-
qDebug() << " * Subdir check " << suffix << ": " << result;
7577
successful |= result;
7678

79+
dartMeasurements << checker.dartMeasurements();
80+
7781
mReport += checker.report();
7882
}
7983

8084
if ( !successful )
81-
qDebug() << "No matching image found. If you think that this result should be considered ok, please copy it into a new subdirectory inside " << baseDir;
85+
{
86+
Q_FOREACH( const QgsDartMeasurement& measurement, dartMeasurements )
87+
measurement.send();
88+
89+
QgsDartMeasurement msg( "Image not accepted by test", QgsDartMeasurement::Text, "This may be caused because the test is supposed to fail or rendering inconsistencies."
90+
"If this is a rendering inconsistency, please add another control image folder, add an anomaly image or increase the color tolerance." );
91+
msg.send();
92+
}
8293

8394
return successful;
8495
}

‎src/core/qgsrenderchecker.cpp

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ QgsRenderChecker::QgsRenderChecker() :
3535
mExpectedImageFile( "" ),
3636
mMismatchCount( 0 ),
3737
mColorTolerance( 0 ),
38-
mElapsedTimeTarget( 0 ),
39-
mControlPathPrefix( "" )
38+
mElapsedTimeTarget( 0 )
4039
{
4140
}
4241

@@ -131,10 +130,8 @@ bool QgsRenderChecker::isKnownAnomaly( QString theDiffImageFile )
131130
.arg( theDiffImageFile )
132131
.arg( myImageHash );
133132
//foo CDash
134-
QString myMeasureMessage = "<DartMeasurement name=\"Anomaly check"
135-
"\" type=\"text/text\">" + myHashMessage +
136-
"</DartMeasurement>";
137-
qDebug() << myMeasureMessage;
133+
emitDashMessage( "Anomaly check", QgsDartMeasurement::Text, myHashMessage );
134+
138135
mReport += "<tr><td colspan=3>" + myHashMessage + "</td></tr>";
139136
if ( myImageHash == myAnomalyHash )
140137
{
@@ -150,6 +147,19 @@ bool QgsRenderChecker::isKnownAnomaly( QString theDiffImageFile )
150147
return false;
151148
}
152149

150+
void QgsRenderChecker::emitDashMessage( const QgsDartMeasurement& dashMessage )
151+
{
152+
if ( mBufferDashMessages )
153+
mDashMessages << dashMessage;
154+
else
155+
dashMessage.send();
156+
}
157+
158+
void QgsRenderChecker::emitDashMessage( const QString& name, QgsDartMeasurement::Type type, const QString& value )
159+
{
160+
emitDashMessage( QgsDartMeasurement( name, type, value ) );
161+
}
162+
153163
bool QgsRenderChecker::runTest( QString theTestName,
154164
unsigned int theMismatchCount )
155165
{
@@ -300,17 +310,18 @@ bool QgsRenderChecker::compareImages( QString theTestName,
300310
" src=\"file://" +
301311
myDiffImageFile +
302312
"\"></td>\n</tr>\n</table>";
313+
314+
QString prefix;
315+
if ( !mControlPathPrefix.isNull() )
316+
{
317+
prefix = QString( " (prefix %1)" ).arg( mControlPathPrefix );
318+
}
303319
//
304320
// To get the images into CDash
305321
//
306-
QString myDashMessage = "<DartMeasurementFile name=\"Rendered Image " + theTestName + "\""
307-
" type=\"image/png\">" + mRenderedImageFile +
308-
"</DartMeasurementFile>\n"
309-
"<DartMeasurementFile name=\"Expected Image " + theTestName + "\" type=\"image/png\">" +
310-
mExpectedImageFile + "</DartMeasurementFile>\n"
311-
"<DartMeasurementFile name=\"Difference Image " + theTestName + "\" type=\"image/png\">" +
312-
myDiffImageFile + "</DartMeasurementFile>\n";
313-
qDebug() << myDashMessage;
322+
emitDashMessage( "Rendered Image " + theTestName + prefix, QgsDartMeasurement::ImagePng, mRenderedImageFile );
323+
emitDashMessage( "Expected Image " + theTestName + prefix, QgsDartMeasurement::ImagePng, mExpectedImageFile );
324+
emitDashMessage( "Difference Image " + theTestName + prefix, QgsDartMeasurement::ImagePng, myDiffImageFile );
314325

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

398404
bool myAnomalyMatchFlag = isKnownAnomaly( myDiffImageFile );
399405

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

422424
if ( mMismatchCount <= theMismatchCount )

‎src/core/qgsrenderchecker.h

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <qgsmaprenderer.h>
2626
#include <qgslogger.h>
2727
#include <qgsmapsettings.h>
28+
#include "qgsdartmeasurement.h"
2829

2930
class QImage;
3031

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

130-
QString expectedImageFile() { return mExpectedImageFile; }
131-
132131
/**Draws a checkboard pattern for image backgrounds, so that transparency is visible
133132
* without requiring a transparent background for the image
134133
*/
135134
static void drawBackround( QImage* image );
136135

136+
/**
137+
* Returns the path to the expected image file
138+
*
139+
* @return Path to the expected image file
140+
*/
141+
const QString& expectedImageFile() const { return mExpectedImageFile; }
142+
143+
/**
144+
* Call this to enable internal buffering of dash messages. You may later call
145+
* dashMessages() to get access to the buffered messages. If disabled (default)
146+
* dash messages will be sent immediately.
147+
*
148+
* @param enable Enable or disable buffering
149+
*/
150+
void enableDashBuffering( bool enable ) { mBufferDashMessages = enable; }
151+
152+
/**
153+
* Get access to buffered dash messages.
154+
* Only will return something if you call enableDashBuffering( true ); before.
155+
*
156+
* @return buffered dash messages
157+
*/
158+
const QVector<QgsDartMeasurement>& dartMeasurements() const { return mDashMessages; }
159+
137160
protected:
138161
QString mReport;
139162
unsigned int mMatchTarget;
@@ -142,14 +165,18 @@ class CORE_EXPORT QgsRenderChecker
142165
QString mExpectedImageFile;
143166

144167
private:
168+
void emitDashMessage( const QgsDartMeasurement& dashMessage );
169+
void emitDashMessage( const QString& name, QgsDartMeasurement::Type type, const QString& value );
170+
145171
QString mControlName;
146172
unsigned int mMismatchCount;
147173
unsigned int mColorTolerance;
148174
int mElapsedTimeTarget;
149175
QgsMapSettings mMapSettings;
150176
QString mControlPathPrefix;
151177
QString mControlPathSuffix;
152-
178+
QVector<QgsDartMeasurement> mDashMessages;
179+
bool mBufferDashMessages;
153180
}; // class QgsRenderChecker
154181

155182

0 commit comments

Comments
 (0)
Please sign in to comment.