Skip to content

Commit

Permalink
Clean up diagram tests
Browse files Browse the repository at this point in the history
- Consolidate tests to single file
- Don't use composition for testing
  • Loading branch information
nyalldawson committed Jun 18, 2015
1 parent e646647 commit e108feb
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 222 deletions.
1 change: 0 additions & 1 deletion tests/src/core/CMakeLists.txt
Expand Up @@ -82,7 +82,6 @@ ADD_QGIS_TEST(clippertest testqgsclipper.cpp)
ADD_QGIS_TEST(distanceareatest testqgsdistancearea.cpp)
ADD_QGIS_TEST(applicationtest testqgsapplication.cpp)
ADD_QGIS_TEST(diagramtest testqgsdiagram.cpp)
ADD_QGIS_TEST(diagramexpressiontest testqgsdiagramexpression.cpp)
ADD_QGIS_TEST(expressiontest testqgsexpression.cpp)
ADD_QGIS_TEST(fieldtest testqgsfield.cpp)
ADD_QGIS_TEST(fieldstest testqgsfields.cpp)
Expand Down
111 changes: 79 additions & 32 deletions tests/src/core/testqgsdiagram.cpp
Expand Up @@ -27,9 +27,6 @@
// #include <qgisapp.h>
#include <diagram/qgspiediagram.h>
#include <qgsdiagramrendererv2.h>
#include <qgscomposition.h>
#include <qgscompositionchecker.h>
#include <qgscomposermap.h>
#include <qgsmaprenderer.h>
#include <qgsmaplayer.h>
#include <qgsvectordataprovider.h>
Expand All @@ -39,12 +36,12 @@
#include <qgsmaplayerregistry.h>
#include <qgsrendererv2.h>
//qgis test includes
#include "qgsrenderchecker.h"
#include "qgsmultirenderchecker.h"
#include "qgspallabeling.h"
#include "qgsproject.h"

/** \ingroup UnitTests
* This is a unit test for the vector layer class.
* Unit tests for the diagram renderer
*/
class TestQgsDiagram : public QObject
{
Expand All @@ -54,20 +51,16 @@ class TestQgsDiagram : public QObject
TestQgsDiagram()
: mTestHasError( false )
, mPointsLayer( 0 )
, mComposition( 0 )
, mPieDiagram( 0 )
, mComposerMap( 0 )
{}

private:
bool mTestHasError;
QgsMapSettings mMapSettings;
QgsVectorLayer * mPointsLayer;
QgsComposition * mComposition;
QString mTestDataDir;
QString mReport;
QgsPieDiagram * mPieDiagram;
QgsComposerMap * mComposerMap;

bool imageCheck( QString theTestType );

private slots:

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

// Create diagrams
mPieDiagram = new QgsPieDiagram();

// Create map composition to draw on
mMapSettings.setLayers( QStringList() << mPointsLayer->id() );
// TODO mMapSettings.setLabelingEngine( new QgsPalLabeling() );
mComposition = new QgsComposition( mMapSettings );
mComposition->setPaperSize( 297, 210 ); // A4 landscape
mComposerMap = new QgsComposerMap( mComposition, 20, 20, 200, 100 );
mComposerMap->setFrameEnabled( true );
mComposition->addComposerMap( mComposerMap );

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

// will be called after the last testfunction was executed.
void cleanupTestCase()
{
delete mComposition;
QgsApplication::exitQgis();
QString myReportFile = QDir::tempPath() + QDir::separator() + "qgistest.html";
QFile myFile( myReportFile );
Expand All @@ -130,8 +113,20 @@ class TestQgsDiagram : public QObject
//QDesktopServices::openUrl( "file:///" + myReportFile );
}
}
void init() {};// will be called before each testfunction is executed.
void cleanup() {};// will be called after every testfunction.

// will be called before each testfunction is executed
void init()
{
mPointsLayer->setDiagramRenderer( 0 );
QgsDiagramLayerSettings dls;
mPointsLayer->setDiagramLayerSettings( dls );
}

// will be called after every testfunction.
void cleanup()
{

}

