Skip to content

Commit d699569

Browse files
committed
Add initial tests for marker symbol layers
1 parent 5a6bfbb commit d699569

File tree

12 files changed

+662
-3
lines changed

12 files changed

+662
-3
lines changed

tests/src/core/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,14 @@ ADD_QGIS_TEST(dataitemtest testqgsdataitem.cpp)
116116
ADD_QGIS_TEST(datasourceuritest testqgsdatasourceuri.cpp)
117117
ADD_QGIS_TEST(diagramtest testqgsdiagram.cpp)
118118
ADD_QGIS_TEST(distanceareatest testqgsdistancearea.cpp)
119+
ADD_QGIS_TEST(ellipsemarkertest testqgsellipsemarker.cpp)
119120
ADD_QGIS_TEST(expressioncontext testqgsexpressioncontext.cpp)
120121
ADD_QGIS_TEST(expressiontest testqgsexpression.cpp)
121122
ADD_QGIS_TEST(featuretest testqgsfeature.cpp)
122123
ADD_QGIS_TEST(fieldstest testqgsfields.cpp)
123124
ADD_QGIS_TEST(fieldtest testqgsfield.cpp)
124125
ADD_QGIS_TEST(filewritertest testqgsvectorfilewriter.cpp)
126+
ADD_QGIS_TEST(fontmarkertest testqgsfontmarker.cpp)
125127
ADD_QGIS_TEST(fontutils testqgsfontutils.cpp)
126128
ADD_QGIS_TEST(geometryimporttest testqgsgeometryimport.cpp)
127129
ADD_QGIS_TEST(geometrytest testqgsgeometry.cpp)
@@ -164,11 +166,13 @@ ADD_QGIS_TEST(rendererstest testqgsrenderers.cpp)
164166
ADD_QGIS_TEST(rulebasedrenderertest testqgsrulebasedrenderer.cpp)
165167
ADD_QGIS_TEST(scaleexpressiontest testqgsscaleexpression.cpp)
166168
ADD_QGIS_TEST(shapebursttest testqgsshapeburst.cpp )
169+
ADD_QGIS_TEST(simplemarkertest testqgssimplemarker.cpp)
167170
ADD_QGIS_TEST(snappingutilstest testqgssnappingutils.cpp )
168171
ADD_QGIS_TEST(spatialindextest testqgsspatialindex.cpp)
169172
ADD_QGIS_TEST(statisticalsummarytest testqgsstatisticalsummary.cpp)
170173
ADD_QGIS_TEST(stringutilstest testqgsstringutils.cpp)
171174
ADD_QGIS_TEST(stylev2test testqgsstylev2.cpp)
175+
ADD_QGIS_TEST(svgmarkertest testqgssvgmarker.cpp)
172176
ADD_QGIS_TEST(symbolv2test testqgssymbolv2.cpp)
173177
ADD_QGIS_TEST(vectordataprovidertest testqgsvectordataprovider.cpp)
174178
ADD_QGIS_TEST(vectorlayercachetest testqgsvectorlayercache.cpp )
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/***************************************************************************
2+
testqgsellipsemarker.cpp
3+
------------------------
4+
Date : Nov 2015
5+
Copyright : (C) 2015 by Nyall Dawson
6+
Email : nyall dot dawson at gmail dot com
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+
#include <QtTest/QtTest>
16+
#include <QObject>
17+
#include <QString>
18+
#include <QStringList>
19+
#include <QApplication>
20+
#include <QFileInfo>
21+
#include <QDir>
22+
#include <QDesktopServices>
23+
24+
//qgis includes...
25+
#include <qgsmaprenderer.h>
26+
#include <qgsmaplayer.h>
27+
#include <qgsvectorlayer.h>
28+
#include <qgsapplication.h>
29+
#include <qgsproviderregistry.h>
30+
#include <qgsmaplayerregistry.h>
31+
#include <qgssymbolv2.h>
32+
#include <qgssinglesymbolrendererv2.h>
33+
#include "qgsmarkersymbollayerv2.h"
34+
#include "qgsellipsesymbollayerv2.h"
35+
#include "qgsdatadefined.h"
36+
37+
//qgis test includes
38+
#include "qgsrenderchecker.h"
39+
40+
/** \ingroup UnitTests
41+
* This is a unit test for ellipse marker symbol types.
42+
*/
43+
class TestQgsEllipseMarkerSymbol : public QObject
44+
{
45+
Q_OBJECT
46+
47+
public:
48+
TestQgsEllipseMarkerSymbol()
49+
: mTestHasError( false )
50+
, mpPointsLayer( 0 )
51+
, mEllipseMarkerLayer( 0 )
52+
, mMarkerSymbol( 0 )
53+
, mSymbolRenderer( 0 )
54+
{}
55+
56+
private slots:
57+
void initTestCase();// will be called before the first testfunction is executed.
58+
void cleanupTestCase();// will be called after the last testfunction was executed.
59+
void init() {} // will be called before each testfunction is executed.
60+
void cleanup() {} // will be called after every testfunction.
61+
62+
void ellipseMarkerSymbol();
63+
64+
private:
65+
bool mTestHasError;
66+
67+
bool imageCheck( const QString& theType );
68+
QgsMapSettings mMapSettings;
69+
QgsVectorLayer * mpPointsLayer;
70+
QgsEllipseSymbolLayerV2* mEllipseMarkerLayer;
71+
QgsMarkerSymbolV2* mMarkerSymbol;
72+
QgsSingleSymbolRendererV2* mSymbolRenderer;
73+
QString mTestDataDir;
74+
QString mReport;
75+
};
76+
77+
78+
void TestQgsEllipseMarkerSymbol::initTestCase()
79+
{
80+
mTestHasError = false;
81+
// init QGIS's paths - true means that all path will be inited from prefix
82+
QgsApplication::init();
83+
QgsApplication::initQgis();
84+
QgsApplication::showSettings();
85+
86+
//create some objects that will be used in all tests...
87+
QString myDataDir( TEST_DATA_DIR ); //defined in CmakeLists.txt
88+
mTestDataDir = myDataDir + '/';
89+
90+
//
91+
//create a poly layer that will be used in all tests...
92+
//
93+
QString pointFileName = mTestDataDir + "points.shp";
94+
QFileInfo pointFileInfo( pointFileName );
95+
mpPointsLayer = new QgsVectorLayer( pointFileInfo.filePath(),
96+
pointFileInfo.completeBaseName(), "ogr" );
97+
98+
// Register the layer with the registry
99+
QgsMapLayerRegistry::instance()->addMapLayers(
100+
QList<QgsMapLayer *>() << mpPointsLayer );
101+
102+
//setup symbol
103+
mEllipseMarkerLayer = new QgsEllipseSymbolLayerV2();
104+
mMarkerSymbol = new QgsMarkerSymbolV2();
105+
mMarkerSymbol->changeSymbolLayer( 0, mEllipseMarkerLayer );
106+
mSymbolRenderer = new QgsSingleSymbolRendererV2( mMarkerSymbol );
107+
mpPointsLayer->setRendererV2( mSymbolRenderer );
108+
109+
// We only need maprender instead of mapcanvas
110+
// since maprender does not require a qui
111+
// and is more light weight
112+
//
113+
mMapSettings.setLayers( QStringList() << mpPointsLayer->id() );
114+
mReport += "<h1>Ellipse Marker Tests</h1>\n";
115+
116+
}
117+
void TestQgsEllipseMarkerSymbol::cleanupTestCase()
118+
{
119+
QString myReportFile = QDir::tempPath() + "/qgistest.html";
120+
QFile myFile( myReportFile );
121+
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
122+
{
123+
QTextStream myQTextStream( &myFile );
124+
myQTextStream << mReport;
125+
myFile.close();
126+
}
127+
128+
QgsApplication::exitQgis();
129+
}
130+
131+
void TestQgsEllipseMarkerSymbol::ellipseMarkerSymbol()
132+
{
133+
mReport += "<h2>Ellipse marker symbol layer test</h2>\n";
134+
135+
mEllipseMarkerLayer->setFillColor( Qt::blue );
136+
mEllipseMarkerLayer->setOutlineColor( Qt::black );
137+
mEllipseMarkerLayer->setSymbolName( "circle" );
138+
mEllipseMarkerLayer->setSymbolHeight( 3 );
139+
mEllipseMarkerLayer->setSymbolWidth( 6 );
140+
mEllipseMarkerLayer->setOutlineWidth( 0.8 );
141+
QVERIFY( imageCheck( "ellipsemarker" ) );
142+
}
143+
144+
//
145+
// Private helper functions not called directly by CTest
146+
//
147+
148+
149+
bool TestQgsEllipseMarkerSymbol::imageCheck( const QString& theTestType )
150+
{
151+
//use the QgsRenderChecker test utility class to
152+
//ensure the rendered output matches our control image
153+
mMapSettings.setExtent( mpPointsLayer->extent() );
154+
mMapSettings.setOutputDpi( 96 );
155+
QgsRenderChecker myChecker;
156+
myChecker.setControlPathPrefix( "symbol_ellipsemarker" );
157+
myChecker.setControlName( "expected_" + theTestType );
158+
myChecker.setMapSettings( mMapSettings );
159+
bool myResultFlag = myChecker.runTest( theTestType );
160+
mReport += myChecker.report();
161+
return myResultFlag;
162+
}
163+
164+
QTEST_MAIN( TestQgsEllipseMarkerSymbol )
165+
#include "testqgsellipsemarker.moc"

