Skip to content

Commit 150c728

Browse files
author
timlinux
committed
Added unit test for QgsCoordinateReferenceSystem
git-svn-id: http://svn.osgeo.org/qgis/trunk@11800 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 3338ac6 commit 150c728

File tree

2 files changed

+329
-0
lines changed

2 files changed

+329
-0
lines changed

tests/src/core/CMakeLists.txt

+21
Original file line numberDiff line numberDiff line change
@@ -297,4 +297,25 @@ ELSE (APPLE)
297297
ENDIF (APPLE)
298298
299299
300+
#
301+
# testqgscoordinatereferencesystem
302+
#
303+
SET(qgis_coordinatereferencesystemtest_SRCS testqgscoordinatereferencesystem.cpp ${util_SRCS})
304+
SET(qgis_coordinatereferencesystemtest_MOC_CPPS testqgscoordinatereferencesystem.cpp)
305+
QT4_WRAP_CPP(qgis_coordinatereferencesystemtest_MOC_SRCS ${qgis_coordinatereferencesystemtest_MOC_CPPS})
306+
ADD_CUSTOM_TARGET(qgis_coordinatereferencesystemtestmoc ALL DEPENDS ${qgis_coordinatereferencesystemtest_MOC_SRCS})
307+
ADD_EXECUTABLE(qgis_coordinatereferencesystemtest ${qgis_coordinatereferencesystemtest_SRCS})
308+
ADD_DEPENDENCIES(qgis_coordinatereferencesystemtest qgis_coordinatereferencesystemtestmoc)
309+
TARGET_LINK_LIBRARIES(qgis_coordinatereferencesystemtest ${QT_LIBRARIES} qgis_core)
310+
SET_TARGET_PROPERTIES(qgis_coordinatereferencesystemtest
311+
PROPERTIES INSTALL_RPATH ${QGIS_LIB_DIR}
312+
INSTALL_RPATH_USE_LINK_PATH true)
313+
IF (APPLE)
314+
# For Mac OS X, the executable must be at the root of the bundle's executable folder
315+
INSTALL(TARGETS qgis_coordinatereferencesystemtest RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
316+
ADD_TEST(qgis_coordinatereferencesystemtest ${CMAKE_INSTALL_PREFIX}/qgis_coordinatereferencesystemtest)
317+
ELSE (APPLE)
318+
INSTALL(TARGETS qgis_coordinatereferencesystemtest RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
319+
ADD_TEST(qgis_coordinatereferencesystemtest ${CMAKE_INSTALL_PREFIX}/bin/qgis_coordinatereferencesystemtest)
320+
ENDIF (APPLE)
300321
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,308 @@
1+
/***************************************************************************
2+
testqgscoordinatereferencesystem.cpp
3+
--------------------------------------
4+
Date : Sun Sep 16 12:22:49 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 <iostream>
17+
18+
#include <QPixmap>
19+
20+
#include <qgsapplication.h>
21+
#include "qgslogger.h"
22+
23+
//header for class being tested
24+
#include <qgscoordinatereferencesystem.h>
25+
26+
class TestQgsCoordinateReferenceSystem: public QObject
27+
{
28+
Q_OBJECT;
29+
private slots:
30+
void initTestCase();
31+
void wktCtor();
32+
void idCtor();
33+
void copyCtor();
34+
void assignmentCtor();
35+
void createFromId();
36+
void createFromOgcWmsCrs();
37+
void createFromSrid();
38+
void createFromWkt();
39+
void createFromEpsg();
40+
void createFromSrsId();
41+
void createFromProj4();
42+
void isValid();
43+
void validate();
44+
void findMatchingProj();
45+
void equality();
46+
void noEquality();
47+
void equals();
48+
void readXML();
49+
void writeXML();
50+
void setCustomSrsValidation();
51+
void customSrsValidation();
52+
void srsid();
53+
void postgisSrid();
54+
void ellipsoidAcronym();
55+
void toWkt();
56+
void toProj4();
57+
void geographicFlag();
58+
void mapUnits();
59+
void setValidationHint();
60+
private:
61+
void debugPrint( QgsCoordinateReferenceSystem &theCrs );
62+
};
63+
64+
65+
void TestQgsCoordinateReferenceSystem::initTestCase()
66+
{
67+
//
68+
// Runs once before any tests are run
69+
//
70+
// init QGIS's paths - true means that all path will be inited from prefix
71+
QString qgisPath = QCoreApplication::applicationDirPath();
72+
QgsApplication::setPrefixPath( INSTALL_PREFIX, true );
73+
QgsApplication::showSettings();
74+
75+
};
76+
77+
void TestQgsCoordinateReferenceSystem::wktCtor()
78+
{
79+
QString myWkt ( "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]],AUTHORITY[\"EPSG\",\"4326\"]]" ) ;
80+
QgsCoordinateReferenceSystem myCrs( myWkt );
81+
debugPrint( myCrs );
82+
QVERIFY( myCrs.isValid() );
83+
}
84+
void TestQgsCoordinateReferenceSystem::idCtor()
85+
{
86+
QgsCoordinateReferenceSystem myCrs( 4326, QgsCoordinateReferenceSystem::EpsgCrsId );
87+
debugPrint( myCrs );
88+
QVERIFY( myCrs.isValid() );
89+
}
90+
void TestQgsCoordinateReferenceSystem::copyCtor()
91+
{
92+
QgsCoordinateReferenceSystem myCrs( 4326, QgsCoordinateReferenceSystem::EpsgCrsId );
93+
QgsCoordinateReferenceSystem myCrs2( myCrs );
94+
debugPrint( myCrs2 );
95+
QVERIFY( myCrs2.isValid() );
96+
}
97+
void TestQgsCoordinateReferenceSystem::assignmentCtor()
98+
{
99+
QgsCoordinateReferenceSystem myCrs( 4326, QgsCoordinateReferenceSystem::EpsgCrsId );
100+
QgsCoordinateReferenceSystem myCrs2 = myCrs;
101+
debugPrint( myCrs2 );
102+
QVERIFY( myCrs2.isValid() );
103+
}
104+
void TestQgsCoordinateReferenceSystem::createFromId()
105+
{
106+
QgsCoordinateReferenceSystem myCrs;
107+
myCrs.createFromId( 4326, QgsCoordinateReferenceSystem::EpsgCrsId );
108+
debugPrint( myCrs );
109+
QVERIFY( myCrs.isValid() );
110+
}
111+
void TestQgsCoordinateReferenceSystem::createFromOgcWmsCrs()
112+
{
113+
QgsCoordinateReferenceSystem myCrs;
114+
//@todo implement this - for now we just check that if fails
115+
//if passed an empty string
116+
QVERIFY ( !myCrs.createFromOgcWmsCrs( QString ("") ) );
117+
}
118+
void TestQgsCoordinateReferenceSystem::createFromSrid()
119+
{
120+
QgsCoordinateReferenceSystem myCrs;
121+
myCrs.createFromSrid( 4326 );
122+
debugPrint( myCrs );
123+
QVERIFY( myCrs.isValid() );
124+
}
125+
void TestQgsCoordinateReferenceSystem::createFromWkt()
126+
{
127+
QgsCoordinateReferenceSystem myCrs;
128+
QString myWkt = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]],AUTHORITY[\"EPSG\",\"4326\"]]" ;
129+
QVERIFY ( !myCrs.createFromWkt( myWkt ) );
130+
}
131+
void TestQgsCoordinateReferenceSystem::createFromEpsg()
132+
{
133+
QgsCoordinateReferenceSystem myCrs;
134+
QVERIFY ( myCrs.createFromEpsg( 4326 ) );
135+
debugPrint( myCrs );
136+
}
137+
void TestQgsCoordinateReferenceSystem::createFromSrsId()
138+
{
139+
QgsCoordinateReferenceSystem myCrs;
140+
QVERIFY( myCrs.createFromSrsId( 4326 ) );
141+
debugPrint( myCrs );
142+
}
143+
void TestQgsCoordinateReferenceSystem::createFromProj4()
144+
{
145+
QgsCoordinateReferenceSystem myCrs;
146+
QVERIFY( myCrs.createFromProj4( "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" ) );
147+
debugPrint( myCrs );
148+
}
149+
void TestQgsCoordinateReferenceSystem::isValid()
150+
{
151+
QgsCoordinateReferenceSystem myCrs;
152+
myCrs.createFromSrsId( 4326 );
153+
QVERIFY( myCrs.isValid() );
154+
debugPrint( myCrs );
155+
}
156+
void TestQgsCoordinateReferenceSystem::validate()
157+
{
158+
QgsCoordinateReferenceSystem myCrs;
159+
myCrs.createFromSrsId( 4326 );
160+
myCrs.validate();
161+
QVERIFY( myCrs.isValid() );
162+
debugPrint( myCrs );
163+
}
164+
void TestQgsCoordinateReferenceSystem::findMatchingProj()
165+
{
166+
QgsCoordinateReferenceSystem myCrs;
167+
myCrs.createFromSrsId( 4326 );
168+
int myLong = myCrs.findMatchingProj();
169+
QVERIFY( myLong == 4326 );
170+
debugPrint( myCrs );
171+
}
172+
void TestQgsCoordinateReferenceSystem::equality()
173+
{
174+
QgsCoordinateReferenceSystem myCrs;
175+
myCrs.createFromSrsId( 4326 );
176+
QgsCoordinateReferenceSystem myCrs2;
177+
myCrs2.createFromSrsId( 4326 );
178+
QVERIFY( myCrs == myCrs2 );
179+
debugPrint( myCrs );
180+
}
181+
void TestQgsCoordinateReferenceSystem::noEquality()
182+
{
183+
QgsCoordinateReferenceSystem myCrs;
184+
myCrs.createFromSrsId( 4326 );
185+
QgsCoordinateReferenceSystem myCrs2;
186+
myCrs2.createFromSrsId( 4327 );
187+
QVERIFY( myCrs != myCrs2 );
188+
debugPrint( myCrs );
189+
}
190+
void TestQgsCoordinateReferenceSystem::equals()
191+
{
192+
QgsCoordinateReferenceSystem myCrs;
193+
myCrs.createFromSrsId( 4326 );
194+
QVERIFY( myCrs.equals( "proj4 string" ) );
195+
debugPrint( myCrs );
196+
}
197+
void TestQgsCoordinateReferenceSystem::readXML()
198+
{
199+
//QgsCoordinateReferenceSystem myCrs;
200+
//myCrs.createFromSrsId( 4326 );
201+
//QgsCoordinateReferenceSystem myCrs2;
202+
//QVERIFY( myCrs2.readXML( QDomNode & theNode ) );
203+
}
204+
void TestQgsCoordinateReferenceSystem::writeXML()
205+
{
206+
//QgsCoordinateReferenceSystem myCrs;
207+
//bool writeXML( QDomNode & theNode, QDomDocument & theDoc ) const;
208+
//QVERIFY( myCrs.isValid() );
209+
}
210+
void TestQgsCoordinateReferenceSystem::setCustomSrsValidation()
211+
{
212+
//QgsCoordinateReferenceSystem myCrs;
213+
//static void setCustomSrsValidation( CUSTOM_CRS_VALIDATION f );
214+
//QVERIFY( myCrs.isValid() );
215+
}
216+
void TestQgsCoordinateReferenceSystem::customSrsValidation()
217+
{
218+
/**
219+
* @todo implement this test
220+
"QgsCoordinateReferenceSystem myCrs;
221+
static CUSTOM_CRS_VALIDATION customSrsValidation();
222+
QVERIFY( myCrs.isValid() );
223+
*/
224+
}
225+
void TestQgsCoordinateReferenceSystem::srsid()
226+
{
227+
QgsCoordinateReferenceSystem myCrs;
228+
myCrs.createFromSrsId( 4326 );
229+
QVERIFY( myCrs.srsid() == 4326 );
230+
debugPrint( myCrs );
231+
}
232+
void TestQgsCoordinateReferenceSystem::postgisSrid()
233+
{
234+
QgsCoordinateReferenceSystem myCrs;
235+
myCrs.createFromSrsId( 4326 );
236+
QVERIFY( myCrs.postgisSrid() == 4326 );
237+
debugPrint( myCrs );
238+
}
239+
void TestQgsCoordinateReferenceSystem::ellipsoidAcronym()
240+
{
241+
QgsCoordinateReferenceSystem myCrs;
242+
myCrs.createFromSrsId( 4326 );
243+
QString myAcronym = myCrs.ellipsoidAcronym();
244+
QVERIFY( myAcronym == "foo" );
245+
debugPrint( myCrs );
246+
}
247+
void TestQgsCoordinateReferenceSystem::toWkt()
248+
{
249+
QgsCoordinateReferenceSystem myCrs;
250+
myCrs.createFromSrsId( 4326 );
251+
QString myWkt = myCrs.toWkt();
252+
QVERIFY( myWkt == "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]],AUTHORITY[\"EPSG\",\"4326\"]]" );
253+
debugPrint( myCrs );
254+
}
255+
void TestQgsCoordinateReferenceSystem::toProj4()
256+
{
257+
QgsCoordinateReferenceSystem myCrs;
258+
myCrs.createFromSrsId( 4326 );
259+
QVERIFY( myCrs.toProj4() == "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" );
260+
debugPrint( myCrs );
261+
}
262+
void TestQgsCoordinateReferenceSystem::geographicFlag()
263+
{
264+
QgsCoordinateReferenceSystem myCrs;
265+
myCrs.createFromSrsId( 4326 );
266+
QVERIFY( myCrs.geographicFlag() );
267+
debugPrint( myCrs );
268+
}
269+
void TestQgsCoordinateReferenceSystem::mapUnits()
270+
{
271+
QgsCoordinateReferenceSystem myCrs;
272+
myCrs.createFromSrsId( 4326 );
273+
QVERIFY( myCrs.mapUnits() == QGis::Degrees );
274+
debugPrint( myCrs );
275+
}
276+
void TestQgsCoordinateReferenceSystem::setValidationHint()
277+
{
278+
QgsCoordinateReferenceSystem myCrs;
279+
myCrs.setValidationHint( "<head>" );
280+
QVERIFY( myCrs.validationHint() == QString( "<head>" ) );
281+
debugPrint( myCrs );
282+
}
283+
284+
void TestQgsCoordinateReferenceSystem::debugPrint( QgsCoordinateReferenceSystem &theCrs )
285+
{
286+
QgsDebugMsg( "***SpatialRefSystem***" );
287+
QgsDebugMsg( "* Valid : " + ( theCrs.isValid() ? QString( "true" ) : QString( "false" ) ) );
288+
QgsDebugMsg( "* SrsId : " + QString::number( theCrs.srsid() ) );
289+
QgsDebugMsg( "* Proj4 : " + theCrs.toProj4() );
290+
QgsDebugMsg( "* WKT : " + theCrs.toWkt() );
291+
QgsDebugMsg( "* Desc. : " + theCrs.description() );
292+
if ( theCrs.mapUnits() == QGis::Meters )
293+
{
294+
QgsDebugMsg( "* Units : meters" );
295+
}
296+
else if ( theCrs.mapUnits() == QGis::Feet )
297+
{
298+
QgsDebugMsg( "* Units : feet" );
299+
}
300+
else if ( theCrs.mapUnits() == QGis::Degrees )
301+
{
302+
QgsDebugMsg( "* Units : degrees" );
303+
}
304+
}
305+
306+
QTEST_MAIN( TestQgsCoordinateReferenceSystem )
307+
#include "moc_testqgscoordinatereferencesystem.cxx"
308+

0 commit comments

Comments
 (0)