From 36f261a52a531cedd52a4ffcf5c2baec1949d30c Mon Sep 17 00:00:00 2001 From: timlinux Date: Fri, 23 Nov 2007 14:51:24 +0000 Subject: [PATCH] Initial unit test for raster layer class Includes a simple 10x10 raster supplied by Enrico Chiaradia git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7649 c8812cc2-4d05-0410-92ff-de0c093fc19c --- CMakeLists.txt | 4 ++ tests/src/core/CMakeLists.txt | 24 ++++++++- tests/src/core/testqgsrasterlayer.cpp | 77 +++++++++++++++++++++++++++ tests/testdata/tenbytenraster.asc | 19 +++++++ 4 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 tests/src/core/testqgsrasterlayer.cpp create mode 100644 tests/testdata/tenbytenraster.asc diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ce7ff21f06..41d108ad199 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -275,6 +275,10 @@ IF (HAVE_PYTHON) ENDIF (HAVE_PYTHON) IF (ENABLE_TESTS) + #create a variable to specify where our test data is + #so that unit tests can use TEST_DATA_DIR to locate + #the test data. See CMakeLists in test dirs for more info + SET (TEST_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests/testdata") SUBDIRS(tests) ENDIF (ENABLE_TESTS) diff --git a/tests/src/core/CMakeLists.txt b/tests/src/core/CMakeLists.txt index 813e34f6f14..61e5ec27e93 100644 --- a/tests/src/core/CMakeLists.txt +++ b/tests/src/core/CMakeLists.txt @@ -4,13 +4,17 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/core + ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/core/raster ${QT_INCLUDE_DIR} ${GDAL_INCLUDE_DIR} ${PROJ_INCLUDE_DIR} ${GEOS_INCLUDE_DIR} ) -# expect that classes are being IMPORTED for the exe +############################################################# +# Compiler defines + +# expect that classes are being IMPORTED for the tests IF (WIN32) # expect that classes are being imported # Note: MSVC doesn't like when the macros are quotes @@ -28,6 +32,11 @@ IF (WIN32) ENDIF (MSVC) ENDIF (WIN32) +# This define is used for tests that need to locate the test +# data under tests/testdata in the qgis source tree. +# the TEST_DATA_DIR variable is set in the top level CMakeLists.txt +ADD_DEFINITIONS(-DTEST_DATA_DIR="\\"${TEST_DATA_DIR}\\"") + ############################################################# # libraries @@ -76,5 +85,18 @@ ADD_DEPENDENCIES(qgis_filewritertest qgis_filewritertestmoc) TARGET_LINK_LIBRARIES(qgis_filewritertest ${QT_LIBRARIES} qgis_core) INSTALL(TARGETS qgis_filewritertest RUNTIME DESTINATION ${QGIS_BIN_DIR}) ADD_TEST(qgis_filewritertest ${QGIS_BIN_DIR}/qgis_filewritertest) +# +# QgsRasterLayer test +# +SET(qgis_rasterlayertest_SRCS testqgsrasterlayer.cpp) +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}) +ADD_EXECUTABLE(qgis_rasterlayertest ${qgis_rasterlayertest_SRCS}) +ADD_DEPENDENCIES(qgis_rasterlayertest qgis_rasterlayertestmoc) +TARGET_LINK_LIBRARIES(qgis_rasterlayertest ${QT_LIBRARIES} qgis_core) +INSTALL(TARGETS qgis_rasterlayertest RUNTIME DESTINATION ${QGIS_BIN_DIR}) +ADD_TEST(qgis_rasterlayertest ${QGIS_BIN_DIR}/qgis_rasterlayertest) + diff --git a/tests/src/core/testqgsrasterlayer.cpp b/tests/src/core/testqgsrasterlayer.cpp new file mode 100644 index 00000000000..042ca8fdbc4 --- /dev/null +++ b/tests/src/core/testqgsrasterlayer.cpp @@ -0,0 +1,77 @@ +/*************************************************************************** + testqgsvectorfilewriter.cpp + -------------------------------------- + Date : Sun Sep 16 12:22:54 AKDT 2007 + Copyright : (C) 2007 by Gary E. Sherman + Email : sherman at mrcc 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 +#include +#include +#include +#include +#include +#include +#include +#include + +//qgis includes... +#include +#include + +/** \ingroup UnitTests + * This is a unit test for the QgsRasterLayer class. + */ +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 init(){};// will be called before each testfunction is executed. + void cleanup(){};// will be called after every testfunction. + + void isValid(); + + private: + QgsRasterLayer * mpLayer; +}; + +void TestQgsRasterLayer::initTestCase() +{ + // init QGIS's paths - true means that all path will be inited from prefix + QString qgisPath = QCoreApplication::applicationDirPath (); + QgsApplication::setPrefixPath(qgisPath, TRUE); +#ifdef Q_OS_LINUX + QgsApplication::setPkgDataPath(qgisPath + "/../share/qgis"); +#endif + //create some objects that will be used in all tests... + + std::cout << "Prefix PATH: " << QgsApplication::prefixPath().toLocal8Bit().data() << std::endl; + std::cout << "Plugin PATH: " << QgsApplication::pluginPath().toLocal8Bit().data() << std::endl; + std::cout << "PkgData PATH: " << QgsApplication::pkgDataPath().toLocal8Bit().data() << std::endl; + std::cout << "User DB PATH: " << QgsApplication::qgisUserDbFilePath().toLocal8Bit().data() << std::endl; + + //create a raster layer that will be used in all tests... + QString myFileName (TEST_DATA_DIR); //defined in CmakeLists.txt + myFileName = myFileName + QDir::separator() + "tenbytenraster.asc"; + QFileInfo myRasterFileInfo ( myFileName ); + mpLayer = new QgsRasterLayer ( myRasterFileInfo.filePath(), + myRasterFileInfo.completeBaseName() ); +} + +void TestQgsRasterLayer::isValid() +{ + QVERIFY ( mpLayer->isValid() ); +} + +QTEST_MAIN(TestQgsRasterLayer) +#include "moc_testqgsrasterlayer.cxx" + diff --git a/tests/testdata/tenbytenraster.asc b/tests/testdata/tenbytenraster.asc new file mode 100644 index 00000000000..c2bce57dc89 --- /dev/null +++ b/tests/testdata/tenbytenraster.asc @@ -0,0 +1,19 @@ +NCOLS 10 +NROWS 10 +XLLCENTER 1535380.000000 +YLLCENTER 5083260.000000 +DX 10 +DY 10 +NODATA_VALUE -9999 +0 1 2 3 4 5 6 7 8 9 +0 1 2 3 4 5 6 7 8 9 +0 1 2 3 4 5 6 7 8 9 +0 1 2 3 4 5 6 7 8 9 +0 1 2 3 4 5 6 7 8 9 +0 1 2 3 4 5 6 7 8 9 +0 1 2 3 4 5 6 7 8 9 +0 1 2 3 4 5 6 7 8 9 +0 1 2 3 4 5 6 7 8 9 +0 1 2 3 4 5 6 7 8 9 +PROJECTION +NOTES