Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[GRASS] test case
  • Loading branch information
blazek committed Apr 9, 2015
1 parent 10a51f6 commit 7c419bf
Show file tree
Hide file tree
Showing 54 changed files with 413 additions and 6 deletions.
5 changes: 4 additions & 1 deletion INSTALL
Expand Up @@ -108,7 +108,10 @@ Required build dependencies:

Optional dependencies:

- for GRASS plugin - GRASS >= 6.0.0 (libraries compiled with exceptions support on Linux 32bit)
- for GRASS providers and plugin - GRASS >= 6.0.0. QGIS may be compiled with GRASS 6 or GRASS 7.
It can also be compiled with both GRASS versions in a single build but only if QGIS
is not installed with rpath. The desired GRASS version is choosen on runtime by setting
LD_LIBRARY_PATH or PATH.
- for georeferencer - GSL >= 1.8
- for postgis support and SPIT plugin - PostgreSQL >= 8.0.x
- for gps plugin - gpsbabel
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/grass/locations.gml
Expand Up @@ -1088,6 +1088,12 @@
<gml:coordinates>-17.23,20.87 -8.01,28</gml:coordinates>
</gml:Envelope>
</gml:featureMember>
<gml:featureMember>
<gml:name>World</gml:name>
<gml:Envelope>
<gml:coordinates>-180,-90 180,90</gml:coordinates>
</gml:Envelope>
</gml:featureMember>
<gml:featureMember>
<gml:name>Yemen</gml:name>
<gml:Envelope>
Expand Down
51 changes: 46 additions & 5 deletions tests/src/providers/CMakeLists.txt
Expand Up @@ -23,11 +23,6 @@ ADD_DEFINITIONS(-DTEST_DATA_DIR="\\"${TEST_DATA_DIR}\\"")

ADD_DEFINITIONS(-DINSTALL_PREFIX="\\"${CMAKE_INSTALL_PREFIX}\\"")

# Temporarily set to old version until server is reconfigured
#SET(TEST_SERVER_URL "http://wcs.qgis.org/${COMPLETE_VERSION}")
SET(TEST_SERVER_URL "http://wcs.qgis.org/1.9.0")
ADD_DEFINITIONS(-DTEST_SERVER_URL="\\"${TEST_SERVER_URL}\\"")

#############################################################
# libraries

Expand Down Expand Up @@ -74,6 +69,14 @@ ENDMACRO (ADD_QGIS_TEST)
# Tests:

ADD_QGIS_TEST(wcsprovidertest testqgswcsprovider.cpp)
# Temporarily set to old version until server is reconfigured
#SET(TEST_SERVER_URL "http://wcs.qgis.org/${COMPLETE_VERSION}")
SET(TEST_SERVER_URL "http://wcs.qgis.org/1.9.0")
#ADD_DEFINITIONS(-DTEST_SERVER_URL="\\"${TEST_SERVER_URL}\\"")
SET_TARGET_PROPERTIES(qgis_wcsprovidertest PROPERTIES
COMPILE_FLAGS "-DTEST_SERVER_URL=\\\"${TEST_SERVER_URL}\\\""
)

ADD_QGIS_TEST(gdalprovidertest testqgsgdalprovider.cpp)

#############################################################
Expand Down Expand Up @@ -118,3 +121,41 @@ IF(UNIX AND NOT ANDROID AND CMAKE_BUILD_TYPE MATCHES Debug)
INSTALL(FILES wcs-servers.json DESTINATION ${QGIS_DATA_DIR}/resources)

ENDIF(UNIX AND NOT ANDROID AND CMAKE_BUILD_TYPE MATCHES Debug)

