Skip to content

Commit 9d3f9f8

Browse files
author
timlinux
committed
Added unit test for QgsPoint
git-svn-id: http://svn.osgeo.org/qgis/trunk@11826 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 49b970a commit 9d3f9f8

File tree

2 files changed

+159
-0
lines changed

2 files changed

+159
-0
lines changed

tests/src/core/CMakeLists.txt

+22
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,25 @@ ELSE (APPLE)
319319
ADD_TEST(qgis_coordinatereferencesystemtest ${CMAKE_INSTALL_PREFIX}/bin/qgis_coordinatereferencesystemtest)
320320
ENDIF (APPLE)
321321
322+
#
323+
# testqgspoint
324+
#
325+
SET(qgis_pointtest_SRCS testqgspoint.cpp ${util_SRCS})
326+
SET(qgis_pointtest_MOC_CPPS testqgspoint.cpp)
327+
QT4_WRAP_CPP(qgis_pointtest_MOC_SRCS ${qgis_pointtest_MOC_CPPS})
328+
ADD_CUSTOM_TARGET(qgis_pointtestmoc ALL DEPENDS ${qgis_pointtest_MOC_SRCS})
329+
ADD_EXECUTABLE(qgis_pointtest ${qgis_pointtest_SRCS})
330+
ADD_DEPENDENCIES(qgis_pointtest qgis_pointtestmoc)
331+
TARGET_LINK_LIBRARIES(qgis_pointtest ${QT_LIBRARIES} qgis_core)
332+
SET_TARGET_PROPERTIES(qgis_pointtest
333+
PROPERTIES INSTALL_RPATH ${QGIS_LIB_DIR}
334+
INSTALL_RPATH_USE_LINK_PATH true)
335+
IF (APPLE)
336+
# For Mac OS X, the executable must be at the root of the bundle's executable folder
337+
INSTALL(TARGETS qgis_pointtest RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
338+
ADD_TEST(qgis_pointtest ${CMAKE_INSTALL_PREFIX}/qgis_pointtest)
339+
ELSE (APPLE)
340+
INSTALL(TARGETS qgis_pointtest RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
341+
ADD_TEST(qgis_pointtest ${CMAKE_INSTALL_PREFIX}/bin/qgis_pointtest)
342+
ENDIF (APPLE)
343+

tests/src/core/testqgspoint.cpp

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/***************************************************************************
2+
test_template.cpp
3+
--------------------------------------
4+
Date : Sun Sep 16 12:22:23 AKDT 2007
5+
Copyright : (C) 2007 by Gary E. Sherman
6+
Email : sherman at mrcc dot 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 <QObject>
19+
#include <QApplication>
20+
#include <QFileInfo>
21+
#include <QDir>
22+
#include <QDesktopServices>
23+
24+
#include <iostream>
25+
//qgis includes...
26+
#include <qgsapplication.h>
27+
#include <qgsgeometry.h>
28+
//header for class being tested
29+
#include <qgspoint.h>
30+
31+
class TestQgsPoint: public QObject
32+
{
33+
Q_OBJECT;
34+
private slots:
35+
void initTestCase();// will be called before the first testfunction is executed.
36+
void cleanupTestCase();// will be called after the last testfunction was executed.
37+
void init();// will be called before each testfunction is executed.
38+
void cleanup();// will be called after every testfunction.
39+
void toString();
40+
void toDegreesMinutesSeconds();
41+
void wellKnownText();
42+
void sqrDist();
43+
void multiply();
44+
void onSegment();
45+
private:
46+
QgsPoint mPoint1;
47+
QgsPoint mPoint2;
48+
QgsPoint mPoint3;
49+
QgsPoint mPoint4;
50+
QString mReport;
51+
};
52+
53+
void TestQgsPoint::init()
54+
{
55+
//
56+
// Reset / reinitialise the geometries before each test is run
57+
//
58+
mPoint1 = QgsPoint( 20.0, -20.0 );
59+
mPoint2 = QgsPoint( -80.0, 20.0 );
60+
mPoint3 = QgsPoint( -80.0, -20.0 );
61+
mPoint4 = QgsPoint( 80.0, 20.0 );
62+
}
63+
64+
void TestQgsPoint::cleanup()
65+
{
66+
// will be called after every testfunction.
67+
}
68+
69+
void TestQgsPoint::initTestCase()
70+
{
71+
//
72+
// Runs once before any tests are run
73+
//
74+
// init QGIS's paths - true means that all path will be inited from prefix
75+
QString qgisPath = QCoreApplication::applicationDirPath();
76+
QgsApplication::setPrefixPath( INSTALL_PREFIX, true );
77+
QgsApplication::showSettings();
78+
mReport += "<h1>Point Tests</h1>\n";
79+
}
80+
81+
82+
void TestQgsPoint::cleanupTestCase()
83+
{
84+
//
85+
// Runs once after all tests are run
86+
//
87+
QString myReportFile = QDir::tempPath() + QDir::separator() + "qgspointtest.html";
88+
QFile myFile( myReportFile );
89+
if ( myFile.open( QIODevice::WriteOnly ) )
90+
{
91+
QTextStream myQTextStream( &myFile );
92+
myQTextStream << mReport;
93+
myFile.close();
94+
QDesktopServices::openUrl( "file://" + myReportFile );
95+
}
96+
97+
}
98+
99+
void TestQgsPoint::toString()
100+
{
101+
mReport += "<p>Testing toString()</p>";
102+
mReport += "<p>" + mPoint1.toString( 2 ) + "</p>";
103+
mReport += "<p>" + mPoint2.toString( 2 ) + "</p>";
104+
mReport += "<p>" + mPoint3.toString( 2 ) + "</p>";
105+
mReport += "<p>" + mPoint4.toString( 2 ) + "</p>";
106+
QVERIFY( mPoint1.toString( 2 ) == QString("20.00,-20.00") );
107+
};
108+
void TestQgsPoint::toDegreesMinutesSeconds()
109+
{
110+
mReport += "<p>Testing toDegreesMinutesSecods()</p>";
111+
mReport += "<p>" + mPoint1.toDegreesMinutesSeconds( 2 ) + "</p>";
112+
mReport += "<p>" + mPoint2.toDegreesMinutesSeconds( 2 ) + "</p>";
113+
mReport += "<p>" + mPoint3.toDegreesMinutesSeconds( 2 ) + "</p>";
114+
mReport += "<p>" + mPoint4.toDegreesMinutesSeconds( 2 ) + "</p>";
115+
QVERIFY( mPoint4.toString( 2 ) == QString("80°0'0.00\"E,20°0'0.00\"N") );
116+
117+
};
118+
void TestQgsPoint::wellKnownText()
119+
{
120+
121+
};
122+
void TestQgsPoint::sqrDist()
123+
{
124+
125+
};
126+
void TestQgsPoint::multiply()
127+
{
128+
129+
};
130+
void TestQgsPoint::onSegment()
131+
{
132+
133+
};
134+
135+
136+
QTEST_MAIN(TestQgsPoint)
137+
#include "moc_testqgspoint.cxx"

0 commit comments

Comments
 (0)