Skip to content
Permalink
Browse files
Updated these tests to use the qgsrenderchecker class to validate res…
…ults.

srcMakelist modified to gui tests will build


git-svn-id: http://svn.osgeo.org/qgis/trunk@8017 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Jan 21, 2008
1 parent 3521311 commit 0fb249930c7d4e7bd03564e60c24f8e88c150252
Showing with 106 additions and 134 deletions.
  1. +1 −0 tests/src/CMakeLists.txt
  2. +10 −6 tests/src/core/CMakeLists.txt
  3. +39 −25 tests/src/core/testqgsmaprender.cpp
  4. +36 −26 tests/src/core/testqgsrasterlayer.cpp
  5. +20 −77 tests/src/core/testqgsrenderers.cpp
@@ -1,3 +1,4 @@
IF (ENABLE_TESTS)
SUBDIRS(core)
SUBDIRS(gui)
ENDIF (ENABLE_TESTS)
@@ -1,3 +1,7 @@
# Standard includes and utils to compile into all tests.
SET (util_SRCS qgsrenderchecker.cpp)


#####################################################
# Don't forget to include output directory, otherwise
# the UI file won't be wrapped!
@@ -64,7 +68,7 @@ ENDIF (APPLE)
#
# QgsApplication test
#
SET(qgis_applicationtest_SRCS testqgsapplication.cpp)
SET(qgis_applicationtest_SRCS testqgsapplication.cpp ${util_SRCS})
SET(qgis_applicationtest_MOC_CPPS testqgsapplication.cpp)
QT4_WRAP_CPP(qgis_applicationtest_MOC_SRCS ${qgis_applicationtest_MOC_CPPS})
ADD_CUSTOM_TARGET(qgis_applicationtestmoc ALL DEPENDS ${qgis_applicationtest_MOC_SRCS})
@@ -85,7 +89,7 @@ ENDIF (APPLE)
#
# QgsFileWriter test
#
SET(qgis_filewritertest_SRCS testqgsvectorfilewriter.cpp)
SET(qgis_filewritertest_SRCS testqgsvectorfilewriter.cpp ${util_SRCS})
SET(qgis_filewritertest_MOC_CPPS testqgsvectorfilewriter.cpp)
QT4_WRAP_CPP(qgis_filewritertest_MOC_SRCS ${qgis_filewritertest_MOC_CPPS})
ADD_CUSTOM_TARGET(qgis_filewritertestmoc ALL DEPENDS ${qgis_filewritertest_MOC_SRCS})
@@ -106,7 +110,7 @@ ENDIF (APPLE)
#
# QgsRasterLayer test
#
SET(qgis_rasterlayertest_SRCS testqgsrasterlayer.cpp)
SET(qgis_rasterlayertest_SRCS testqgsrasterlayer.cpp ${util_SRCS})
SET(qgis_rasterlayertest_MOC_CPPS testqgsrasterlayer.cpp)
QT4_WRAP_CPP(qgis_rasterlayertest_MOC_SRCS ${qgis_rasterlayertest_MOC_CPPS})
ADD_CUSTOM_TARGET(qgis_rasterlayertestmoc ALL DEPENDS ${qgis_rasterlayertest_MOC_SRCS})
@@ -127,7 +131,7 @@ ENDIF (APPLE)
#
# QgsMapLayer test
#
SET(qgis_maplayertest_SRCS testqgsmaplayer.cpp)
SET(qgis_maplayertest_SRCS testqgsmaplayer.cpp ${util_SRCS})
SET(qgis_maplayertest_MOC_CPPS testqgsmaplayer.cpp)
QT4_WRAP_CPP(qgis_maplayertest_MOC_SRCS ${qgis_maplayertest_MOC_CPPS})
ADD_CUSTOM_TARGET(qgis_maplayertestmoc ALL DEPENDS ${qgis_maplayertest_MOC_SRCS})
@@ -148,7 +152,7 @@ ENDIF (APPLE)
#
# Qgs Renderers test (qsinglesymbol renderer etc)
#
SET(qgis_rendererstest_SRCS testqgsrenderers.cpp)
SET(qgis_rendererstest_SRCS testqgsrenderers.cpp ${util_SRCS})
SET(qgis_rendererstest_MOC_CPPS testqgsrenderers.cpp)
QT4_WRAP_CPP(qgis_rendererstest_MOC_SRCS ${qgis_rendererstest_MOC_CPPS})
ADD_CUSTOM_TARGET(qgis_rendererstestmoc ALL DEPENDS ${qgis_rendererstest_MOC_SRCS})
@@ -169,7 +173,7 @@ ENDIF (APPLE)
#
# QgsMapRender test
#
SET(qgis_maprendertest_SRCS testqgsmaprender.cpp)
SET(qgis_maprendertest_SRCS testqgsmaprender.cpp ${util_SRCS})
SET(qgis_maprendertest_MOC_CPPS testqgsmaprender.cpp)
QT4_WRAP_CPP(qgis_maprendertest_MOC_SRCS ${qgis_maprendertest_MOC_CPPS})
ADD_CUSTOM_TARGET(qgis_maprendertestmoc ALL DEPENDS ${qgis_maprendertest_MOC_SRCS})
@@ -2,8 +2,8 @@
testqgsvectorfilewriter.cpp
--------------------------------------
Date : Sun Sep 16 12:22:54 AKDT 2007
Copyright : (C) 2007 by Gary E. Sherman
Email : sherman at mrcc dot com
Copyright : (C) 2007 by Tim Sutton
Email : tim @ linfiniti.com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
@@ -23,6 +23,7 @@
#include <iostream>

