Skip to content

Commit 7c419bf

Browse files
committed
[GRASS] test case
1 parent 10a51f6 commit 7c419bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+413
-6
lines changed

INSTALL

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ Required build dependencies:
108108

109109
Optional dependencies:
110110

111-
- for GRASS plugin - GRASS >= 6.0.0 (libraries compiled with exceptions support on Linux 32bit)
111+
- for GRASS providers and plugin - GRASS >= 6.0.0. QGIS may be compiled with GRASS 6 or GRASS 7.
112+
It can also be compiled with both GRASS versions in a single build but only if QGIS
113+
is not installed with rpath. The desired GRASS version is choosen on runtime by setting
114+
LD_LIBRARY_PATH or PATH.
112115
- for georeferencer - GSL >= 1.8
113116
- for postgis support and SPIT plugin - PostgreSQL >= 8.0.x
114117
- for gps plugin - gpsbabel

src/plugins/grass/locations.gml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,12 @@
10881088
<gml:coordinates>-17.23,20.87 -8.01,28</gml:coordinates>
10891089
</gml:Envelope>
10901090
</gml:featureMember>
1091+
<gml:featureMember>
1092+
<gml:name>World</gml:name>
1093+
<gml:Envelope>
1094+
<gml:coordinates>-180,-90 180,90</gml:coordinates>
1095+
</gml:Envelope>
1096+
</gml:featureMember>
10911097
<gml:featureMember>
10921098
<gml:name>Yemen</gml:name>
10931099
<gml:Envelope>