void testPieDiagram()
{
Expand All @@ -149,35 +144,87 @@ class TestQgsDiagram : public QObject
ds.penWidth = .5;
ds.scaleByArea = true;
ds.sizeType = QgsDiagramSettings::MM;
ds.size = QSizeF( 15, 15 );
ds.size = QSizeF( 5, 5 );
ds.angleOffset = 0;


QgsLinearlyInterpolatedDiagramRenderer *dr = new QgsLinearlyInterpolatedDiagramRenderer();
dr->setLowerValue( 0.0 );
dr->setLowerSize( QSizeF( 0.0, 0.0 ) );
dr->setUpperValue( 10 );
dr->setUpperSize( QSizeF( 100, 100 ) );
dr->setUpperSize( QSizeF( 40, 40 ) );
dr->setClassificationAttribute( 5 ); // Staff
dr->setDiagram( mPieDiagram );
dr->setDiagram( new QgsPieDiagram() );
dr->setDiagramSettings( ds );
mPointsLayer->setDiagramRenderer( dr );

QgsDiagramLayerSettings dls = QgsDiagramLayerSettings();
dls.placement = QgsDiagramLayerSettings::OverPoint;
dls.showAll = true;
mPointsLayer->setDiagramLayerSettings( dls );

QgsProject::instance()->writeEntry( "PAL", "/ShowingAllLabels", true );
QVERIFY( imageCheck( "piediagram" ) );
}

mPointsLayer->setDiagramLayerSettings( dls );
void testPieDiagramExpression()
{
QgsDiagramSettings ds;
QColor col1 = Qt::red;
QColor col2 = Qt::yellow;
col1.setAlphaF( 0.5 );
col2.setAlphaF( 0.5 );
ds.categoryColors = QList<QColor>() << col1 << col2;
ds.categoryAttributes = QList<QString>() << "ln(Pilots + 1)" << "ln(\"Cabin Crew\" + 1)";
ds.maxScaleDenominator = -1;
ds.minScaleDenominator = -1;
ds.minimumSize = 0;
ds.penColor = Qt::green;
ds.penWidth = .5;
ds.scaleByArea = true;
ds.sizeType = QgsDiagramSettings::MM;
ds.size = QSizeF( 5, 5 );
ds.angleOffset = 0;

QgsLinearlyInterpolatedDiagramRenderer *dr = new QgsLinearlyInterpolatedDiagramRenderer();
dr->setLowerValue( 0.0 );
dr->setLowerSize( QSizeF( 0.0, 0.0 ) );
dr->setUpperValue( 10 );
dr->setUpperSize( QSizeF( 40, 40 ) );
dr->setClassificationAttributeIsExpression( true );
dr->setClassificationAttributeExpression( "ln(Staff + 1)" );
dr->setDiagram( new QgsPieDiagram() );
dr->setDiagramSettings( ds );

mComposerMap->setNewExtent( QgsRectangle( -122, -79, -70, 47 ) );
QgsCompositionChecker checker( "piediagram", mComposition );
QgsDiagramLayerSettings dls = QgsDiagramLayerSettings();
dls.placement = QgsDiagramLayerSettings::OverPoint;
dls.showAll = true;
// dls.setRenderer( dr );

QVERIFY( checker.testComposition( mReport ) );
mPointsLayer->setDiagramRenderer( dr );
mPointsLayer->setDiagramLayerSettings( dls );

QVERIFY( imageCheck( "piediagram_expression" ) );

mPointsLayer->setDiagramRenderer( 0 );
}

};

bool TestQgsDiagram::imageCheck( QString theTestType )
{
//use the QgsRenderChecker test utility class to
//ensure the rendered output matches our control image

QgsRectangle extent( -126, 23, -70, 47 );
mMapSettings.setExtent( extent );
mMapSettings.setFlag( QgsMapSettings::ForceVectorOutput );
QgsMultiRenderChecker myChecker;
myChecker.setControlName( "expected_" + theTestType );
myChecker.setMapSettings( mMapSettings );
myChecker.setColorTolerance( 15 );
bool myResultFlag = myChecker.runTest( theTestType, 200 );
mReport += myChecker.report();
return myResultFlag;
}

QTEST_MAIN( TestQgsDiagram )
#include "testqgsdiagram.moc"
189 changes: 0 additions & 189 deletions tests/src/core/testqgsdiagramexpression.cpp

This file was deleted.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e108feb

Please sign in to comment.