Skip to content
Permalink
Browse files

Add initial tests for marker symbol layers

  • Loading branch information
nyalldawson committed Nov 14, 2015
1 parent 5a6bfbb commit d699569b86a321ca40eaea401982e42ae6a25bff
@@ -116,12 +116,14 @@ ADD_QGIS_TEST(dataitemtest testqgsdataitem.cpp)
ADD_QGIS_TEST(datasourceuritest testqgsdatasourceuri.cpp)
ADD_QGIS_TEST(diagramtest testqgsdiagram.cpp)
ADD_QGIS_TEST(distanceareatest testqgsdistancearea.cpp)
ADD_QGIS_TEST(ellipsemarkertest testqgsellipsemarker.cpp)
ADD_QGIS_TEST(expressioncontext testqgsexpressioncontext.cpp)
ADD_QGIS_TEST(expressiontest testqgsexpression.cpp)
ADD_QGIS_TEST(featuretest testqgsfeature.cpp)
ADD_QGIS_TEST(fieldstest testqgsfields.cpp)
ADD_QGIS_TEST(fieldtest testqgsfield.cpp)
ADD_QGIS_TEST(filewritertest testqgsvectorfilewriter.cpp)
ADD_QGIS_TEST(fontmarkertest testqgsfontmarker.cpp)
ADD_QGIS_TEST(fontutils testqgsfontutils.cpp)
ADD_QGIS_TEST(geometryimporttest testqgsgeometryimport.cpp)
ADD_QGIS_TEST(geometrytest testqgsgeometry.cpp)
@@ -164,11 +166,13 @@ ADD_QGIS_TEST(rendererstest testqgsrenderers.cpp)
ADD_QGIS_TEST(rulebasedrenderertest testqgsrulebasedrenderer.cpp)
ADD_QGIS_TEST(scaleexpressiontest testqgsscaleexpression.cpp)
ADD_QGIS_TEST(shapebursttest testqgsshapeburst.cpp )
ADD_QGIS_TEST(simplemarkertest testqgssimplemarker.cpp)
ADD_QGIS_TEST(snappingutilstest testqgssnappingutils.cpp )
ADD_QGIS_TEST(spatialindextest testqgsspatialindex.cpp)
ADD_QGIS_TEST(statisticalsummarytest testqgsstatisticalsummary.cpp)
ADD_QGIS_TEST(stringutilstest testqgsstringutils.cpp)
ADD_QGIS_TEST(stylev2test testqgsstylev2.cpp)
ADD_QGIS_TEST(svgmarkertest testqgssvgmarker.cpp)
ADD_QGIS_TEST(symbolv2test testqgssymbolv2.cpp)
ADD_QGIS_TEST(vectordataprovidertest testqgsvectordataprovider.cpp)
ADD_QGIS_TEST(vectorlayercachetest testqgsvectorlayercache.cpp )
@@ -0,0 +1,165 @@
/***************************************************************************
testqgsellipsemarker.cpp
------------------------
Date : Nov 2015
Copyright : (C) 2015 by Nyall Dawson
Email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* 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 <QtTest/QtTest>
#include <QObject>
#include <QString>
#include <QStringList>
#include <QApplication>
#include <QFileInfo>
#include <QDir>
#include <QDesktopServices>

//qgis includes...
#include <qgsmaprenderer.h>
#include <qgsmaplayer.h>
#include <qgsvectorlayer.h>
#include <qgsapplication.h>
#include <qgsproviderregistry.h>
#include <qgsmaplayerregistry.h>
#include <qgssymbolv2.h>
#include <qgssinglesymbolrendererv2.h>
#include "qgsmarkersymbollayerv2.h"
#include "qgsellipsesymbollayerv2.h"
#include "qgsdatadefined.h"

//qgis test includes
#include "qgsrenderchecker.h"

/** \ingroup UnitTests
* This is a unit test for ellipse marker symbol types.
*/
class TestQgsEllipseMarkerSymbol : public QObject
{
Q_OBJECT

public:
TestQgsEllipseMarkerSymbol()
: mTestHasError( false )
, mpPointsLayer( 0 )
, mEllipseMarkerLayer( 0 )
, mMarkerSymbol( 0 )
, mSymbolRenderer( 0 )
{}

private slots:
void initTestCase();// will be called before the first testfunction is executed.
void cleanupTestCase();// will be called after the last testfunction was executed.
void init() {} // will be called before each testfunction is executed.
void cleanup() {} // will be called after every testfunction.

void ellipseMarkerSymbol();

private:
bool mTestHasError;

bool imageCheck( const QString& theType );
QgsMapSettings mMapSettings;
QgsVectorLayer * mpPointsLayer;
QgsEllipseSymbolLayerV2* mEllipseMarkerLayer;
QgsMarkerSymbolV2* mMarkerSymbol;
QgsSingleSymbolRendererV2* mSymbolRenderer;
QString mTestDataDir;
QString mReport;
};


