Skip to content

Commit 0c759ed

Browse files
committed
Upgrade some more tests
1 parent 5d4da68 commit 0c759ed

8 files changed

+269
-353
lines changed

tests/src/core/testqgscallout.cpp

+68-97
Large diffs are not rendered by default.

tests/src/core/testqgscentroidfillsymbol.cpp

+26-32
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333
#include "qgsmarkersymbollayer.h"
3434
#include "qgsfillsymbol.h"
3535

36-
//qgis test includes
37-
#include "qgsrenderchecker.h"
38-
3936
/**
4037
* \ingroup UnitTests
4138
* This is a unit test for line fill symbol types.
@@ -45,7 +42,7 @@ class TestQgsCentroidFillSymbol : public QgsTest
4542
Q_OBJECT
4643

4744
public:
48-
TestQgsCentroidFillSymbol() : QgsTest( QStringLiteral( "Centroid Fill Symbol Tests" ) ) {}
45+
TestQgsCentroidFillSymbol() : QgsTest( QStringLiteral( "Centroid Fill Symbol Tests" ), QStringLiteral( "symbol_centroidfill" ) ) {}
4946

5047
private slots:
5148
void initTestCase();// will be called before the first testfunction is executed.
@@ -64,7 +61,6 @@ class TestQgsCentroidFillSymbol : public QgsTest
6461
private:
6562
bool mTestHasError = false ;
6663

67-
bool imageCheck( const QString &type );
6864
QgsMapSettings mMapSettings;
6965
QgsVectorLayer *mpPolysLayer = nullptr;
7066
QgsCentroidFillSymbolLayer *mCentroidFill = nullptr;
@@ -122,35 +118,45 @@ void TestQgsCentroidFillSymbol::cleanupTestCase()
122118

123119
void TestQgsCentroidFillSymbol::centroidFillSymbol()
124120
{
125-
QVERIFY( imageCheck( "symbol_centroidfill" ) );
121+
mMapSettings.setExtent( mpPolysLayer->extent() );
122+
mMapSettings.setOutputDpi( 96 );
123+
QGSVERIFYRENDERMAPSETTINGSCHECK( "symbol_centroidfill", "symbol_centroidfill", mMapSettings );
126124
}
127125

128126
void TestQgsCentroidFillSymbol::centroidFillSymbolPointOnSurface()
129127
{
130128
mCentroidFill->setPointOnSurface( true );
131-
QVERIFY( imageCheck( "symbol_centroidfill_point_on_surface" ) );
129+
mMapSettings.setExtent( mpPolysLayer->extent() );
130+
mMapSettings.setOutputDpi( 96 );
131+
QGSVERIFYRENDERMAPSETTINGSCHECK( "symbol_centroidfill_point_on_surface", "symbol_centroidfill_point_on_surface", mMapSettings );
132132
mCentroidFill->setPointOnSurface( false );
133133
}
134134

135135
void TestQgsCentroidFillSymbol::centroidFillSymbolPartBiggest()
136136
{
137137
mCentroidFill->setPointOnAllParts( false );
138-
QVERIFY( imageCheck( "symbol_centroidfill_part_biggest" ) );
138+
mMapSettings.setExtent( mpPolysLayer->extent() );
139+
mMapSettings.setOutputDpi( 96 );
140+
QGSVERIFYRENDERMAPSETTINGSCHECK( "symbol_centroidfill_part_biggest", "symbol_centroidfill_part_biggest", mMapSettings );
139141
mCentroidFill->setPointOnAllParts( true );
140142
}
141143

142144
void TestQgsCentroidFillSymbol::centroidFillClipPoints()
143145
{
144146
mCentroidFill->setClipPoints( true );
145-
QVERIFY( imageCheck( "symbol_centroidfill_clip_points" ) );
147+
mMapSettings.setExtent( mpPolysLayer->extent() );
148+
mMapSettings.setOutputDpi( 96 );
149+
QGSVERIFYRENDERMAPSETTINGSCHECK( "symbol_centroidfill_clip_points", "symbol_centroidfill_clip_points", mMapSettings );
146150
mCentroidFill->setClipPoints( false );
147151
}
148152

149153
void TestQgsCentroidFillSymbol::centroidFillClipOnCurrentPartOnly()
150154
{
151155
mCentroidFill->setClipPoints( true );
152156
mCentroidFill->setClipOnCurrentPartOnly( true );
153-
QVERIFY( imageCheck( "symbol_centroidfill_clip_current_only" ) );
157+
mMapSettings.setExtent( mpPolysLayer->extent() );
158+
mMapSettings.setOutputDpi( 96 );
159+
QGSVERIFYRENDERMAPSETTINGSCHECK( "symbol_centroidfill_clip_current_only", "symbol_centroidfill_clip_current_only", mMapSettings );
154160
mCentroidFill->setClipPoints( false );
155161
mCentroidFill->setClipOnCurrentPartOnly( false );
156162
}
@@ -160,7 +166,9 @@ void TestQgsCentroidFillSymbol::centroidFillClipOnCurrentPartOnlyBiggest()
160166
mCentroidFill->setClipPoints( true );
161167
mCentroidFill->setClipOnCurrentPartOnly( true );
162168
mCentroidFill->setPointOnAllParts( false );
163-
QVERIFY( imageCheck( "symbol_centroidfill_clip_current_biggest" ) );
169+
mMapSettings.setExtent( mpPolysLayer->extent() );
170+
mMapSettings.setOutputDpi( 96 );
171+
QGSVERIFYRENDERMAPSETTINGSCHECK( "symbol_centroidfill_clip_current_biggest", "symbol_centroidfill_clip_current_biggest", mMapSettings );
164172
mCentroidFill->setClipPoints( false );
165173
mCentroidFill->setClipOnCurrentPartOnly( false );
166174
mCentroidFill->setPointOnAllParts( true );
@@ -178,7 +186,9 @@ void TestQgsCentroidFillSymbol::centroidFillClipMultiplayerPoints()
178186
mFillSymbol->appendSymbolLayer( mCentroidFill->clone() );
179187
mFillSymbol->appendSymbolLayer( simpleFill.clone() );
180188

181-
QVERIFY( imageCheck( "symbol_centroidfill_clip_multilayer" ) );
189+
mMapSettings.setExtent( mpPolysLayer->extent() );
190+
mMapSettings.setOutputDpi( 96 );
191+
QGSVERIFYRENDERMAPSETTINGSCHECK( "symbol_centroidfill_clip_multilayer", "symbol_centroidfill_clip_multilayer", mMapSettings );
182192

183193
mCentroidFill->setClipPoints( false );
184194
mFillSymbol->deleteSymbolLayer( 0 );
@@ -199,7 +209,9 @@ void TestQgsCentroidFillSymbol::opacityWithDataDefinedColor()
199209
mCentroidFill->subSymbol()->setOpacity( 0.5 );
200210
mFillSymbol->setOpacity( 0.5 );
201211

202-
QVERIFY( imageCheck( "symbol_centroidfill_opacityddcolor" ) );
212+
mMapSettings.setExtent( mpPolysLayer->extent() );
213+
mMapSettings.setOutputDpi( 96 );
214+
QGSVERIFYRENDERMAPSETTINGSCHECK( "symbol_centroidfill_opacityddcolor", "symbol_centroidfill_opacityddcolor", mMapSettings );
203215
}
204216

205217
void TestQgsCentroidFillSymbol::dataDefinedOpacity()
@@ -214,27 +226,9 @@ void TestQgsCentroidFillSymbol::dataDefinedOpacity()
214226
mFillSymbol->setOpacity( 1.0 );
215227
mFillSymbol->setDataDefinedProperty( QgsSymbol::PropertyOpacity, QgsProperty::fromExpression( QStringLiteral( "if(\"Value\" >10, 25, 50)" ) ) );
216228

217-
QVERIFY( imageCheck( "symbol_centroidfill_ddopacity" ) );
218-
}
219-
220-
//
221-
// Private helper functions not called directly by CTest
222-
//
223-
224-
225-
bool TestQgsCentroidFillSymbol::imageCheck( const QString &testType )
226-
{
227-
//use the QgsRenderChecker test utility class to
228-
//ensure the rendered output matches our control image
229229
mMapSettings.setExtent( mpPolysLayer->extent() );
230230
mMapSettings.setOutputDpi( 96 );
231-
QgsRenderChecker myChecker;
232-
myChecker.setControlPathPrefix( QStringLiteral( "symbol_centroidfill" ) );
233-
myChecker.setControlName( "expected_" + testType );
234-
myChecker.setMapSettings( mMapSettings );
235-
const bool myResultFlag = myChecker.runTest( testType );
236-
mReport += myChecker.report();
237-
return myResultFlag;
231+
QGSVERIFYRENDERMAPSETTINGSCHECK( "symbol_centroidfill_ddopacity", "symbol_centroidfill_ddopacity", mMapSettings );
238232
}
239233

240234
QGSTEST_MAIN( TestQgsCentroidFillSymbol )

tests/src/core/testqgsclipper.cpp

+8-27
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class TestQgsClipper: public QgsTest
3333
Q_OBJECT
3434

3535
public:
36-
TestQgsClipper() : QgsTest( QStringLiteral( "Clipper Rendering Tests" ) ) {}
36+
TestQgsClipper() : QgsTest( QStringLiteral( "Clipper Rendering Tests" ), QStringLiteral( "3d" ) ) {}
3737

3838
private slots:
3939
void initTestCase();// will be called before the first testfunction is executed.
@@ -48,7 +48,6 @@ class TestQgsClipper: public QgsTest
4848

4949
bool checkBoundingBox( const QPolygonF &polygon, const QgsRectangle &clipRect );
5050
bool checkBoundingBox( const QgsLineString &polygon, const QgsBox3D &clipRect );
51-
bool render2dCheck( const QString &testName, QgsVectorLayer *layer, QgsRectangle extent );
5251
};
5352

5453
void TestQgsClipper::initTestCase()
@@ -200,7 +199,13 @@ void TestQgsClipper::epsg4978LineRendering()
200199
fillSymbol->setColor( QColor( 255, 0, 0 ) );
201200
layerLines->setRenderer( new QgsSingleSymbolRenderer( fillSymbol ) );
202201

203-
QVERIFY( render2dCheck( "4978_2D_line_rendering", layerLines.get(), QgsRectangle( -2.5e7, -2.5e7, 2.5e7, 2.5e7 ) ) );
202+
QgsMapSettings mapSettings;
203+
mapSettings.setLayers( QList<QgsMapLayer *>() << layerLines.get() );
204+
mapSettings.setExtent( QgsRectangle( -2.5e7, -2.5e7, 2.5e7, 2.5e7 ) );
205+
mapSettings.setOutputDpi( 96 );
206+
mapSettings.setDestinationCrs( QgsCoordinateReferenceSystem( "EPSG:3857" ) );
207+
208+
QGSVERIFYRENDERMAPSETTINGSCHECK( "4978_2D_line_rendering", "4978_2D_line_rendering", mapSettings, 0, 50 );
204209
}
205210

206211
void TestQgsClipper::clipGeometryWithNaNZValues()
@@ -247,29 +252,5 @@ void TestQgsClipper::clipGeometryWithNaNZValues()
247252
QGSCOMPARENEAR( pointsZ.at( 0 ), 19.568, 0.01 );
248253
}
249254

250-
bool TestQgsClipper::render2dCheck( const QString &testName, QgsVectorLayer *layer, QgsRectangle extent )
251-
{
252-
const QString myTmpDir = QDir::tempPath() + '/';
253-
const QString myFileName = myTmpDir + testName + ".png";
254-
255-
QgsMapSettings mMapSettings;
256-
mMapSettings.setLayers( QList<QgsMapLayer *>() << layer );
257-
mMapSettings.setExtent( extent );
258-
mMapSettings.setOutputDpi( 96 );
259-
QgsCoordinateReferenceSystem newCrs;
260-
newCrs.createFromString( "EPSG:3857" );
261-
mMapSettings.setDestinationCrs( newCrs );
262-
263-
QgsRenderChecker myChecker;
264-
myChecker.setControlPathPrefix( QStringLiteral( "3d" ) );
265-
myChecker.setControlName( "expected_" + testName );
266-
myChecker.setMapSettings( mMapSettings );
267-
myChecker.setRenderedImage( myFileName );
268-
myChecker.setColorTolerance( 50 );
269-
const bool myResultFlag = myChecker.runTest( testName, 0 );
270-
mReport += myChecker.report();
271-
return myResultFlag;
272-
}
273-
274255
QGSTEST_MAIN( TestQgsClipper )
275256
#include "testqgsclipper.moc"

tests/src/core/testqgsdatadefinedsizelegend.cpp

+4-27
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,8 @@
1717

1818
#include "qgsdatadefinedsizelegend.h"
1919
#include "qgsfontutils.h"
20-
#include "qgsrenderchecker.h"
21-
#include "qgssymbol.h"
2220
#include "qgsmarkersymbol.h"
2321

24-
static QString _fileNameForTest( const QString &testName )
25-
{
26-
return QDir::tempPath() + '/' + testName + ".png";
27-
}
28-
29-
static bool _verifyImage( const QString &testName, QString &report )
30-
{
31-
QgsRenderChecker checker;
32-
checker.setControlPathPrefix( QStringLiteral( "data_defined_size_legend" ) );
33-
checker.setControlName( "expected_" + testName );
34-
checker.setRenderedImage( _fileNameForTest( testName ) );
35-
checker.setSizeTolerance( 3, 3 );
36-
const bool equal = checker.compareImages( testName, 500 );
37-
report += checker.report();
38-
return equal;
39-
}
40-
4122
static QgsRenderContext _createRenderContext( double mupp, double dpi, double scale )
4223
{
4324
QgsRenderContext context;
@@ -58,7 +39,7 @@ class TestQgsDataDefinedSizeLegend : public QgsTest
5839

5940
public:
6041

61-
TestQgsDataDefinedSizeLegend() : QgsTest( QStringLiteral( "Data Defined Size Legend Tests" ) ) {}
42+
TestQgsDataDefinedSizeLegend() : QgsTest( QStringLiteral( "Data Defined Size Legend Tests" ), QStringLiteral( "data_defined_size_legend" ) ) {}
6243

6344
private slots:
6445
void initTestCase();// will be called before the first testfunction is executed.
@@ -105,14 +86,12 @@ void TestQgsDataDefinedSizeLegend::testBasic()
10586
QgsRenderContext context( _createRenderContext( 100, 96, 100 ) );
10687

10788
const QImage imgBottom = settings.collapsedLegendImage( context, Qt::white, 1 );
108-
imgBottom.save( _fileNameForTest( QStringLiteral( "basic_bottom" ) ) );
109-
QVERIFY( _verifyImage( "basic_bottom", mReport ) );
89+
QGSVERIFYIMAGECHECK( "basic_bottom", "basic_bottom", imgBottom, QString(), 500, QSize( 3, 3 ) );
11090

11191
settings.setVerticalAlignment( QgsDataDefinedSizeLegend::AlignCenter );
11292

11393
const QImage imgCenter = settings.collapsedLegendImage( context, Qt::white, 1 );
114-
imgCenter.save( _fileNameForTest( QStringLiteral( "basic_center" ) ) );
115-
QVERIFY( _verifyImage( "basic_center", mReport ) );
94+
QGSVERIFYIMAGECHECK( "basic_center", "basic_center", imgCenter, QString(), 500, QSize( 3, 3 ) );
11695
}
11796

11897
void TestQgsDataDefinedSizeLegend::testCrowded()
@@ -140,9 +119,7 @@ void TestQgsDataDefinedSizeLegend::testCrowded()
140119
QgsRenderContext context( _createRenderContext( 100, 96, 100 ) );
141120

142121
const QImage img = settings.collapsedLegendImage( context, Qt::white, 1 );
143-
img.save( _fileNameForTest( QStringLiteral( "crowded" ) ) );
144-
145-
QVERIFY( _verifyImage( "crowded", mReport ) );
122+
QGSVERIFYIMAGECHECK( "crowded", "crowded", img, QString(), 500, QSize( 3, 3 ) );
146123
}
147124

148125
QGSTEST_MAIN( TestQgsDataDefinedSizeLegend )

0 commit comments

Comments
 (0)