Skip to content

Commit e108feb

Browse files
committed
Clean up diagram tests
- Consolidate tests to single file - Don't use composition for testing
1 parent e646647 commit e108feb

File tree

7 files changed

+79
-222
lines changed

7 files changed

+79
-222
lines changed

tests/src/core/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ ADD_QGIS_TEST(clippertest testqgsclipper.cpp)
8282
ADD_QGIS_TEST(distanceareatest testqgsdistancearea.cpp)
8383
ADD_QGIS_TEST(applicationtest testqgsapplication.cpp)
8484
ADD_QGIS_TEST(diagramtest testqgsdiagram.cpp)
85-
ADD_QGIS_TEST(diagramexpressiontest testqgsdiagramexpression.cpp)
8685
ADD_QGIS_TEST(expressiontest testqgsexpression.cpp)
8786
ADD_QGIS_TEST(fieldtest testqgsfield.cpp)
8887
ADD_QGIS_TEST(fieldstest testqgsfields.cpp)

tests/src/core/testqgsdiagram.cpp

Lines changed: 79 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
// #include <qgisapp.h>
2828
#include <diagram/qgspiediagram.h>
2929
#include <qgsdiagramrendererv2.h>
30-
#include <qgscomposition.h>
31-
#include <qgscompositionchecker.h>
32-
#include <qgscomposermap.h>
3330
#include <qgsmaprenderer.h>
3431
#include <qgsmaplayer.h>
3532
#include <qgsvectordataprovider.h>
@@ -39,12 +36,12 @@
3936
#include <qgsmaplayerregistry.h>
4037
#include <qgsrendererv2.h>
4138
//qgis test includes
42-
#include "qgsrenderchecker.h"
39+
#include "qgsmultirenderchecker.h"
4340
#include "qgspallabeling.h"
4441
#include "qgsproject.h"
4542

4643
/** \ingroup UnitTests
47-
* This is a unit test for the vector layer class.
44+
* Unit tests for the diagram renderer
4845
*/
4946
class TestQgsDiagram : public QObject
5047
{
@@ -54,20 +51,16 @@ class TestQgsDiagram : public QObject
5451
TestQgsDiagram()
5552
: mTestHasError( false )
5653
, mPointsLayer( 0 )
57-
, mComposition( 0 )
58-
, mPieDiagram( 0 )
59-
, mComposerMap( 0 )
6054
{}
6155

6256
private:
6357
bool mTestHasError;
6458
QgsMapSettings mMapSettings;
6559
QgsVectorLayer * mPointsLayer;
66-
QgsComposition * mComposition;
6760
QString mTestDataDir;
6861
QString mReport;
69-
QgsPieDiagram * mPieDiagram;
70-
QgsComposerMap * mComposerMap;
62+
63+
bool imageCheck( QString theTestType );
7164

7265
private slots:
7366

@@ -100,25 +93,15 @@ class TestQgsDiagram : public QObject
10093
QgsMapLayerRegistry::instance()->addMapLayers(
10194
QList<QgsMapLayer *>() << mPointsLayer );
10295

103-
// Create diagrams
104-
mPieDiagram = new QgsPieDiagram();
105-
10696
// Create map composition to draw on
10797
mMapSettings.setLayers( QStringList() << mPointsLayer->id() );
108-
// TODO mMapSettings.setLabelingEngine( new QgsPalLabeling() );
109-
mComposition = new QgsComposition( mMapSettings );
110-
mComposition->setPaperSize( 297, 210 ); // A4 landscape
111-
mComposerMap = new QgsComposerMap( mComposition, 20, 20, 200, 100 );
112-
mComposerMap->setFrameEnabled( true );
113-
mComposition->addComposerMap( mComposerMap );
11498

11599
mReport += "<h1>Diagram Tests</h1>\n";
116100
}
117101

118102
// will be called after the last testfunction was executed.
119103
void cleanupTestCase()
120104
{
121-
delete mComposition;
122105
QgsApplication::exitQgis();
123106
QString myReportFile = QDir::tempPath() + QDir::separator() + "qgistest.html";
124107
QFile myFile( myReportFile );
@@ -130,8 +113,20 @@ class TestQgsDiagram : public QObject
130113
//QDesktopServices::openUrl( "file:///" + myReportFile );
131114
}
132115
}
133-
void init() {};// will be called before each testfunction is executed.
134-
void cleanup() {};// will be called after every testfunction.
116+
117+
// will be called before each testfunction is executed
118+
void init()
119+
{
120+
mPointsLayer->setDiagramRenderer( 0 );
121+
QgsDiagramLayerSettings dls;
122+
mPointsLayer->setDiagramLayerSettings( dls );
123+
}
124+
125+
// will be called after every testfunction.
126+
void cleanup()
127+
{
128+
129+
}
135130

