From 9d3f9f8715a3ce1e4603d9dcbbef293cf4854c55 Mon Sep 17 00:00:00 2001 From: timlinux Date: Wed, 21 Oct 2009 22:43:41 +0000 Subject: [PATCH] Added unit test for QgsPoint git-svn-id: http://svn.osgeo.org/qgis/trunk@11826 c8812cc2-4d05-0410-92ff-de0c093fc19c --- tests/src/core/CMakeLists.txt | 22 +++++ tests/src/core/testqgspoint.cpp | 137 ++++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 tests/src/core/testqgspoint.cpp diff --git a/tests/src/core/CMakeLists.txt b/tests/src/core/CMakeLists.txt index d93879d2489..4c871f90e98 100644 --- a/tests/src/core/CMakeLists.txt +++ b/tests/src/core/CMakeLists.txt @@ -319,3 +319,25 @@ ELSE (APPLE) ADD_TEST(qgis_coordinatereferencesystemtest ${CMAKE_INSTALL_PREFIX}/bin/qgis_coordinatereferencesystemtest) ENDIF (APPLE) +# +# testqgspoint +# +SET(qgis_pointtest_SRCS testqgspoint.cpp ${util_SRCS}) +SET(qgis_pointtest_MOC_CPPS testqgspoint.cpp) +QT4_WRAP_CPP(qgis_pointtest_MOC_SRCS ${qgis_pointtest_MOC_CPPS}) +ADD_CUSTOM_TARGET(qgis_pointtestmoc ALL DEPENDS ${qgis_pointtest_MOC_SRCS}) +ADD_EXECUTABLE(qgis_pointtest ${qgis_pointtest_SRCS}) +ADD_DEPENDENCIES(qgis_pointtest qgis_pointtestmoc) +TARGET_LINK_LIBRARIES(qgis_pointtest ${QT_LIBRARIES} qgis_core) +SET_TARGET_PROPERTIES(qgis_pointtest + 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_pointtest RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}) + ADD_TEST(qgis_pointtest ${CMAKE_INSTALL_PREFIX}/qgis_pointtest) +ELSE (APPLE) + INSTALL(TARGETS qgis_pointtest RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) + ADD_TEST(qgis_pointtest ${CMAKE_INSTALL_PREFIX}/bin/qgis_pointtest) +ENDIF (APPLE) + diff --git a/tests/src/core/testqgspoint.cpp b/tests/src/core/testqgspoint.cpp new file mode 100644 index 00000000000..37b5e0b8395 --- /dev/null +++ b/tests/src/core/testqgspoint.cpp @@ -0,0 +1,137 @@ +/*************************************************************************** + test_template.cpp + -------------------------------------- + Date : Sun Sep 16 12:22:23 AKDT 2007 + Copyright : (C) 2007 by Gary E. Sherman + Email : sherman at mrcc 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 +#include +#include +#include +#include +#include +#include +#include + +#include +//qgis includes... +#include +#include +//header for class being tested +#include + +class TestQgsPoint: 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 toString(); + void toDegreesMinutesSeconds(); + void wellKnownText(); + void sqrDist(); + void multiply(); + void onSegment(); + private: + QgsPoint mPoint1; + QgsPoint mPoint2; + QgsPoint mPoint3; + QgsPoint mPoint4; + QString mReport; +}; + +void TestQgsPoint::init() +{ + // + // Reset / reinitialise the geometries before each test is run + // + mPoint1 = QgsPoint( 20.0, -20.0 ); + mPoint2 = QgsPoint( -80.0, 20.0 ); + mPoint3 = QgsPoint( -80.0, -20.0 ); + mPoint4 = QgsPoint( 80.0, 20.0 ); +} + +void TestQgsPoint::cleanup() +{ + // will be called after every testfunction. +} + +void TestQgsPoint::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( INSTALL_PREFIX, true ); + QgsApplication::showSettings(); + mReport += "

Point Tests

\n"; +} + + +void TestQgsPoint::cleanupTestCase() +{ + // + // Runs once after all tests are run + // + QString myReportFile = QDir::tempPath() + QDir::separator() + "qgspointtest.html"; + QFile myFile( myReportFile ); + if ( myFile.open( QIODevice::WriteOnly ) ) + { + QTextStream myQTextStream( &myFile ); + myQTextStream << mReport; + myFile.close(); + QDesktopServices::openUrl( "file://" + myReportFile ); + } + +} + +void TestQgsPoint::toString() +{ + mReport += "

Testing toString()

"; + mReport += "

" + mPoint1.toString( 2 ) + "

"; + mReport += "

" + mPoint2.toString( 2 ) + "

"; + mReport += "

" + mPoint3.toString( 2 ) + "

"; + mReport += "

" + mPoint4.toString( 2 ) + "

"; + QVERIFY( mPoint1.toString( 2 ) == QString("20.00,-20.00") ); +}; +void TestQgsPoint::toDegreesMinutesSeconds() +{ + mReport += "

Testing toDegreesMinutesSecods()

"; + mReport += "

" + mPoint1.toDegreesMinutesSeconds( 2 ) + "

"; + mReport += "

" + mPoint2.toDegreesMinutesSeconds( 2 ) + "

"; + mReport += "

" + mPoint3.toDegreesMinutesSeconds( 2 ) + "

"; + mReport += "

" + mPoint4.toDegreesMinutesSeconds( 2 ) + "

"; + QVERIFY( mPoint4.toString( 2 ) == QString("80°0'0.00\"E,20°0'0.00\"N") ); + +}; +void TestQgsPoint::wellKnownText() +{ + +}; +void TestQgsPoint::sqrDist() +{ + +}; +void TestQgsPoint::multiply() +{ + +}; +void TestQgsPoint::onSegment() +{ + +}; + + +QTEST_MAIN(TestQgsPoint) +#include "moc_testqgspoint.cxx"