void TestQgsEllipseMarkerSymbol::initTestCase()
{
mTestHasError = false;
// init QGIS's paths - true means that all path will be inited from prefix
QgsApplication::init();
QgsApplication::initQgis();
QgsApplication::showSettings();

//create some objects that will be used in all tests...
QString myDataDir( TEST_DATA_DIR ); //defined in CmakeLists.txt
mTestDataDir = myDataDir + '/';

//
//create a poly layer that will be used in all tests...
//
QString pointFileName = mTestDataDir + "points.shp";
QFileInfo pointFileInfo( pointFileName );
mpPointsLayer = new QgsVectorLayer( pointFileInfo.filePath(),
pointFileInfo.completeBaseName(), "ogr" );

// Register the layer with the registry
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpPointsLayer );

//setup symbol
mEllipseMarkerLayer = new QgsEllipseSymbolLayerV2();
mMarkerSymbol = new QgsMarkerSymbolV2();
mMarkerSymbol->changeSymbolLayer( 0, mEllipseMarkerLayer );
mSymbolRenderer = new QgsSingleSymbolRendererV2( mMarkerSymbol );
mpPointsLayer->setRendererV2( mSymbolRenderer );

// We only need maprender instead of mapcanvas
// since maprender does not require a qui
// and is more light weight
//
mMapSettings.setLayers( QStringList() << mpPointsLayer->id() );
mReport += "<h1>Ellipse Marker Tests</h1>\n";

}
void TestQgsEllipseMarkerSymbol::cleanupTestCase()
{
QString myReportFile = QDir::tempPath() + "/qgistest.html";
QFile myFile( myReportFile );
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
{
QTextStream myQTextStream( &myFile );
myQTextStream << mReport;
myFile.close();
}

QgsApplication::exitQgis();
}

void TestQgsEllipseMarkerSymbol::ellipseMarkerSymbol()
{
mReport += "<h2>Ellipse marker symbol layer test</h2>\n";

mEllipseMarkerLayer->setFillColor( Qt::blue );
mEllipseMarkerLayer->setOutlineColor( Qt::black );
mEllipseMarkerLayer->setSymbolName( "circle" );
mEllipseMarkerLayer->setSymbolHeight( 3 );
mEllipseMarkerLayer->setSymbolWidth( 6 );
mEllipseMarkerLayer->setOutlineWidth( 0.8 );
QVERIFY( imageCheck( "ellipsemarker" ) );
}

//
// Private helper functions not called directly by CTest
//


bool TestQgsEllipseMarkerSymbol::imageCheck( const QString& theTestType )
{
//use the QgsRenderChecker test utility class to
//ensure the rendered output matches our control image
mMapSettings.setExtent( mpPointsLayer->extent() );
mMapSettings.setOutputDpi( 96 );
QgsRenderChecker myChecker;
myChecker.setControlPathPrefix( "symbol_ellipsemarker" );
myChecker.setControlName( "expected_" + theTestType );
myChecker.setMapSettings( mMapSettings );
bool myResultFlag = myChecker.runTest( theTestType );
mReport += myChecker.report();
return myResultFlag;
}

QTEST_MAIN( TestQgsEllipseMarkerSymbol )
#include "testqgsellipsemarker.moc"
@@ -0,0 +1,164 @@
/***************************************************************************
testqgsfontmarker.cpp
---------------------
Date : Nov 2015
Copyright : (C) 2015 by Nyall Dawson
Email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* 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 <QtTest/QtTest>
#include <QObject>
#include <QString>
#include <QStringList>
#include <QApplication>
#include <QFileInfo>
#include <QDir>
#include <QDesktopServices>

//qgis includes...
#include <qgsmaprenderer.h>
#include <qgsmaplayer.h>
#include <qgsvectorlayer.h>
#include <qgsapplication.h>
#include <qgsproviderregistry.h>
#include <qgsmaplayerregistry.h>
#include <qgssymbolv2.h>
#include <qgssinglesymbolrendererv2.h>
#include "qgsmarkersymbollayerv2.h"
#include "qgsdatadefined.h"
#include "qgsfontutils.h"

//qgis test includes
#include "qgsrenderchecker.h"

/** \ingroup UnitTests
* This is a unit test for font marker symbol types.
*/
class TestQgsFontMarkerSymbol : public QObject
{
Q_OBJECT

public:
TestQgsFontMarkerSymbol()
: mTestHasError( false )
, mpPointsLayer( 0 )
, mFontMarkerLayer( 0 )
, mMarkerSymbol( 0 )
, mSymbolRenderer( 0 )
{}

private slots:
void initTestCase();// will be called before the first testfunction is executed.
void cleanupTestCase();// will be called after the last testfunction was executed.
void init() {} // will be called before each testfunction is executed.
void cleanup() {} // will be called after every testfunction.

void fontMarkerSymbol();

private:
bool mTestHasError;

bool imageCheck( const QString& theType );
QgsMapSettings mMapSettings;
QgsVectorLayer * mpPointsLayer;
QgsFontMarkerSymbolLayerV2* mFontMarkerLayer;
QgsMarkerSymbolV2* mMarkerSymbol;
QgsSingleSymbolRendererV2* mSymbolRenderer;
QString mTestDataDir;
QString mReport;
};