########################### GRASS ##################################
ADD_DEFINITIONS("-DGRASS_EXPORT=${DLLIMPORT} -DGRASS_LIB_EXPORT=${DLLIMPORT}")
MACRO (ADD_QGIS_GRASS_TEST grass_build_version testname testsrc)
SET(qgis_${testname}${grass_build_version}_SRCS ${testsrc} ${util_SRCS})
ADD_CUSTOM_TARGET(qgis_${testname}${grass_build_version}moc ALL DEPENDS ${qgis_${testname}${grass_build_version}_MOC_SRCS})
ADD_EXECUTABLE(qgis_${testname}${grass_build_version} ${qgis_${testname}${grass_build_version}_SRCS})

GET_PROPERTY(INCLUDE_DIRECTORIES DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
LIST(APPEND INCLUDE_DIRECTORIES
${GRASS_INCLUDE_DIR${grass_build_version}}
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/providers/grass
)

SET_TARGET_PROPERTIES(qgis_${testname}${grass_build_version} PROPERTIES
AUTOMOC TRUE
INCLUDE_DIRECTORIES "${INCLUDE_DIRECTORIES}"
COMPILE_FLAGS "-DGRASS_BASE=\\\"${GRASS_PREFIX${grass_build_version}}\\\" \"-DGRASS_BUILD_VERSION=${grass_build_version}\""
)
TARGET_LINK_LIBRARIES(qgis_${testname}${grass_build_version}
${QT_QTXML_LIBRARY}
${QT_QTCORE_LIBRARY}
${QT_QTSVG_LIBRARY}
${QT_QTTEST_LIBRARY}
${PROJ_LIBRARY}
${GEOS_LIBRARY}
${GDAL_LIBRARY}
qgis_core
qgisgrass${GRASS_BUILD_VERSION}
)
ADD_TEST(qgis_${testname}${grass_build_version} ${CMAKE_CURRENT_BINARY_DIR}/../../../output/bin/qgis_${testname}${grass_build_version})
ENDMACRO (ADD_QGIS_GRASS_TEST)

FOREACH(GRASS_BUILD_VERSION 6 7)
IF(GRASS_FOUND${GRASS_BUILD_VERSION})
ADD_QGIS_GRASS_TEST(${GRASS_BUILD_VERSION} grassprovidertest testqgsgrassprovider.cpp)
ENDIF(GRASS_FOUND${GRASS_BUILD_VERSION})
ENDFOREACH(GRASS_BUILD_VERSION 6 7)
146 changes: 146 additions & 0 deletions tests/src/providers/testqgsgrassprovider.cpp
@@ -0,0 +1,146 @@
/***************************************************************************
testqgsgrassprovider.cpp
--------------------------------------
Date : April 2015
Copyright : (C) 2015 by Radim Blazek
Email : radim dot blazek at gmail 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 <cmath>

#include <QApplication>
#include <QObject>
#include <QObject>
#include <QString>
#include <QStringList>
#include <QtTest/QtTest>

#include <qgsapplication.h>
#include <qgsgrass.h>
#include <qgsproviderregistry.h>
#include <qgsvectordataprovider.h>

extern "C"
{
#ifndef _MSC_VER
#include <unistd.h>
#endif
#include <grass/version.h>
}

#define TINY_VALUE std::numeric_limits<double>::epsilon() * 20

/** \ingroup UnitTests
* This is a unit test for the QgsRasterLayer class.
*/
class TestQgsGrassProvider: 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 vectorLayers();
private:
void reportRow(QString message);
QString mGisdbase;
QString mLocation;
QString mReport;
};


void TestQgsGrassProvider::reportRow(QString message)
{
mReport += message + "<br>";
}