#include <QApplication>
#include <QDesktopServices>

//qgis includes...
#include <qgsvectorlayer.h> //defines QgsFieldMap
@@ -41,6 +42,9 @@
#include <qgsproviderregistry.h>
#include <qgsmaplayerregistry.h>

//qgs unit test utility class
#include "qgsrenderchecker.h"

/** \ingroup UnitTests
* This is a unit test for the QgsMapRender class.
* It will do some performance testing too
@@ -51,6 +55,7 @@ class TestQgsMapRender: public QObject
Q_OBJECT;
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.

@@ -64,6 +69,7 @@ class TestQgsMapRender: public QObject
QgsFieldMap mFields;
QgsMapRender * mpMapRenderer;
QgsMapLayer * mpPolysLayer;
QString mReport;
};

void TestQgsMapRender::initTestCase()
@@ -84,7 +90,7 @@ void TestQgsMapRender::initTestCase()

//create some objects that will be used in all tests...
mEncoding = "UTF-8";
QgsField myField1("Field1",QVariant::String,"String",10,0,"Field 1 comment");
QgsField myField1("Value",QVariant::Int,"int",10,0,"Value on lon");
mFields.insert(0, myField1);
mSRS = QgsSpatialRefSys(GEOWKT);
//
@@ -94,6 +100,9 @@ void TestQgsMapRender::initTestCase()
QString myTestDataDir = myDataDir + QDir::separator();
QString myTmpDir = QDir::tempPath() + QDir::separator() ;
QString myFileName = myTmpDir + "maprender_testdata.shp";
//copy over the default qml for our generated layer
QString myQmlFileName = myTestDataDir + "maprender_testdata.qml";
QFile::copy(myQmlFileName, myTmpDir + "maprender_testdata.qml");
qDebug ( "Checking test dataset exists...");
qDebug ( myFileName );
if (!QFile::exists(myFileName))
@@ -131,7 +140,7 @@ void TestQgsMapRender::initTestCase()
QgsFeature myFeature;
myFeature.setTypeName("WKBPolygon");
myFeature.setGeometry(mypPolygonGeometry);
myFeature.addAttribute(0,"HelloWorld");
myFeature.addAttribute(0,i);
//
// Write the feature to the filewriter
// and check for errors
@@ -167,32 +176,37 @@ void TestQgsMapRender::initTestCase()
QStringList myLayers;
myLayers << mpPolysLayer->getLayerID();
mpMapRenderer->setLayerSet(myLayers);
mReport += "<h1>Map Render Tests</h1>\n";
}

void TestQgsMapRender::performanceTest()

void TestQgsMapRender::cleanupTestCase()
{
QString myReportFile = QDir::tempPath() + QDir::separator() + "maprendertest.html";
QFile myFile ( myReportFile);
if ( myFile.open ( QIODevice::WriteOnly ) )
{
QTextStream myQTextStream ( &myFile );
myQTextStream << mReport;
myFile.close();
QDesktopServices::openUrl("file://"+myReportFile);
}

}

//
// Now render our layers onto a pixmap
//
QPixmap myPixmap( 1800,900 );
myPixmap.fill ( QColor ( "#98dbf9" ) );
QPainter myPainter( &myPixmap );
mpMapRenderer->setOutputSize( QSize ( 1800,900 ),72 );


void TestQgsMapRender::performanceTest()
{
mpMapRenderer->setExtent(mpPolysLayer->extent());
qDebug ("Extents set to:");
qDebug (mpPolysLayer->extent().stringRep());
QTime myTime;
myTime.start();
mpMapRenderer->render( &myPainter );
qDebug ("Elapsed time in ms for render job: " +
QString::number ( myTime.elapsed() ).toLocal8Bit());
myPainter.end();
//
// Save the pixmap to disk so the user can make a
// visual assessment if needed
//
myPixmap.save (QDir::tempPath() + QDir::separator() + "maprender_result.png");
QString myDataDir (TEST_DATA_DIR); //defined in CmakeLists.txt
QString myTestDataDir = myDataDir + QDir::separator();
QgsRenderChecker myChecker;
myChecker.setExpectedImage ( myTestDataDir + "expected_maprender.png" );
myChecker.setMapRenderer ( mpMapRenderer );
bool myResultFlag = myChecker.runTest("maprender");
mReport += myChecker.report();
QVERIFY(myResultFlag);
}


@@ -24,6 +24,7 @@
#include <QPainter>
#include <QSettings>
#include <QTime>
#include <QDesktopServices>


//qgis includes...
@@ -33,6 +34,10 @@
#include <qgsapplication.h>
#include <qgsmaprender.h>

//qgis unit test includes
#include <qgsrenderchecker.h>


/** \ingroup UnitTests
* This is a unit test for the QgsRasterLayer class.
*/
@@ -41,19 +46,21 @@ class TestQgsRasterLayer: public QObject
Q_OBJECT;
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 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 isValid();
void pseudoColor();
void checkDimensions();
private:
void render(QString theFileName);
bool render(QString theFileName);
QgsRasterLayer * mpRasterLayer;
QgsMapRender * mpMapRenderer;
QString mReport;
};

