[QGIS Commit] r8180 - trunk/qgis/tests/src/core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Mon Feb 25 21:52:00 EST 2008


Author: timlinux
Date: 2008-02-25 21:52:00 -0500 (Mon, 25 Feb 2008)
New Revision: 8180

Added:
   trunk/qgis/tests/src/core/testqgsgeometry.cpp
Modified:
   trunk/qgis/tests/src/core/CMakeLists.txt
Log:
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...


Modified: trunk/qgis/tests/src/core/CMakeLists.txt
===================================================================
--- trunk/qgis/tests/src/core/CMakeLists.txt	2008-02-26 02:48:23 UTC (rev 8179)
+++ trunk/qgis/tests/src/core/CMakeLists.txt	2008-02-26 02:52:00 UTC (rev 8180)
@@ -191,6 +191,27 @@
   INSTALL(TARGETS qgis_maprendertest RUNTIME DESTINATION ${QGIS_BIN_DIR})
   ADD_TEST(qgis_maprendertest ${QGIS_BIN_DIR}/qgis_maprendertest)
 ENDIF (APPLE)
+#
+# QgsGeometry test
+#
+SET(qgis_geometrytest_SRCS testqgsgeometry.cpp ${util_SRCS})
+SET(qgis_geometrytest_MOC_CPPS testqgsgeometry.cpp)
+QT4_WRAP_CPP(qgis_geometrytest_MOC_SRCS ${qgis_geometrytest_MOC_CPPS})
+ADD_CUSTOM_TARGET(qgis_geometrytestmoc ALL DEPENDS ${qgis_geometrytest_MOC_SRCS})
+ADD_EXECUTABLE(qgis_geometrytest ${qgis_geometrytest_SRCS})
+ADD_DEPENDENCIES(qgis_geometrytest qgis_geometrytestmoc)
+TARGET_LINK_LIBRARIES(qgis_geometrytest ${QT_LIBRARIES} qgis_core)
+SET_TARGET_PROPERTIES(qgis_geometrytest 
+  PROPERTIES INSTALL_RPATH ${QGIS_LIB_DIR}
+  INSTALL_RPATH_USE_LINK_PATH true)
+IF (APPLE)
+  # For Mac OS X, the executable must be at the root of the bundle's executable folder
+  INSTALL(TARGETS qgis_geometrytest RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
+  ADD_TEST(qgis_geometrytest ${CMAKE_INSTALL_PREFIX}/qgis_geometrytest)
+ELSE (APPLE)
+  INSTALL(TARGETS qgis_geometrytest RUNTIME DESTINATION ${QGIS_BIN_DIR})
+  ADD_TEST(qgis_geometrytest ${QGIS_BIN_DIR}/qgis_geometrytest)
+ENDIF (APPLE)
 
 
 

Copied: trunk/qgis/tests/src/core/testqgsgeometry.cpp (from rev 8178, trunk/qgis/tests/src/core/testqgsrenderers.cpp)
===================================================================
--- trunk/qgis/tests/src/core/testqgsgeometry.cpp	                        (rev 0)
+++ trunk/qgis/tests/src/core/testqgsgeometry.cpp	2008-02-26 02:52:00 UTC (rev 8180)
@@ -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"
+



More information about the QGIS-commit mailing list