//runs before all tests
void TestQgsGrassProvider::initTestCase()
{
// init QGIS's paths - true means that all path will be inited from prefix
QgsApplication::init();
// QgsApplication::initQgis() calls QgsProviderRegistry::instance() which registers providers.
// Because providers are linked in build directory with rpath, it will also try to load GRASS providers
// in version different form which we are testing here so it loads also GRASS libs in different version
// and it results in segfault when __do_global_dtors_aux() is called.
// => we must not call QgsApplication::initQgis()
//QgsApplication::initQgis();
QString mySettings = QgsApplication::showSettings();
mySettings = mySettings.replace( "\n", "<br />" );
mReport += QString("<h1>GRASS %1 provider tests</h1>\n").arg( GRASS_BUILD_VERSION );
mReport += "<p>" + mySettings + "</p>";

QgsGrass::init();

//create some objects that will be used in all tests...
//create a raster layer that will be used in all tests...
mGisdbase = QString( TEST_DATA_DIR ) + "/grass";
mLocation = "wgs84";
reportRow( "mGisdbase: " + mGisdbase );
reportRow( "mLocation: " + mLocation );
qDebug() << "mGisdbase = " << mGisdbase << " mLocation = " << mLocation;
}

//runs after all tests
void TestQgsGrassProvider::cleanupTestCase()
{
QString myReportFile = QDir::tempPath() + "/qgistest.html";
QFile myFile( myReportFile );
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
{
QTextStream myQTextStream( &myFile );
myQTextStream << mReport;
myFile.close();
}

//QgsApplication::exitQgis();
}

void TestQgsGrassProvider::vectorLayers()
{
QString mapset = QString("test%1").arg( GRASS_BUILD_VERSION );
QString mapName = "test";
QStringList expectedLayers;
expectedLayers << "1_point" << "2_line" << "3_polygon";

reportRow("");
reportRow("QgsGrass::vectorLayers test");
reportRow("mapset: " + mapset);
reportRow("mapName: " + mapName);
reportRow("expectedLayers: " + expectedLayers.join(", "));

bool ok = true;
G_TRY
{
QStringList layers = QgsGrass::vectorLayers(mGisdbase, mLocation, mapset, mapName);
reportRow("layers:" + layers.join(", "));

foreach( QString expectedLayer, expectedLayers)
{
if ( !layers.contains(expectedLayer) )
{
ok = false;
reportRow("ERROR: expected layer '" + expectedLayer + "' missing");
}
}
}
G_CATCH( QgsGrass::Exception &e )
{
ok = false;
reportRow( QString("ERROR: %1").arg(e.what()) );
}

QVERIFY( ok );
reportRow("OK");
}

QTEST_MAIN( TestQgsGrassProvider )
#include "testqgsgrassprovider.moc"
18 changes: 18 additions & 0 deletions tests/testdata/grass/wgs84/PERMANENT/DEFAULT_WIND
@@ -0,0 +1,18 @@
proj: 3
zone: 0
north: 90N
south: 90S
east: 180E
west: 180W
cols: 1000
rows: 500
e-w resol: 0:21:36
n-s resol: 0:21:36
top: 1.000000000000000
bottom: 0.000000000000000
cols3: 10000
rows3: 5000
depths: 1
e-w resol3: 0:02:09.6
n-s resol3: 0:02:09.6
t-b resol: 1
6 changes: 6 additions & 0 deletions tests/testdata/grass/wgs84/PERMANENT/PROJ_INFO
@@ -0,0 +1,6 @@
name: Lat/Lon
proj: ll
datum: wgs84
ellps: wgs84
towgs84: 0,0,0,0,0,0,0
no_defs: defined
3 changes: 3 additions & 0 deletions tests/testdata/grass/wgs84/PERMANENT/PROJ_UNITS
@@ -0,0 +1,3 @@
unit: degree
units: degrees
meters: 1.0
18 changes: 18 additions & 0 deletions tests/testdata/grass/wgs84/PERMANENT/WIND
@@ -0,0 +1,18 @@
proj: 3
zone: 0
north: 90N
south: 90S
east: 180E
west: 180W
cols: 1000
rows: 500
e-w resol: 0:21:36
n-s resol: 0:21:36
top: 1.000000000000000
bottom: 0.000000000000000
cols3: 10000
rows3: 5000
depths: 1
e-w resol3: 0:02:09.6
n-s resol3: 0:02:09.6
t-b resol: 1
18 changes: 18 additions & 0 deletions tests/testdata/grass/wgs84/test/WIND
@@ -0,0 +1,18 @@
proj: 3
zone: 0
north: 5N
south: 5S
east: 5E
west: 5W
cols: 10
rows: 10
e-w resol: 1
n-s resol: 1
top: 1.000000000000000
bottom: 0.000000000000000
cols3: 278
rows3: 278
depths: 1
e-w resol3: 0:02:09.496403
n-s resol3: 0:02:09.496403
t-b resol: 1
4 changes: 4 additions & 0 deletions tests/testdata/grass/wgs84/test/cats/cell
@@ -0,0 +1,4 @@
# 0 categories


