Updated these tests to use the qgsrenderchecker class to validate results.

srcMakelist modified to gui tests will build


git-svn-id: http://svn.osgeo.org/qgis/trunk@8017 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
timlinux 2008-01-21 13:17:30 +00:00
parent 35213117ac
commit 0fb249930c
5 changed files with 106 additions and 134 deletions

View File

@ -1,3 +1,4 @@
IF (ENABLE_TESTS)
SUBDIRS(core)
SUBDIRS(gui)
ENDIF (ENABLE_TESTS)

View File

@ -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})

View File

@ -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::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);
}
}
void TestQgsMapRender::performanceTest()
{
//
// Now render our layers onto a pixmap
//
QPixmap myPixmap( 1800,900 );
myPixmap.fill ( QColor ( "#98dbf9" ) );
QPainter myPainter( &myPixmap );
mpMapRenderer->setOutputSize( QSize ( 1800,900 ),72 );
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);
}

View File

@ -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,7 +46,7 @@ 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.
@ -49,11 +54,13 @@ class TestQgsRasterLayer: public QObject
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)

View File

@ -1,9 +1,9 @@
/***************************************************************************
testqgsvectorfilewriter.cpp
testqgsrenderers.cpp
--------------------------------------
Date : Sun Sep 16 12:22:54 AKDT 2007
Copyright : (C) 2007 by Gary E. Sherman
Email : sherman at mrcc dot com
Date : 20 Jan 2008
Copyright : (C) 2008 by Tim Sutton
Email : tim @ linfiniti.com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
@ -15,10 +15,6 @@
#include <QtTest>
#include <QObject>
#include <QString>
#include <QPainter>
#include <QPixmap>
#include <QByteArray>
#include <QBuffer>
#include <QStringList>
#include <QObject>
#include <QApplication>
@ -34,6 +30,8 @@
#include <qgsapplication.h>
#include <qgsproviderregistry.h>
#include <qgsmaplayerregistry.h>
//qgis test includes
#include "qgsrenderchecker.h"
/** \ingroup UnitTests
* This is a unit test for the different renderers for vector layers.
@ -134,6 +132,7 @@ void TestQgsRenderers::initTestCase()
myLayers << mpPolysLayer->getLayerID();
myLayers << mpLinesLayer->getLayerID();
mpMapRenderer->setLayerSet(myLayers);
mReport+= "<h1>Vector Renderer Tests</h1>\n";
}
void TestQgsRenderers::cleanupTestCase()
{
@ -151,28 +150,28 @@ void TestQgsRenderers::cleanupTestCase()
void TestQgsRenderers::singleSymbol()
{
mReport+= "<h1>Single symbol renderer test</h1>\n";
mReport+= "<h2>Single symbol renderer test</h2>\n";
QVERIFY ( setQml("single") );
QVERIFY ( imageCheck("single"));
}
void TestQgsRenderers::uniqueValue()
{
mReport+= "<h1>Unique value symbol renderer test</h1>\n";
mReport+= "<h2>Unique value symbol renderer test</h2>\n";
QVERIFY ( setQml("uniquevalue") );
QVERIFY ( imageCheck("uniquevalue"));
}
void TestQgsRenderers::graduatedSymbol()
{
mReport+= "<h1>Graduated symbol renderer test</h1>\n";
mReport+= "<h2>Graduated symbol renderer test</h2>\n";
QVERIFY ( setQml("graduated") );
QVERIFY ( imageCheck("graduated"));
}
void TestQgsRenderers::continuousSymbol()
{
mReport+= "<h1>Continuous symbol renderer test</h1>\n";
mReport+= "<h2>Continuous symbol renderer test</h2>\n";
QVERIFY ( setQml("continuous") );
QVERIFY ( imageCheck("continuous"));
}
@ -217,72 +216,16 @@ bool TestQgsRenderers::setQml (QString theType)
bool TestQgsRenderers::imageCheck(QString theTestType)
{
//
// Now render our layers onto a pixmap
//
QPixmap myPixmap( 800,800 );
myPixmap.fill ( QColor ( "#98dbf9" ) );
QPainter myPainter( &myPixmap );
mpMapRenderer->setOutputSize( QSize ( 800,800 ),72 );
//use the QgsRenderChecker test utility class to
//ensure the rendered output matches our control image
mpMapRenderer->setExtent(mpPointsLayer->extent());
mpMapRenderer->render( &myPainter );
myPainter.end();
//
// Save the pixmap to disk so the user can make a
// visual assessment if needed
//
myPixmap.save (QDir::tempPath() + QDir::separator() + theTestType + ".png");
//
// Load the expected result pixmap
//
QPixmap myExpectedPixmap (mTestDataDir + "expected_" + theTestType + ".png");
mReport+= "<table>"
"<tr><td>Test Result:</td><td>Expected Result:</td></tr>\n"
"<tr><td><img src=\"" +
QDir::tempPath() + QDir::separator() + theTestType + ".png" +
"\"></td>\n<td><img src=\"" +
mTestDataDir + "expected_" + theTestType + ".png" +
"\"></td></tr></table>\n";
//
// Now load the renderered image and the expected image
// each into a byte array, and then iterate through them
// counting how many dissimilar pixel values there are
//
QByteArray myResultBytes;
QBuffer myResultBuffer(&myResultBytes);
myResultBuffer.open(QIODevice::WriteOnly);
myPixmap.save(&myResultBuffer, "PNG"); // writes pixmap into bytes in PNG format
QByteArray myExpectedBytes;
QBuffer myExpectedBuffer(&myExpectedBytes);
myExpectedBuffer.open(QIODevice::WriteOnly);
myExpectedPixmap.save(&myExpectedBuffer, "PNG"); // writes pixmap into bytes in PNG format
if (myExpectedBytes.size() != myResultBytes.size())
{
qDebug ("Test image and result image for " + theTestType + " are different - FAILING!");
return false;
}
int myMismatchCount = 0;
for (int i = 0; i < myExpectedBytes.size(); ++i)
{
if (myExpectedBytes.at(i) != myResultBytes.at(i))
{
++myMismatchCount;
}
}
qDebug (QString::number(myMismatchCount).toLocal8Bit() + "/" +
QString::number(myExpectedBytes.size()).toLocal8Bit() +
" bytes mismatched");;
if ( myMismatchCount==0 )
{
return true;
}
else
{
return false;
}
QString myExpectedImage = mTestDataDir + "expected_" + theTestType + ".png";
QgsRenderChecker myChecker;
myChecker.setExpectedImage ( myExpectedImage );
myChecker.setMapRenderer ( mpMapRenderer );
bool myResultFlag = myChecker.runTest( theTestType );
mReport += myChecker.report();
return myResultFlag;
}
QTEST_MAIN(TestQgsRenderers)