tests/src/core/testqgsfontmarker.cpp

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/***************************************************************************
2+
testqgsfontmarker.cpp
3+
---------------------
4+
Date : Nov 2015
5+
Copyright : (C) 2015 by Nyall Dawson
6+
Email : nyall dot dawson at gmail dot com
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+
#include <QtTest/QtTest>
16+
#include <QObject>
17+
#include <QString>
18+
#include <QStringList>
19+
#include <QApplication>
20+
#include <QFileInfo>
21+
#include <QDir>
22+
#include <QDesktopServices>
23+
24+
//qgis includes...
25+
#include <qgsmaprenderer.h>
26+
#include <qgsmaplayer.h>
27+
#include <qgsvectorlayer.h>
28+
#include <qgsapplication.h>
29+
#include <qgsproviderregistry.h>
30+
#include <qgsmaplayerregistry.h>
31+
#include <qgssymbolv2.h>
32+
#include <qgssinglesymbolrendererv2.h>
33+
#include "qgsmarkersymbollayerv2.h"
34+
#include "qgsdatadefined.h"
35+
#include "qgsfontutils.h"
36+
37+
//qgis test includes
38+
#include "qgsrenderchecker.h"
39+
40+
/** \ingroup UnitTests
41+
* This is a unit test for font marker symbol types.
42+
*/
43+
class TestQgsFontMarkerSymbol : public QObject
44+
{
45+
Q_OBJECT
46+
47+
public:
48+
TestQgsFontMarkerSymbol()
49+
: mTestHasError( false )
50+
, mpPointsLayer( 0 )
51+
, mFontMarkerLayer( 0 )
52+
, mMarkerSymbol( 0 )
53+
, mSymbolRenderer( 0 )
54+
{}
55+
56+
private slots:
57+
void initTestCase();// will be called before the first testfunction is executed.
58+
void cleanupTestCase();// will be called after the last testfunction was executed.
59+
void init() {} // will be called before each testfunction is executed.
60+
void cleanup() {} // will be called after every testfunction.
61+
62+
void fontMarkerSymbol();
63+
64+
private:
65+
bool mTestHasError;
66+
67+
bool imageCheck( const QString& theType );
68+
QgsMapSettings mMapSettings;
69+
QgsVectorLayer * mpPointsLayer;
70+
QgsFontMarkerSymbolLayerV2* mFontMarkerLayer;
71+
QgsMarkerSymbolV2* mMarkerSymbol;
72+
QgsSingleSymbolRendererV2* mSymbolRenderer;
73+
QString mTestDataDir;
74+
QString mReport;
75+
};
76+
77+
78+
void TestQgsFontMarkerSymbol::initTestCase()
79+
{
80+
mTestHasError = false;
81+
// init QGIS's paths - true means that all path will be inited from prefix
82+
QgsApplication::init();
83+
QgsApplication::initQgis();
84+
QgsApplication::showSettings();
85+
86+
//create some objects that will be used in all tests...
87+
QString myDataDir( TEST_DATA_DIR ); //defined in CmakeLists.txt
88+
mTestDataDir = myDataDir + '/';
89+
90+
//
91+
//create a poly layer that will be used in all tests...
92+
//
93+
QString pointFileName = mTestDataDir + "points.shp";
94+
QFileInfo pointFileInfo( pointFileName );
95+
mpPointsLayer = new QgsVectorLayer( pointFileInfo.filePath(),
96+
pointFileInfo.completeBaseName(), "ogr" );
97+
98+
// Register the layer with the registry
99+
QgsMapLayerRegistry::instance()->addMapLayers(
100+
QList<QgsMapLayer *>() << mpPointsLayer );
101+
102+
//setup symbol
103+
mFontMarkerLayer = new QgsFontMarkerSymbolLayerV2();
104+
mMarkerSymbol = new QgsMarkerSymbolV2();
105+
mMarkerSymbol->changeSymbolLayer( 0, mFontMarkerLayer );
106+
mSymbolRenderer = new QgsSingleSymbolRendererV2( mMarkerSymbol );
107+
mpPointsLayer->setRendererV2( mSymbolRenderer );
108+
109+
// We only need maprender instead of mapcanvas
110+
// since maprender does not require a qui
111+
// and is more light weight
112+
//
113+
mMapSettings.setLayers( QStringList() << mpPointsLayer->id() );
114+
mReport += "<h1>Font Marker Tests</h1>\n";
115+
116+
}
117+
void TestQgsFontMarkerSymbol::cleanupTestCase()
118+
{
119+
QString myReportFile = QDir::tempPath() + "/qgistest.html";
120+
QFile myFile( myReportFile );
121+
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
122+
{
123+
QTextStream myQTextStream( &myFile );
124+
myQTextStream << mReport;
125+
myFile.close();
126+
}
127+
128+
QgsApplication::exitQgis();
129+
}
130+
131+
void TestQgsFontMarkerSymbol::fontMarkerSymbol()
132+
{
133+
mReport += "<h2>Font marker symbol layer test</h2>\n";
134+
135+
mFontMarkerLayer->setColor( Qt::blue );
136+
QFont font = QgsFontUtils::getStandardTestFont( "Bold" );
137+
mFontMarkerLayer->setFontFamily( font.family() );
138+
mFontMarkerLayer->setCharacter( 'A' );
139+
mFontMarkerLayer->setSize( 12 );
140+
QVERIFY( imageCheck( "fontmarker" ) );
141+
}
142+
143+
//
144+
// Private helper functions not called directly by CTest
145+
//
146+
147+
148+
bool TestQgsFontMarkerSymbol::imageCheck( const QString& theTestType )
149+
{
150+
//use the QgsRenderChecker test utility class to
151+
//ensure the rendered output matches our control image
152+
mMapSettings.setExtent( mpPointsLayer->extent() );
153+
mMapSettings.setOutputDpi( 96 );
154+
QgsRenderChecker myChecker;
155+
myChecker.setControlPathPrefix( "symbol_fontmarker" );
156+
myChecker.setControlName( "expected_" + theTestType );
157+
myChecker.setMapSettings( mMapSettings );
158+
bool myResultFlag = myChecker.runTest( theTestType );
159+
mReport += myChecker.report();
160+
return myResultFlag;
161+
}
162+
163+
QTEST_MAIN( TestQgsFontMarkerSymbol )
164+
#include "testqgsfontmarker.moc"