0.00 0.00 0.00 0.00
4 changes: 4 additions & 0 deletions tests/testdata/grass/wgs84/test/cats/dcell
@@ -0,0 +1,4 @@
# 0 categories


0.00 0.00 0.00 0.00
4 changes: 4 additions & 0 deletions tests/testdata/grass/wgs84/test/cats/fcell
@@ -0,0 +1,4 @@
# 0 categories


0.00 0.00 0.00 0.00
Binary file added tests/testdata/grass/wgs84/test/cell/cell
Binary file not shown.
Empty file.
Empty file.
Binary file added tests/testdata/grass/wgs84/test/cell_misc/cell/null
Binary file not shown.
1 change: 1 addition & 0 deletions tests/testdata/grass/wgs84/test/cell_misc/cell/range
@@ -0,0 +1 @@
-20 20
3 changes: 3 additions & 0 deletions tests/testdata/grass/wgs84/test/cell_misc/dcell/f_format
@@ -0,0 +1,3 @@
type: double
byte_order: xdr
lzw_compression_bits: -1
1 change: 1 addition & 0 deletions tests/testdata/grass/wgs84/test/cell_misc/dcell/f_quant
@@ -0,0 +1 @@
round
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions tests/testdata/grass/wgs84/test/cell_misc/fcell/f_format
@@ -0,0 +1,3 @@
type: float
byte_order: xdr
lzw_compression_bits: -1
1 change: 1 addition & 0 deletions tests/testdata/grass/wgs84/test/cell_misc/fcell/f_quant
@@ -0,0 +1 @@
round
Binary file not shown.
Binary file not shown.
12 changes: 12 additions & 0 deletions tests/testdata/grass/wgs84/test/cellhd/cell
@@ -0,0 +1,12 @@
proj: 3
zone: 0
north: 5N
south: 5S
east: 5E
west: 5W
cols: 10
rows: 10
e-w resol: 1
n-s resol: 1
format: 3
compressed: 2
12 changes: 12 additions & 0 deletions tests/testdata/grass/wgs84/test/cellhd/dcell
@@ -0,0 +1,12 @@
proj: 3
zone: 0
north: 5N
south: 5S
east: 5E
west: 5W
cols: 10
rows: 10
e-w resol: 1
n-s resol: 1
format: -1
compressed: 2
12 changes: 12 additions & 0 deletions tests/testdata/grass/wgs84/test/cellhd/fcell
@@ -0,0 +1,12 @@
proj: 3
zone: 0
north: 5N
south: 5S
east: 5E
west: 5W
cols: 10
rows: 10
e-w resol: 1
n-s resol: 1
format: -1
compressed: 2
Binary file added tests/testdata/grass/wgs84/test/fcell/dcell
Binary file not shown.
Binary file added tests/testdata/grass/wgs84/test/fcell/fcell
Binary file not shown.
9 changes: 9 additions & 0 deletions tests/testdata/grass/wgs84/test/hist/cell
@@ -0,0 +1,9 @@
Wed Apr 8 12:02:01 2015
cell
test
radim
raster


generated by r.mapcalc
int(x() * y())
9 changes: 9 additions & 0 deletions tests/testdata/grass/wgs84/test/hist/dcell
@@ -0,0 +1,9 @@
Wed Apr 8 12:02:26 2015
dcell
test
radim
raster


generated by r.mapcalc
x() * y()

0 comments on commit 7c419bf

Please sign in to comment.