Skip to content

Commit cce210c

Browse files
author
timlinux
committed
Initial test for qgsgeometry. At the moment it only does the following:
- creates some test intersecting and non intersecting geometries before each test runs - destroys these after each test runs - performs a simple intersection and non-intersection test Please feel free to add further tests here as you work on qgsgeometry - its very simple to do with the framework I have put in place now... git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8180 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 4858e02 commit cce210c

File tree

2 files changed

+170
-0
lines changed

2 files changed

+170
-0
lines changed

tests/src/core/CMakeLists.txt

+21
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,27 @@ ELSE (APPLE)
191191
INSTALL(TARGETS qgis_maprendertest RUNTIME DESTINATION ${QGIS_BIN_DIR})
192192
ADD_TEST(qgis_maprendertest ${QGIS_BIN_DIR}/qgis_maprendertest)
193193
ENDIF (APPLE)
194+
#
195+
# QgsGeometry test
196+
#
197+
SET(qgis_geometrytest_SRCS testqgsgeometry.cpp ${util_SRCS})
198+
SET(qgis_geometrytest_MOC_CPPS testqgsgeometry.cpp)
199+
QT4_WRAP_CPP(qgis_geometrytest_MOC_SRCS ${qgis_geometrytest_MOC_CPPS})
200+
ADD_CUSTOM_TARGET(qgis_geometrytestmoc ALL DEPENDS ${qgis_geometrytest_MOC_SRCS})
201+
ADD_EXECUTABLE(qgis_geometrytest ${qgis_geometrytest_SRCS})
202+
ADD_DEPENDENCIES(qgis_geometrytest qgis_geometrytestmoc)
203+
TARGET_LINK_LIBRARIES(qgis_geometrytest ${QT_LIBRARIES} qgis_core)
204+
SET_TARGET_PROPERTIES(qgis_geometrytest
205+
PROPERTIES INSTALL_RPATH ${QGIS_LIB_DIR}
206+
INSTALL_RPATH_USE_LINK_PATH true)
207+
IF (APPLE)
208+
# For Mac OS X, the executable must be at the root of the bundle's executable folder
209+
INSTALL(TARGETS qgis_geometrytest RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
210+
ADD_TEST(qgis_geometrytest ${CMAKE_INSTALL_PREFIX}/qgis_geometrytest)
211+
ELSE (APPLE)
212+
INSTALL(TARGETS qgis_geometrytest RUNTIME DESTINATION ${QGIS_BIN_DIR})
213+
ADD_TEST(qgis_geometrytest ${QGIS_BIN_DIR}/qgis_geometrytest)
214+
ENDIF (APPLE)
194215
195216
196217

tests/src/core/testqgsgeometry.cpp

+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/***************************************************************************
2+
testqgsgeometry.cpp
3+
--------------------------------------
4+
Date : 20 Jan 2008
5+
Copyright : (C) 2008 by Tim Sutton
6+
Email : tim @ linfiniti.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 <QApplication>
21+
#include <QFileInfo>
22+
#include <QDir>
23+
#include <QDesktopServices>
24+
25+
#include <iostream>
26+
//qgis includes...
27+
#include <qgsapplication.h>
28+
#include <qgsgeometry.h>
29+
30+
/** \ingroup UnitTests
31+
* This is a unit test for the different geometry operations on vector features.
32+
*/
33+
class TestQgsGeometry: public QObject
34+
{
35+
Q_OBJECT;
36+
private slots:
37+
QString getQgisPath(); // Gets the path to QGIS installation
38+
void initTestCase();// will be called before the first testfunction is executed.
39+
void cleanupTestCase();// will be called after the last testfunction was executed.
40+
void init();// will be called before each testfunction is executed.
41+
void cleanup();// will be called after every testfunction.
42+
43+
void intersectionCheck();
44+
private:
45+
QgsPoint mPoint1; /* +1 +A */
46+
QgsPoint mPoint2; /* / \ / \ */
47+
QgsPoint mPoint3; /* / X \ */
48+
QgsPoint mPointA; /* 2+---/-+3 \ */
49+
QgsPoint mPointB; /* B+-------+C */
50+
QgsPoint mPointC; /* */
51+
QgsPoint mPointD; /* +D */
52+
QgsPolyline mPolylineA;
53+
QgsPolyline mPolylineB;
54+
QgsPolyline mPolylineC;
55+
QgsPolygon mPolygonA;
56+
QgsPolygon mPolygonB;
57+
QgsPolygon mPolygonC;
58+
QgsGeometry * mpPolygonGeometryA;
59+
QgsGeometry * mpPolygonGeometryB;
60+
QgsGeometry * mpPolygonGeometryC;
61+
62+
QString mTestDataDir;
63+
};
64+
65+
QString TestQgsGeometry::getQgisPath()
66+
{
67+
#ifdef Q_OS_LINUX
68+
QString qgisPath = QCoreApplication::applicationDirPath () + "/../";
69+
#else //mac and win
70+
QString qgisPath = QCoreApplication::applicationDirPath () ;
71+
#endif
72+
return qgisPath;
73+
}
74+
75+
void TestQgsGeometry::init()
76+
{
77+
//
78+
// Reset / reinitialise the geometries before each test is run
79+
//
80+
mPoint1 = QgsPoint(20.0,10.0); /* +1 +A */
81+
mPoint2 = QgsPoint(10.0,30.0); /* / \ / \ */
82+
mPoint3 = QgsPoint(30.0,30.0); /* / X \ */
83+
mPointA = QgsPoint(40.0,10.0); /* 2+---/-+3 \ */
84+
mPointB = QgsPoint(20.0,40.0); /* B+-------+C */
85+
mPointC = QgsPoint(50.0,40.0); /* */
86+
mPointD = QgsPoint(20.0,60.0); /* */
87+
88+
mPolylineA << mPoint1 << mPoint2 << mPoint3 << mPoint1;
89+
mPolygonA << mPolylineA;
90+
//Polygon B intersects Polygon A
91+
mPolylineB << mPointA << mPointB << mPointC << mPointA;
92+
mPolygonB << mPolylineB;
93+
// Polygon C should intersect no other polys
94+
mPolylineC << mPointD << mPointB << mPointC << mPointD;
95+
mPolygonC << mPolylineC;
96+
97+
//polygon: first item of the list is outer ring,
98+
// inner rings (if any) start from second item
99+
mpPolygonGeometryA = QgsGeometry::fromPolygon(mPolygonA);
100+
mpPolygonGeometryB = QgsGeometry::fromPolygon(mPolygonB);
101+
mpPolygonGeometryC = QgsGeometry::fromPolygon(mPolygonC);
102+
103+
}
104+
105+
void TestQgsGeometry::cleanup()
106+
{
107+
// will be called after every testfunction.
108+
delete mpPolygonGeometryA;
109+
delete mpPolygonGeometryB;
110+
delete mpPolygonGeometryC;
111+
}
112+
113+
void TestQgsGeometry::initTestCase()
114+
{
115+
//
116+
// Runs once before any tests are run
117+
//
118+
// init QGIS's paths - true means that all path will be inited from prefix
119+
//QString qgisPath = QCoreApplication::applicationDirPath ();
120+
QgsApplication::setPrefixPath(getQgisPath(), TRUE);
121+
#ifdef Q_OS_LINUX
122+
// QgsApplication::setPkgDataPath(qgisPath + "/../share/qgis");
123+
// QgsApplication::setPluginPath(qgisPath + "/../lib/qgis");
124+
#endif
125+
126+
std::cout << "Prefix PATH: " << QgsApplication::prefixPath().toLocal8Bit().data() << std::endl;
127+
std::cout << "Plugin PATH: " << QgsApplication::pluginPath().toLocal8Bit().data() << std::endl;
128+
std::cout << "PkgData PATH: " << QgsApplication::pkgDataPath().toLocal8Bit().data() << std::endl;
129+
std::cout << "User DB PATH: " << QgsApplication::qgisUserDbFilePath().toLocal8Bit().data() << std::endl;
130+
131+
}
132+
void TestQgsGeometry::cleanupTestCase()
133+
{
134+
//
135+
// Runs once after all tests are run
136+
//
137+
138+
}
139+
140+
void TestQgsGeometry::intersectionCheck()
141+
{
142+
QVERIFY ( mpPolygonGeometryA->intersects(mpPolygonGeometryB));
143+
QVERIFY ( !mpPolygonGeometryA->intersects(mpPolygonGeometryC));
144+
}
145+
146+
147+
QTEST_MAIN(TestQgsGeometry)
148+
#include "moc_testqgsgeometry.cxx"
149+

0 commit comments

Comments
 (0)