void TestQgsFontMarkerSymbol::initTestCase()
{
mTestHasError = false;
// init QGIS's paths - true means that all path will be inited from prefix
QgsApplication::init();
QgsApplication::initQgis();
QgsApplication::showSettings();

//create some objects that will be used in all tests...
QString myDataDir( TEST_DATA_DIR ); //defined in CmakeLists.txt
mTestDataDir = myDataDir + '/';

//
//create a poly layer that will be used in all tests...
//
QString pointFileName = mTestDataDir + "points.shp";
QFileInfo pointFileInfo( pointFileName );
mpPointsLayer = new QgsVectorLayer( pointFileInfo.filePath(),
pointFileInfo.completeBaseName(), "ogr" );

// Register the layer with the registry
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpPointsLayer );

//setup symbol
mFontMarkerLayer = new QgsFontMarkerSymbolLayerV2();
mMarkerSymbol = new QgsMarkerSymbolV2();
mMarkerSymbol->changeSymbolLayer( 0, mFontMarkerLayer );
mSymbolRenderer = new QgsSingleSymbolRendererV2( mMarkerSymbol );
mpPointsLayer->setRendererV2( mSymbolRenderer );

// We only need maprender instead of mapcanvas
// since maprender does not require a qui
// and is more light weight
//
mMapSettings.setLayers( QStringList() << mpPointsLayer->id() );
mReport += "<h1>Font Marker Tests</h1>\n";

}
void TestQgsFontMarkerSymbol::cleanupTestCase()
{
QString myReportFile = QDir::tempPath() + "/qgistest.html";
QFile myFile( myReportFile );
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
{
QTextStream myQTextStream( &myFile );
myQTextStream << mReport;
myFile.close();
}

QgsApplication::exitQgis();
}

void TestQgsFontMarkerSymbol::fontMarkerSymbol()
{
mReport += "<h2>Font marker symbol layer test</h2>\n";

mFontMarkerLayer->setColor( Qt::blue );
QFont font = QgsFontUtils::getStandardTestFont( "Bold" );
mFontMarkerLayer->setFontFamily( font.family() );
mFontMarkerLayer->setCharacter( 'A' );
mFontMarkerLayer->setSize( 12 );
QVERIFY( imageCheck( "fontmarker" ) );
}

//
// Private helper functions not called directly by CTest
//


bool TestQgsFontMarkerSymbol::imageCheck( const QString& theTestType )
{
//use the QgsRenderChecker test utility class to
//ensure the rendered output matches our control image
mMapSettings.setExtent( mpPointsLayer->extent() );
mMapSettings.setOutputDpi( 96 );
QgsRenderChecker myChecker;
myChecker.setControlPathPrefix( "symbol_fontmarker" );
myChecker.setControlName( "expected_" + theTestType );
myChecker.setMapSettings( mMapSettings );
bool myResultFlag = myChecker.runTest( theTestType );
mReport += myChecker.report();
return myResultFlag;
}

QTEST_MAIN( TestQgsFontMarkerSymbol )
#include "testqgsfontmarker.moc"
@@ -116,7 +116,7 @@ void TestQgsLineFillSymbol::initTestCase()
// and is more light weight
//
mMapSettings.setLayers( QStringList() << mpPolysLayer->id() );
mReport += "<h1>Gradient Renderer Tests</h1>\n";
mReport += "<h1>Line Fill Symbol Tests</h1>\n";

}
void TestQgsLineFillSymbol::cleanupTestCase()
@@ -104,7 +104,7 @@ void TestQgsPointPatternFillSymbol::initTestCase()
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpPolysLayer );

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

}
void TestQgsPointPatternFillSymbol::cleanupTestCase()

0 comments on commit d699569

Please sign in to comment.
You can’t perform that action at this time.