tests/src/providers/CMakeLists.txt

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ ADD_DEFINITIONS(-DTEST_DATA_DIR="\\"${TEST_DATA_DIR}\\"")
2323
2424
ADD_DEFINITIONS(-DINSTALL_PREFIX="\\"${CMAKE_INSTALL_PREFIX}\\"")
2525
26-
# Temporarily set to old version until server is reconfigured
27-
#SET(TEST_SERVER_URL "http://wcs.qgis.org/${COMPLETE_VERSION}")
28-
SET(TEST_SERVER_URL "http://wcs.qgis.org/1.9.0")
29-
ADD_DEFINITIONS(-DTEST_SERVER_URL="\\"${TEST_SERVER_URL}\\"")
30-
3126
#############################################################
3227
# libraries
3328
@@ -74,6 +69,14 @@ ENDMACRO (ADD_QGIS_TEST)
7469
# Tests:
7570
7671
ADD_QGIS_TEST(wcsprovidertest testqgswcsprovider.cpp)
72+
# Temporarily set to old version until server is reconfigured
73+
#SET(TEST_SERVER_URL "http://wcs.qgis.org/${COMPLETE_VERSION}")
74+
SET(TEST_SERVER_URL "http://wcs.qgis.org/1.9.0")
75+
#ADD_DEFINITIONS(-DTEST_SERVER_URL="\\"${TEST_SERVER_URL}\\"")
76+
SET_TARGET_PROPERTIES(qgis_wcsprovidertest PROPERTIES
77+
COMPILE_FLAGS "-DTEST_SERVER_URL=\\\"${TEST_SERVER_URL}\\\""
78+
)
79+
7780
ADD_QGIS_TEST(gdalprovidertest testqgsgdalprovider.cpp)
7881
7982
#############################################################
@@ -118,3 +121,41 @@ IF(UNIX AND NOT ANDROID AND CMAKE_BUILD_TYPE MATCHES Debug)
118121
INSTALL(FILES wcs-servers.json DESTINATION ${QGIS_DATA_DIR}/resources)
119122
120123
ENDIF(UNIX AND NOT ANDROID AND CMAKE_BUILD_TYPE MATCHES Debug)
124+
125+
########################### GRASS ##################################
126+
ADD_DEFINITIONS("-DGRASS_EXPORT=${DLLIMPORT} -DGRASS_LIB_EXPORT=${DLLIMPORT}")
127+
MACRO (ADD_QGIS_GRASS_TEST grass_build_version testname testsrc)
128+
SET(qgis_${testname}${grass_build_version}_SRCS ${testsrc} ${util_SRCS})
129+
ADD_CUSTOM_TARGET(qgis_${testname}${grass_build_version}moc ALL DEPENDS ${qgis_${testname}${grass_build_version}_MOC_SRCS})
130+
ADD_EXECUTABLE(qgis_${testname}${grass_build_version} ${qgis_${testname}${grass_build_version}_SRCS})
131+
132+
GET_PROPERTY(INCLUDE_DIRECTORIES DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
133+
LIST(APPEND INCLUDE_DIRECTORIES
134+
${GRASS_INCLUDE_DIR${grass_build_version}}
135+
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/providers/grass
136+
)
137+
138+
SET_TARGET_PROPERTIES(qgis_${testname}${grass_build_version} PROPERTIES
139+
AUTOMOC TRUE
140+
INCLUDE_DIRECTORIES "${INCLUDE_DIRECTORIES}"
141+
COMPILE_FLAGS "-DGRASS_BASE=\\\"${GRASS_PREFIX${grass_build_version}}\\\" \"-DGRASS_BUILD_VERSION=${grass_build_version}\""
142+
)
143+
TARGET_LINK_LIBRARIES(qgis_${testname}${grass_build_version}
144+
${QT_QTXML_LIBRARY}
145+
${QT_QTCORE_LIBRARY}
146+
${QT_QTSVG_LIBRARY}
147+
${QT_QTTEST_LIBRARY}
148+
${PROJ_LIBRARY}
149+
${GEOS_LIBRARY}
150+
${GDAL_LIBRARY}
151+
qgis_core
152+
qgisgrass${GRASS_BUILD_VERSION}
153+
)
154+
ADD_TEST(qgis_${testname}${grass_build_version} ${CMAKE_CURRENT_BINARY_DIR}/../../../output/bin/qgis_${testname}${grass_build_version})
155+
ENDMACRO (ADD_QGIS_GRASS_TEST)
156+
157+
FOREACH(GRASS_BUILD_VERSION 6 7)
158+
IF(GRASS_FOUND${GRASS_BUILD_VERSION})
159+
ADD_QGIS_GRASS_TEST(${GRASS_BUILD_VERSION} grassprovidertest testqgsgrassprovider.cpp)
160+
ENDIF(GRASS_FOUND${GRASS_BUILD_VERSION})
161+
ENDFOREACH(GRASS_BUILD_VERSION 6 7)
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/***************************************************************************
2+
testqgsgrassprovider.cpp
3+
--------------------------------------
4+
Date : April 2015
5+
Copyright : (C) 2015 by Radim Blazek
6+
Email : radim dot blazek at gmail 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 <cmath>
16+
17+
#include <QApplication>
18+
#include <QObject>
19+
#include <QObject>
20+
#include <QString>
21+
#include <QStringList>
22+
#include <QtTest/QtTest>
23+
24+
#include <qgsapplication.h>
25+
#include <qgsgrass.h>
26+
#include <qgsproviderregistry.h>
27+
#include <qgsvectordataprovider.h>
28+
29+
extern "C"
30+
{
31+
#ifndef _MSC_VER
32+
#include <unistd.h>
33+
#endif
34+
#include <grass/version.h>
35+
}
36+
37+
#define TINY_VALUE std::numeric_limits<double>::epsilon() * 20
38+
39+
/** \ingroup UnitTests
40+
* This is a unit test for the QgsRasterLayer class.
41+
*/
42+
class TestQgsGrassProvider: public QObject
43+
{
44+
Q_OBJECT
45+
private slots:
46+
void initTestCase();// will be called before the first testfunction is executed.
47+
void cleanupTestCase();// will be called after the last testfunction was executed.
48+
void init() {};// will be called before each testfunction is executed.
49+
void cleanup() {};// will be called after every testfunction.
50+
51+
void vectorLayers();
52+
private:
53+
void reportRow(QString message);
54+
QString mGisdbase;
55+
QString mLocation;
56+
QString mReport;
57+
};
58+
59+
60+
void TestQgsGrassProvider::reportRow(QString message)
61+
{
62+
mReport += message + "<br>";
63+
}
64+
65+
//runs before all tests
66+
void TestQgsGrassProvider::initTestCase()
67+
{
68+
// init QGIS's paths - true means that all path will be inited from prefix
69+
QgsApplication::init();
70+
// QgsApplication::initQgis() calls QgsProviderRegistry::instance() which registers providers.
71+
// Because providers are linked in build directory with rpath, it will also try to load GRASS providers
72+
// in version different form which we are testing here so it loads also GRASS libs in different version
73+
// and it results in segfault when __do_global_dtors_aux() is called.
74+
// => we must not call QgsApplication::initQgis()
75+
//QgsApplication::initQgis();
76+
QString mySettings = QgsApplication::showSettings();
77+
mySettings = mySettings.replace( "\n", "<br />" );
78+
mReport += QString("<h1>GRASS %1 provider tests</h1>\n").arg( GRASS_BUILD_VERSION );
79+
mReport += "<p>" + mySettings + "</p>";
80+
81+
QgsGrass::init();
82+
83+
//create some objects that will be used in all tests...
84+
//create a raster layer that will be used in all tests...
85+
mGisdbase = QString( TEST_DATA_DIR ) + "/grass";
86+
mLocation = "wgs84";
87+
reportRow( "mGisdbase: " + mGisdbase );
88+
reportRow( "mLocation: " + mLocation );
89+
qDebug() << "mGisdbase = " << mGisdbase << " mLocation = " << mLocation;
90+
}
91+
92+
//runs after all tests
93+
void TestQgsGrassProvider::cleanupTestCase()
94+
{
95+
QString myReportFile = QDir::tempPath() + "/qgistest.html";
96+
QFile myFile( myReportFile );
97+
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
98+
{
99+
QTextStream myQTextStream( &myFile );
100+
myQTextStream << mReport;
101+
myFile.close();
102+
}
103+
104+
//QgsApplication::exitQgis();
105+
}
106+
107+
void TestQgsGrassProvider::vectorLayers()
108+
{
109+
QString mapset = QString("test%1").arg( GRASS_BUILD_VERSION );
110+
QString mapName = "test";
111+
QStringList expectedLayers;
112+
expectedLayers << "1_point" << "2_line" << "3_polygon";
113+
114+
reportRow("");
115+
reportRow("QgsGrass::vectorLayers test");
116+
reportRow("mapset: " + mapset);
117+
reportRow("mapName: " + mapName);
118+
reportRow("expectedLayers: " + expectedLayers.join(", "));
119+
120+
bool ok = true;
121+
G_TRY
122+
{
123+
QStringList layers = QgsGrass::vectorLayers(mGisdbase, mLocation, mapset, mapName);
124+
reportRow("layers:" + layers.join(", "));
125+
126+
foreach( QString expectedLayer, expectedLayers)
127+
{
128+
if ( !layers.contains(expectedLayer) )
129+
{
130+
ok = false;
131+
reportRow("ERROR: expected layer '" + expectedLayer + "' missing");
132+
}
133+
}
134+
}
135+
G_CATCH( QgsGrass::Exception &e )
136+
{
137+
ok = false;
138+
reportRow( QString("ERROR: %1").arg(e.what()) );
139+
}
140+
141+
QVERIFY( ok );
142+
reportRow("OK");
143+
}
144+
145+
QTEST_MAIN( TestQgsGrassProvider )
146+
#include "testqgsgrassprovider.moc"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
proj: 3
2+
zone: 0
3+
north: 90N
4+
south: 90S
5+
east: 180E
6+
west: 180W
7+
cols: 1000
8+
rows: 500
9+
e-w resol: 0:21:36
10+
n-s resol: 0:21:36
11+
top: 1.000000000000000
12+
bottom: 0.000000000000000
13+
cols3: 10000
14+
rows3: 5000
15+
depths: 1
16+
e-w resol3: 0:02:09.6
17+
n-s resol3: 0:02:09.6
18+
t-b resol: 1
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: Lat/Lon
2+
proj: ll
3+
datum: wgs84
4+
ellps: wgs84
5+
towgs84: 0,0,0,0,0,0,0
6+
no_defs: defined
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
unit: degree
2+
units: degrees
3+
meters: 1.0
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
proj: 3
2+
zone: 0
3+
north: 90N
4+
south: 90S
5+
east: 180E
6+
west: 180W
7+
cols: 1000
8+
rows: 500
9+
e-w resol: 0:21:36
10+
n-s resol: 0:21:36
11+
top: 1.000000000000000
12+
bottom: 0.000000000000000
13+
cols3: 10000
14+
rows3: 5000
15+
depths: 1
16+
e-w resol3: 0:02:09.6
17+
n-s resol3: 0:02:09.6
18+
t-b resol: 1

tests/testdata/grass/wgs84/test/WIND

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
proj: 3
2+
zone: 0
3+
north: 5N
4+
south: 5S
5+
east: 5E
6+
west: 5W
7+
cols: 10
8+
rows: 10
9+
e-w resol: 1
10+
n-s resol: 1
11+
top: 1.000000000000000
12+
bottom: 0.000000000000000
13+
cols3: 278
14+
rows3: 278
15+
depths: 1
16+
e-w resol3: 0:02:09.496403
17+
n-s resol3: 0:02:09.496403
18+
t-b resol: 1
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# 0 categories
2+
3+
4+
0.00 0.00 0.00 0.00
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# 0 categories
2+
3+
4+
0.00 0.00 0.00 0.00
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# 0 categories
2+
3+
4+
0.00 0.00 0.00 0.00
417 Bytes
Binary file not shown.

tests/testdata/grass/wgs84/test/cell/dcell

Whitespace-only changes.

tests/testdata/grass/wgs84/test/cell/fcell

Whitespace-only changes.
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-20 20
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type: double
2+
byte_order: xdr
3+
lzw_compression_bits: -1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
round
Binary file not shown.
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type: float
2+
byte_order: xdr
3+
lzw_compression_bits: -1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
round
Binary file not shown.
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
proj: 3
2+
zone: 0
3+
north: 5N
4+
south: 5S
5+
east: 5E
6+
west: 5W
7+
cols: 10
8+
rows: 10
9+
e-w resol: 1
10+
n-s resol: 1
11+
format: 3
12+
compressed: 2
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
proj: 3
2+
zone: 0
3+
north: 5N
4+
south: 5S
5+
east: 5E
6+
west: 5W
7+
cols: 10
8+
rows: 10
9+
e-w resol: 1
10+
n-s resol: 1
11+
format: -1
12+
compressed: 2
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
proj: 3
2+
zone: 0
3+
north: 5N
4+
south: 5S
5+
east: 5E
6+
west: 5W
7+
cols: 10
8+
rows: 10
9+
e-w resol: 1
10+
n-s resol: 1
11+
format: -1
12+
compressed: 2
511 Bytes
Binary file not shown.
494 Bytes
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Wed Apr 8 12:02:01 2015
2+
cell
3+
test
4+
radim
5+
raster
6+
7+
8+
generated by r.mapcalc
9+
int(x() * y())
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Wed Apr 8 12:02:26 2015
2+
dcell
3+
test
4+
radim
5+
raster
6+
7+
8+
generated by r.mapcalc
9+
x() * y()

0 commit comments

Comments
 (0)