tests/src/core/testqgslinefillsymbol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void TestQgsLineFillSymbol::initTestCase()
116116
// and is more light weight
117117
//
118118
mMapSettings.setLayers( QStringList() << mpPolysLayer->id() );
119-
mReport += "<h1>Gradient Renderer Tests</h1>\n";
119+
mReport += "<h1>Line Fill Symbol Tests</h1>\n";
120120

121121
}
122122
void TestQgsLineFillSymbol::cleanupTestCase()

tests/src/core/testqgspointpatternfillsymbol.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void TestQgsPointPatternFillSymbol::initTestCase()
104104
QgsMapLayerRegistry::instance()->addMapLayers(
105105
QList<QgsMapLayer *>() << mpPolysLayer );
106106

107-
//setup gradient fill
107+
//setup symbol
108108
mPointPatternFill = new QgsPointPatternFillSymbolLayer();
109109
mFillSymbol = new QgsFillSymbolV2();
110110
mFillSymbol->changeSymbolLayer( 0, mPointPatternFill );
@@ -116,7 +116,7 @@ void TestQgsPointPatternFillSymbol::initTestCase()
116116
// and is more light weight
117117
//
118118
mMapSettings.setLayers( QStringList() << mpPolysLayer->id() );
119-
mReport += "<h1>Gradient Renderer Tests</h1>\n";
119+
mReport += "<h1>Point Pattern Fill Tests</h1>\n";
120120

121121
}
122122
void TestQgsPointPatternFillSymbol::cleanupTestCase()

0 commit comments

Comments
 (0)