136131
void testPieDiagram()
137132
{
@@ -149,35 +144,87 @@ class TestQgsDiagram : public QObject
149144
ds.penWidth = .5;
150145
ds.scaleByArea = true;
151146
ds.sizeType = QgsDiagramSettings::MM;
152-
ds.size = QSizeF( 15, 15 );
147+
ds.size = QSizeF( 5, 5 );
153148
ds.angleOffset = 0;
154149

155-
156150
QgsLinearlyInterpolatedDiagramRenderer *dr = new QgsLinearlyInterpolatedDiagramRenderer();
157151
dr->setLowerValue( 0.0 );
158152
dr->setLowerSize( QSizeF( 0.0, 0.0 ) );
159153
dr->setUpperValue( 10 );
160-
dr->setUpperSize( QSizeF( 100, 100 ) );
154+
dr->setUpperSize( QSizeF( 40, 40 ) );
161155
dr->setClassificationAttribute( 5 ); // Staff
162-
dr->setDiagram( mPieDiagram );
156+
dr->setDiagram( new QgsPieDiagram() );
163157
dr->setDiagramSettings( ds );
164158
mPointsLayer->setDiagramRenderer( dr );
165159

166160
QgsDiagramLayerSettings dls = QgsDiagramLayerSettings();
167161
dls.placement = QgsDiagramLayerSettings::OverPoint;
162+
dls.showAll = true;
163+
mPointsLayer->setDiagramLayerSettings( dls );
168164

169-
QgsProject::instance()->writeEntry( "PAL", "/ShowingAllLabels", true );
165+
QVERIFY( imageCheck( "piediagram" ) );
166+
}
170167

171-
mPointsLayer->setDiagramLayerSettings( dls );
168+
void testPieDiagramExpression()
169+
{
170+
QgsDiagramSettings ds;
171+
QColor col1 = Qt::red;
172+
QColor col2 = Qt::yellow;
173+
col1.setAlphaF( 0.5 );
174+
col2.setAlphaF( 0.5 );
175+
ds.categoryColors = QList<QColor>() << col1 << col2;
176+
ds.categoryAttributes = QList<QString>() << "ln(Pilots + 1)" << "ln(\"Cabin Crew\" + 1)";
177+
ds.maxScaleDenominator = -1;
178+
ds.minScaleDenominator = -1;
179+
ds.minimumSize = 0;
180+
ds.penColor = Qt::green;
181+
ds.penWidth = .5;
182+
ds.scaleByArea = true;
183+
ds.sizeType = QgsDiagramSettings::MM;
184+
ds.size = QSizeF( 5, 5 );
185+
ds.angleOffset = 0;
186+
187+
QgsLinearlyInterpolatedDiagramRenderer *dr = new QgsLinearlyInterpolatedDiagramRenderer();
188+
dr->setLowerValue( 0.0 );
189+
dr->setLowerSize( QSizeF( 0.0, 0.0 ) );
190+
dr->setUpperValue( 10 );
191+
dr->setUpperSize( QSizeF( 40, 40 ) );
192+
dr->setClassificationAttributeIsExpression( true );
193+
dr->setClassificationAttributeExpression( "ln(Staff + 1)" );
194+
dr->setDiagram( new QgsPieDiagram() );
195+
dr->setDiagramSettings( ds );
172196

173-
mComposerMap->setNewExtent( QgsRectangle( -122, -79, -70, 47 ) );
174-
QgsCompositionChecker checker( "piediagram", mComposition );
197+
QgsDiagramLayerSettings dls = QgsDiagramLayerSettings();
198+
dls.placement = QgsDiagramLayerSettings::OverPoint;
199+
dls.showAll = true;
200+
// dls.setRenderer( dr );
175201

176-
QVERIFY( checker.testComposition( mReport ) );
202+
mPointsLayer->setDiagramRenderer( dr );
203+
mPointsLayer->setDiagramLayerSettings( dls );
204+
205+
QVERIFY( imageCheck( "piediagram_expression" ) );
177206

178207
mPointsLayer->setDiagramRenderer( 0 );
179208
}
209+
180210
};
181211

212+
bool TestQgsDiagram::imageCheck( QString theTestType )
213+
{
214+
//use the QgsRenderChecker test utility class to
215+
//ensure the rendered output matches our control image
216+
217+
QgsRectangle extent( -126, 23, -70, 47 );
218+
mMapSettings.setExtent( extent );
219+
mMapSettings.setFlag( QgsMapSettings::ForceVectorOutput );
220+
QgsMultiRenderChecker myChecker;
221+
myChecker.setControlName( "expected_" + theTestType );
222+
myChecker.setMapSettings( mMapSettings );
223+
myChecker.setColorTolerance( 15 );
224+
bool myResultFlag = myChecker.runTest( theTestType, 200 );
225+
mReport += myChecker.report();
226+
return myResultFlag;
227+
}
228+
182229
QTEST_MAIN( TestQgsDiagram )
183230
#include "testqgsdiagram.moc"

tests/src/core/testqgsdiagramexpression.cpp

Lines changed: 0 additions & 189 deletions
This file was deleted.
Loading
Loading

0 commit comments

Comments
 (0)