Skip to content

Commit

Permalink
Added regression test for ticket #992
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8980 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Aug 2, 2008
1 parent bc3da6a commit ca3dd86
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/src/core/CMakeLists.txt
Expand Up @@ -127,6 +127,27 @@ ELSE (APPLE)
ENDIF (APPLE)


#
# Ticket 992 Regression992 test
#
SET(regression992_SRCS regression992.cpp ${util_SRCS})
SET(regression992_MOC_CPPS regression992.cpp)
QT4_WRAP_CPP(regression992_MOC_SRCS ${regression992_MOC_CPPS})
ADD_CUSTOM_TARGET(regression992moc ALL DEPENDS ${regression992_MOC_SRCS})
ADD_EXECUTABLE(regression992 ${regression992_SRCS})
ADD_DEPENDENCIES(regression992 regression992moc)
TARGET_LINK_LIBRARIES(regression992 ${QT_LIBRARIES} qgis_core)
SET_TARGET_PROPERTIES(regression992
PROPERTIES INSTALL_RPATH ${QGIS_LIB_DIR}
INSTALL_RPATH_USE_LINK_PATH true)
IF (APPLE)
# For Mac OS X, the executable must be at the root of the bundle's executable folder
INSTALL(TARGETS regression992 RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
ADD_TEST(regression992 ${CMAKE_INSTALL_PREFIX}/regression992)
ELSE (APPLE)
INSTALL(TARGETS regression992 RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
ADD_TEST(regression992 ${CMAKE_INSTALL_PREFIX}/bin/regression992)
ENDIF (APPLE)
#
# Ticket 1141 Regression1141 test
#
Expand Down
117 changes: 117 additions & 0 deletions tests/src/core/regression992.cpp
@@ -0,0 +1,117 @@
/***************************************************************************
testqgsvectorfilewriter.cpp
--------------------------------------
Date : Frida Nov 23 2007
Copyright : (C) 2007 by Tim Sutton
Email : tim@linfiniti.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>
#include <QObject>
#include <QString>
#include <QStringList>
#include <QObject>
#include <iostream>
#include <QApplication>
#include <QFileInfo>
#include <QDir>
#include <QPainter>
#include <QSettings>
#include <QTime>
#include <QDesktopServices>


//qgis includes...
#include <qgsrasterlayer.h>
#include <qgsrasterbandstats.h>
#include <qgsmaplayerregistry.h>
#include <qgsapplication.h>
#include <qgsmaprender.h>

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


/** \ingroup UnitTests
* This is a regression test for ticket #992.
*/
class Regression992: 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.

void regression992();
private:
bool render(QString theFileName);
QString mTestDataDir;
QgsRasterLayer * mpRasterLayer;
QgsMapRender * mpMapRenderer;
QString mReport;
};

//runs before all tests
void Regression992::initTestCase()
{
// init QGIS's paths - true means that all path will be inited from prefix
QString qgisPath = QCoreApplication::applicationDirPath ();
QgsApplication::setPrefixPath(INSTALL_PREFIX, true);
QgsApplication::showSettings();
//create some objects that will be used in all tests...
//create a raster layer that will be used in all tests...
mTestDataDir = QString(TEST_DATA_DIR) + QDir::separator(); //defined in CMakeLists.txt
QString myFileName = mTestDataDir + "rgbwcmyk01_YeGeo.jp2";
QFileInfo myRasterFileInfo ( myFileName );
mpRasterLayer = new QgsRasterLayer ( myRasterFileInfo.filePath(),
myRasterFileInfo.completeBaseName() );
// Register the layer with the registry
QgsMapLayerRegistry::instance()->addMapLayer(mpRasterLayer);
// add the test layer to the maprender
mpMapRenderer = new QgsMapRender();
QStringList myLayers;
myLayers << mpRasterLayer->getLayerID();
mpMapRenderer->setLayerSet(myLayers);
mReport += "<h1>Regression 992 Test</h1>\n";
mReport += "<p>See <a href=\"https://trac.osgeo.org/qgis/ticket/992\">"
"trac ticket 992</a> for more details.</p>";
}
//runs after all tests
void Regression992::cleanupTestCase()
{
QString myReportFile = QDir::tempPath() + QDir::separator() + "regression992.html";
QFile myFile ( myReportFile);
if ( myFile.open ( QIODevice::WriteOnly ) )
{
QTextStream myQTextStream ( &myFile );
myQTextStream << mReport;
myFile.close();
QDesktopServices::openUrl("file://"+myReportFile);
}
}

void Regression992::regression992()
{
QVERIFY ( mpRasterLayer->isValid() );
mpMapRenderer->setExtent(mpRasterLayer->extent());
QString myDataDir (TEST_DATA_DIR); //defined in CmakeLists.txt
QString myTestDataDir = myDataDir + QDir::separator();
QgsRenderChecker myChecker;
myChecker.setExpectedImage ( myTestDataDir + "expected_rgbwcmyk01_YeGeo.jp2.png" );
myChecker.setMapRenderer ( mpMapRenderer );
bool myResultFlag = myChecker.runTest("regression992");
mReport += "\n\n\n" + myChecker.report();
QVERIFY(myResultFlag);
}

QTEST_MAIN(Regression992)
#include "moc_regression992.cxx"

Binary file added tests/testdata/rgbwcmyk01_YeGeo.jp2
Binary file not shown.

0 comments on commit ca3dd86

Please sign in to comment.