Skip to content

Commit bbde2c7

Browse files
author
timlinux
committedNov 23, 2007
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@7649 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 00e26fd commit bbde2c7

File tree

4 files changed

+123
-1
lines changed

4 files changed

+123
-1
lines changed
 

‎CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ IF (HAVE_PYTHON)
275275
ENDIF (HAVE_PYTHON)
276276

277277
IF (ENABLE_TESTS)
278+
#create a variable to specify where our test data is
279+
#so that unit tests can use TEST_DATA_DIR to locate
280+
#the test data. See CMakeLists in test dirs for more info
281+
SET (TEST_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests/testdata")
278282
SUBDIRS(tests)
279283
ENDIF (ENABLE_TESTS)
280284

‎tests/src/core/CMakeLists.txt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
55
${CMAKE_CURRENT_BINARY_DIR}
66
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/core
7+
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/core/raster
78
${QT_INCLUDE_DIR}
89
${GDAL_INCLUDE_DIR}
910
${PROJ_INCLUDE_DIR}
1011
${GEOS_INCLUDE_DIR}
1112
)
1213

13-
# expect that classes are being IMPORTED for the exe
14+
#############################################################
15+
# Compiler defines
16+
17+
# expect that classes are being IMPORTED for the tests
1418
IF (WIN32)
1519
# expect that classes are being imported
1620
# Note: MSVC doesn't like when the macros are quotes
@@ -28,6 +32,11 @@ IF (WIN32)
2832
ENDIF (MSVC)
2933
ENDIF (WIN32)
3034

35+
# This define is used for tests that need to locate the test
36+
# data under tests/testdata in the qgis source tree.
37+
# the TEST_DATA_DIR variable is set in the top level CMakeLists.txt
38+
ADD_DEFINITIONS(-DTEST_DATA_DIR="\\"${TEST_DATA_DIR}\\"")
39+
3140
#############################################################
3241
# libraries
3342

@@ -76,5 +85,18 @@ ADD_DEPENDENCIES(qgis_filewritertest qgis_filewritertestmoc)
7685
TARGET_LINK_LIBRARIES(qgis_filewritertest ${QT_LIBRARIES} qgis_core)
7786
INSTALL(TARGETS qgis_filewritertest RUNTIME DESTINATION ${QGIS_BIN_DIR})
7887
ADD_TEST(qgis_filewritertest ${QGIS_BIN_DIR}/qgis_filewritertest)
88+
#
89+
# QgsRasterLayer test
90+
#
91+
SET(qgis_rasterlayertest_SRCS testqgsrasterlayer.cpp)
92+
SET(qgis_rasterlayertest_MOC_CPPS testqgsrasterlayer.cpp)
93+
QT4_WRAP_CPP(qgis_rasterlayertest_MOC_SRCS ${qgis_rasterlayertest_MOC_CPPS})
94+
ADD_CUSTOM_TARGET(qgis_rasterlayertestmoc ALL DEPENDS ${qgis_rasterlayertest_MOC_SRCS})
95+
ADD_EXECUTABLE(qgis_rasterlayertest ${qgis_rasterlayertest_SRCS})
96+
ADD_DEPENDENCIES(qgis_rasterlayertest qgis_rasterlayertestmoc)
97+
TARGET_LINK_LIBRARIES(qgis_rasterlayertest ${QT_LIBRARIES} qgis_core)
98+
INSTALL(TARGETS qgis_rasterlayertest RUNTIME DESTINATION ${QGIS_BIN_DIR})
99+
ADD_TEST(qgis_rasterlayertest ${QGIS_BIN_DIR}/qgis_rasterlayertest)
100+
79101

80102

‎tests/src/core/testqgsrasterlayer.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/***************************************************************************
2+
testqgsvectorfilewriter.cpp
3+
--------------------------------------
4+
Date : Sun Sep 16 12:22:54 AKDT 2007
5+
Copyright : (C) 2007 by Gary E. Sherman
6+
Email : sherman at mrcc dot com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
#include <QtTest>
16+
#include <QObject>
17+
#include <QString>
18+
#include <QStringList>
19+
#include <QObject>
20+
#include <iostream>
21+
#include <QApplication>
22+
#include <QFileInfo>
23+
#include <QDir>
24+
25+
//qgis includes...
26+
#include <qgsrasterlayer.h>
27+
#include <qgsapplication.h>
28+
29+
/** \ingroup UnitTests
30+
* This is a unit test for the QgsRasterLayer class.
31+
*/
32+
class TestQgsRasterLayer: public QObject
33+
{
34+
Q_OBJECT;
35+
private slots:
36+
void initTestCase();// will be called before the first testfunction is executed.
37+
void cleanupTestCase(){};// will be called after the last testfunction was executed.
38+
void init(){};// will be called before each testfunction is executed.
39+
void cleanup(){};// will be called after every testfunction.
40+
41+
void isValid();
42+
43+
private:
44+
QgsRasterLayer * mpLayer;
45+
};
46+
47+
void TestQgsRasterLayer::initTestCase()
48+
{
49+
// init QGIS's paths - true means that all path will be inited from prefix
50+
QString qgisPath = QCoreApplication::applicationDirPath ();
51+
QgsApplication::setPrefixPath(qgisPath, TRUE);
52+
#ifdef Q_OS_LINUX
53+
QgsApplication::setPkgDataPath(qgisPath + "/../share/qgis");
54+
#endif
55+
//create some objects that will be used in all tests...
56+
57+
std::cout << "Prefix PATH: " << QgsApplication::prefixPath().toLocal8Bit().data() << std::endl;
58+
std::cout << "Plugin PATH: " << QgsApplication::pluginPath().toLocal8Bit().data() << std::endl;
59+
std::cout << "PkgData PATH: " << QgsApplication::pkgDataPath().toLocal8Bit().data() << std::endl;
60+
std::cout << "User DB PATH: " << QgsApplication::qgisUserDbFilePath().toLocal8Bit().data() << std::endl;
61+
62+
//create a raster layer that will be used in all tests...
63+
QString myFileName (TEST_DATA_DIR); //defined in CmakeLists.txt
64+
myFileName = myFileName + QDir::separator() + "tenbytenraster.asc";
65+
QFileInfo myRasterFileInfo ( myFileName );
66+
mpLayer = new QgsRasterLayer ( myRasterFileInfo.filePath(),
67+
myRasterFileInfo.completeBaseName() );
68+
}
69+
70+
void TestQgsRasterLayer::isValid()
71+
{
72+
QVERIFY ( mpLayer->isValid() );
73+
}
74+
75+
QTEST_MAIN(TestQgsRasterLayer)
76+
#include "moc_testqgsrasterlayer.cxx"
77+

‎tests/testdata/tenbytenraster.asc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
NCOLS 10
2+
NROWS 10
3+
XLLCENTER 1535380.000000
4+
YLLCENTER 5083260.000000
5+
DX 10
6+
DY 10
7+
NODATA_VALUE -9999
8+
0 1 2 3 4 5 6 7 8 9
9+
0 1 2 3 4 5 6 7 8 9
10+
0 1 2 3 4 5 6 7 8 9
11+
0 1 2 3 4 5 6 7 8 9
12+
0 1 2 3 4 5 6 7 8 9
13+
0 1 2 3 4 5 6 7 8 9
14+
0 1 2 3 4 5 6 7 8 9
15+
0 1 2 3 4 5 6 7 8 9
16+
0 1 2 3 4 5 6 7 8 9
17+
0 1 2 3 4 5 6 7 8 9
18+
PROJECTION
19+
NOTES

0 commit comments

Comments
 (0)
Please sign in to comment.