Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
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
- Loading branch information
timlinux
committed
Feb 26, 2008
1 parent
4858e02
commit cce210c
Showing
2 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/*************************************************************************** | ||
testqgsgeometry.cpp | ||
-------------------------------------- | ||
Date : 20 Jan 2008 | ||
Copyright : (C) 2008 by Tim Sutton | ||
Email : tim @ linfiniti.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 <QtTest> | ||
#include <QObject> | ||
#include <QString> | ||
#include <QStringList> | ||
#include <QObject> | ||
#include <QApplication> | ||
#include <QFileInfo> | ||
#include <QDir> | ||
#include <QDesktopServices> | ||
|
||
#include <iostream> | ||
//qgis includes... | ||
#include <qgsapplication.h> | ||
#include <qgsgeometry.h> | ||
|
||
/** \ingroup UnitTests | ||
* This is a unit test for the different geometry operations on vector features. | ||
*/ | ||
class TestQgsGeometry: public QObject | ||
{ | ||
Q_OBJECT; | ||
private slots: | ||
QString getQgisPath(); // Gets the path to QGIS installation | ||
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 intersectionCheck(); | ||
private: | ||
QgsPoint mPoint1; /* +1 +A */ | ||
QgsPoint mPoint2; /* / \ / \ */ | ||
QgsPoint mPoint3; /* / X \ */ | ||
QgsPoint mPointA; /* 2+---/-+3 \ */ | ||
QgsPoint mPointB; /* B+-------+C */ | ||
QgsPoint mPointC; /* */ | ||
QgsPoint mPointD; /* +D */ | ||
QgsPolyline mPolylineA; | ||
QgsPolyline mPolylineB; | ||
QgsPolyline mPolylineC; | ||
QgsPolygon mPolygonA; | ||
QgsPolygon mPolygonB; | ||
QgsPolygon mPolygonC; | ||
QgsGeometry * mpPolygonGeometryA; | ||
QgsGeometry * mpPolygonGeometryB; | ||
QgsGeometry * mpPolygonGeometryC; | ||
|
||
QString mTestDataDir; | ||
}; | ||
|
||
QString TestQgsGeometry::getQgisPath() | ||
{ | ||
#ifdef Q_OS_LINUX | ||
QString qgisPath = QCoreApplication::applicationDirPath () + "/../"; | ||
#else //mac and win | ||
QString qgisPath = QCoreApplication::applicationDirPath () ; | ||
#endif | ||
return qgisPath; | ||
} | ||
|
||
void TestQgsGeometry::init() | ||
{ | ||
// | ||
// Reset / reinitialise the geometries before each test is run | ||
// | ||
mPoint1 = QgsPoint(20.0,10.0); /* +1 +A */ | ||
mPoint2 = QgsPoint(10.0,30.0); /* / \ / \ */ | ||
mPoint3 = QgsPoint(30.0,30.0); /* / X \ */ | ||
mPointA = QgsPoint(40.0,10.0); /* 2+---/-+3 \ */ | ||
mPointB = QgsPoint(20.0,40.0); /* B+-------+C */ | ||
mPointC = QgsPoint(50.0,40.0); /* */ | ||
mPointD = QgsPoint(20.0,60.0); /* */ | ||
|
||
mPolylineA << mPoint1 << mPoint2 << mPoint3 << mPoint1; | ||
mPolygonA << mPolylineA; | ||
//Polygon B intersects Polygon A | ||
mPolylineB << mPointA << mPointB << mPointC << mPointA; | ||
mPolygonB << mPolylineB; | ||
// Polygon C should intersect no other polys | ||
mPolylineC << mPointD << mPointB << mPointC << mPointD; | ||
mPolygonC << mPolylineC; | ||
|
||
//polygon: first item of the list is outer ring, | ||
// inner rings (if any) start from second item | ||
mpPolygonGeometryA = QgsGeometry::fromPolygon(mPolygonA); | ||
mpPolygonGeometryB = QgsGeometry::fromPolygon(mPolygonB); | ||
mpPolygonGeometryC = QgsGeometry::fromPolygon(mPolygonC); | ||
|
||
} | ||
|
||
void TestQgsGeometry::cleanup() | ||
{ | ||
// will be called after every testfunction. | ||
delete mpPolygonGeometryA; | ||
delete mpPolygonGeometryB; | ||
delete mpPolygonGeometryC; | ||
} | ||
|
||
void TestQgsGeometry::initTestCase() | ||
{ | ||
// | ||
// Runs once before any tests are run | ||
// | ||
// init QGIS's paths - true means that all path will be inited from prefix | ||
//QString qgisPath = QCoreApplication::applicationDirPath (); | ||
QgsApplication::setPrefixPath(getQgisPath(), TRUE); | ||
#ifdef Q_OS_LINUX | ||
// QgsApplication::setPkgDataPath(qgisPath + "/../share/qgis"); | ||
// QgsApplication::setPluginPath(qgisPath + "/../lib/qgis"); | ||
#endif | ||
|
||
std::cout << "Prefix PATH: " << QgsApplication::prefixPath().toLocal8Bit().data() << std::endl; | ||
std::cout << "Plugin PATH: " << QgsApplication::pluginPath().toLocal8Bit().data() << std::endl; | ||
std::cout << "PkgData PATH: " << QgsApplication::pkgDataPath().toLocal8Bit().data() << std::endl; | ||
std::cout << "User DB PATH: " << QgsApplication::qgisUserDbFilePath().toLocal8Bit().data() << std::endl; | ||
|
||
} | ||
void TestQgsGeometry::cleanupTestCase() | ||
{ | ||
// | ||
// Runs once after all tests are run | ||
// | ||
|
||
} | ||
|
||
void TestQgsGeometry::intersectionCheck() | ||
{ | ||
QVERIFY ( mpPolygonGeometryA->intersects(mpPolygonGeometryB)); | ||
QVERIFY ( !mpPolygonGeometryA->intersects(mpPolygonGeometryC)); | ||
} | ||
|
||
|
||
QTEST_MAIN(TestQgsGeometry) | ||
#include "moc_testqgsgeometry.cxx" | ||
|