//runs before all tests
void TestQgsRasterLayer::initTestCase()
{
// init QGIS's paths - true means that all path will be inited from prefix
@@ -82,12 +89,27 @@ void TestQgsRasterLayer::initTestCase()
QStringList myLayers;
myLayers << mpRasterLayer->getLayerID();
mpMapRenderer->setLayerSet(myLayers);
mReport += "<h1>Raster Layer Tests</h1>\n";
}
//runs after all tests
void TestQgsRasterLayer::cleanupTestCase()
{
QString myReportFile = QDir::tempPath() + QDir::separator() + "rastertest.html";
QFile myFile ( myReportFile);
if ( myFile.open ( QIODevice::WriteOnly ) )
{
QTextStream myQTextStream ( &myFile );
myQTextStream << mReport;
myFile.close();
QDesktopServices::openUrl("file://"+myReportFile);
}

}

void TestQgsRasterLayer::isValid()
{
QVERIFY ( mpRasterLayer->isValid() );
render("raster_test.png");
QVERIFY ( render("raster") );
}

void TestQgsRasterLayer::pseudoColor()
@@ -98,7 +120,7 @@ void TestQgsRasterLayer::pseudoColor()
QgsContrastEnhancement::STRETCH_TO_MINMAX, false);
mpRasterLayer->setMinimumValue(mpRasterLayer->getGrayBandName(),0.0, false);
mpRasterLayer->setMaximumValue(mpRasterLayer->getGrayBandName(),0.0);
render("raster_pseudo_test.png");
QVERIFY(render("raster_pseudo"));
}

void TestQgsRasterLayer::checkDimensions()
@@ -110,30 +132,18 @@ void TestQgsRasterLayer::checkDimensions()
QVERIFY ( mpRasterLayer->getRasterBandStats(1).elementCount == 100 );
}

void TestQgsRasterLayer::render(QString theFileName)
bool TestQgsRasterLayer::render(QString theTestType)
{

//
// Now render our layers onto a pixmap
//
QPixmap myPixmap( 100,100 );
myPixmap.fill ( QColor ( "#98dbf9" ) );
QPainter myPainter( &myPixmap );
mpMapRenderer->setOutputSize( QSize ( 100,100 ),72 );
mReport += "<h2>" + theTestType + "</h2>\n";
mpMapRenderer->setExtent(mpRasterLayer->extent());
qDebug ("Extents set to:");
qDebug (mpRasterLayer->extent().stringRep());
QTime myTime;
myTime.start();
mpMapRenderer->render( &myPainter );
qDebug ("Elapsed time in ms for render job: " +
QString::number ( myTime.elapsed() ).toLocal8Bit());
myPainter.end();
//
// Save the pixmap to disk so the user can make a
// visual assessment if needed
//
myPixmap.save (QDir::tempPath() + QDir::separator() + theFileName);
QString myDataDir (TEST_DATA_DIR); //defined in CmakeLists.txt
QString myTestDataDir = myDataDir + QDir::separator();
QgsRenderChecker myChecker;
myChecker.setExpectedImage ( myTestDataDir + "expected_" + theTestType + ".png" );
myChecker.setMapRenderer ( mpMapRenderer );
bool myResultFlag = myChecker.runTest(theTestType);
mReport += "\n\n\n" + myChecker.report();
return myResultFlag;
}

QTEST_MAIN(TestQgsRasterLayer)

0 comments on commit 0fb2499

Please sign in to comment.