Skip to content
Permalink
Browse files

[GRASS] test case

  • Loading branch information
blazek committed Apr 9, 2015
1 parent 10a51f6 commit 7c419bf26902fe5253737fb112ac7d909784efad
Showing with 413 additions and 6 deletions.
  1. +4 −1 INSTALL
  2. +6 −0 src/plugins/grass/locations.gml
  3. +46 −5 tests/src/providers/CMakeLists.txt
  4. +146 −0 tests/src/providers/testqgsgrassprovider.cpp
  5. +18 −0 tests/testdata/grass/wgs84/PERMANENT/DEFAULT_WIND
  6. +6 −0 tests/testdata/grass/wgs84/PERMANENT/PROJ_INFO
  7. +3 −0 tests/testdata/grass/wgs84/PERMANENT/PROJ_UNITS
  8. +18 −0 tests/testdata/grass/wgs84/PERMANENT/WIND
  9. +18 −0 tests/testdata/grass/wgs84/test/WIND
  10. +4 −0 tests/testdata/grass/wgs84/test/cats/cell
  11. +4 −0 tests/testdata/grass/wgs84/test/cats/dcell
  12. +4 −0 tests/testdata/grass/wgs84/test/cats/fcell
  13. BIN tests/testdata/grass/wgs84/test/cell/cell
  14. 0 tests/testdata/grass/wgs84/test/cell/dcell
  15. 0 tests/testdata/grass/wgs84/test/cell/fcell
  16. BIN tests/testdata/grass/wgs84/test/cell_misc/cell/null
  17. +1 −0 tests/testdata/grass/wgs84/test/cell_misc/cell/range
  18. +3 −0 tests/testdata/grass/wgs84/test/cell_misc/dcell/f_format
  19. +1 −0 tests/testdata/grass/wgs84/test/cell_misc/dcell/f_quant
  20. BIN tests/testdata/grass/wgs84/test/cell_misc/dcell/f_range
  21. BIN tests/testdata/grass/wgs84/test/cell_misc/dcell/null
  22. +3 −0 tests/testdata/grass/wgs84/test/cell_misc/fcell/f_format
  23. +1 −0 tests/testdata/grass/wgs84/test/cell_misc/fcell/f_quant
  24. BIN tests/testdata/grass/wgs84/test/cell_misc/fcell/f_range
  25. BIN tests/testdata/grass/wgs84/test/cell_misc/fcell/null
  26. +12 −0 tests/testdata/grass/wgs84/test/cellhd/cell
  27. +12 −0 tests/testdata/grass/wgs84/test/cellhd/dcell
  28. +12 −0 tests/testdata/grass/wgs84/test/cellhd/fcell
  29. BIN tests/testdata/grass/wgs84/test/fcell/dcell
  30. BIN tests/testdata/grass/wgs84/test/fcell/fcell
  31. +9 −0 tests/testdata/grass/wgs84/test/hist/cell
  32. +9 −0 tests/testdata/grass/wgs84/test/hist/dcell
  33. +9 −0 tests/testdata/grass/wgs84/test/hist/fcell
  34. +2 −0 tests/testdata/grass/wgs84/test6/VAR
  35. +18 −0 tests/testdata/grass/wgs84/test6/WIND
  36. BIN tests/testdata/grass/wgs84/test6/dbf/test_1.dbf
  37. BIN tests/testdata/grass/wgs84/test6/dbf/test_2.dbf
  38. BIN tests/testdata/grass/wgs84/test6/dbf/test_3.dbf
  39. BIN tests/testdata/grass/wgs84/test6/vector/test/cidx
  40. BIN tests/testdata/grass/wgs84/test6/vector/test/coor
  41. +3 −0 tests/testdata/grass/wgs84/test6/vector/test/dbln
  42. +9 −0 tests/testdata/grass/wgs84/test6/vector/test/head
  43. 0 tests/testdata/grass/wgs84/test6/vector/test/hist
  44. BIN tests/testdata/grass/wgs84/test6/vector/test/topo
  45. +2 −0 tests/testdata/grass/wgs84/test7/VAR
  46. +18 −0 tests/testdata/grass/wgs84/test7/WIND
  47. BIN tests/testdata/grass/wgs84/test7/sqlite/sqlite.db
  48. BIN tests/testdata/grass/wgs84/test7/vector/test/cidx
  49. BIN tests/testdata/grass/wgs84/test7/vector/test/coor
  50. +3 −0 tests/testdata/grass/wgs84/test7/vector/test/dbln
  51. +9 −0 tests/testdata/grass/wgs84/test7/vector/test/head
  52. 0 tests/testdata/grass/wgs84/test7/vector/test/hist
  53. BIN tests/testdata/grass/wgs84/test7/vector/test/sidx
  54. BIN tests/testdata/grass/wgs84/test7/vector/test/topo
@@ -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
@@ -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>
@@ -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

@@ -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)

#############################################################
@@ -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)
@@ -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"
@@ -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
@@ -0,0 +1,6 @@
name: Lat/Lon
proj: ll
datum: wgs84
ellps: wgs84
towgs84: 0,0,0,0,0,0,0
no_defs: defined
@@ -0,0 +1,3 @@
unit: degree
units: degrees
meters: 1.0
@@ -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
@@ -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
@@ -0,0 +1,4 @@
# 0 categories


0.00 0.00 0.00 0.00
@@ -0,0 +1,4 @@
# 0 categories


0.00 0.00 0.00 0.00
@@ -0,0 +1,4 @@
# 0 categories


0.00 0.00 0.00 0.00
Binary file not shown.
No changes.
No changes.
Binary file not shown.
@@ -0,0 +1 @@
-20 20
@@ -0,0 +1,3 @@
type: double
byte_order: xdr
lzw_compression_bits: -1
@@ -0,0 +1 @@
round
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
type: float
byte_order: xdr
lzw_compression_bits: -1
@@ -0,0 +1 @@
round
Binary file not shown.
Binary file not shown.
@@ -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
@@ -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
@@ -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 not shown.
Binary file not shown.
@@ -0,0 +1,9 @@
Wed Apr 8 12:02:01 2015
cell
test
radim
raster


generated by r.mapcalc
int(x() * y())
@@ -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.
You can’t perform that action at this time.