2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Sami Rämö - sami.ramo@ixonos.com
7 Situare is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
11 Situare is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Situare; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 #include <QtCore/QString>
23 #include <QtTest/QtTest>
25 #include "coordinates/scenecoordinate.h"
26 #include "map/mapcommon.h"
28 #include "coordinates/geocoordinate.h"
30 const double LATITUDE = 12.345678;
31 const double LONGITUDE = -89.765432;
33 const double ONE_SCENE_PIXEL_WIDTH_IN_DEGREES = 0.00000536441802978516;
35 class TestGeoCoordinate : public QObject
43 void conversion_data();
44 void settersAndGetters();
47 // for formatting the output of double valuest into the test log
50 char *toString(const double &number)
53 ba += QByteArray::number(number, 'f', 9);
54 return qstrdup(ba.data());
58 void TestGeoCoordinate::constructors()
60 GeoCoordinate coordinate;
61 QVERIFY(coordinate.isNull());
63 GeoCoordinate coordinate2(LATITUDE, LONGITUDE);
64 QCOMPARE(coordinate2.latitude(), LATITUDE);
65 QCOMPARE(coordinate2.longitude(), LONGITUDE);
67 // NOTE: constructor with conversion from GeoCoordinate is tested in conversion() test slot
70 void TestGeoCoordinate::conversion()
72 // allow rounding error of one tenth of one scene pixel
73 const double MAX_ERROR = ONE_SCENE_PIXEL_WIDTH_IN_DEGREES * 0.1;
75 QFETCH(SceneCoordinate, sceneCoordinate);
76 QFETCH(GeoCoordinate, result);
78 GeoCoordinate geoCoordinate(sceneCoordinate);
80 QVERIFY(qAbs(geoCoordinate.latitude() - result.latitude()) < MAX_ERROR);
81 QVERIFY(qAbs(geoCoordinate.longitude() - result.longitude()) < MAX_ERROR);
84 void TestGeoCoordinate::conversion_data()
86 QTest::addColumn<SceneCoordinate>("sceneCoordinate");
87 QTest::addColumn<GeoCoordinate>("result");
89 QTest::newRow("top left") << SceneCoordinate(MAP_MIN_PIXEL_X, MAP_MIN_PIXEL_Y)
90 << GeoCoordinate(MAX_LATITUDE, MIN_LONGITUDE);
92 const double LAST_SCENE_HORIZONTAL_PIXEL_LONGITUDE = MAX_LONGITUDE
93 - ONE_SCENE_PIXEL_WIDTH_IN_DEGREES;
95 QTest::newRow("bottom right") << SceneCoordinate(MAP_MAX_PIXEL_X, MAP_MAX_PIXEL_Y)
96 << GeoCoordinate(MIN_LATITUDE, LAST_SCENE_HORIZONTAL_PIXEL_LONGITUDE);
99 void TestGeoCoordinate::isNull()
101 GeoCoordinate coordinate;
102 QVERIFY(coordinate.isNull());
103 coordinate.setLatitude(1);
104 QVERIFY(!coordinate.isNull());
106 GeoCoordinate coordinate2;
107 QVERIFY(coordinate2.isNull());
108 coordinate2.setLongitude(1);
109 QVERIFY(!coordinate.isNull());
111 GeoCoordinate coordinate3;
112 QVERIFY(coordinate3.isNull());
113 coordinate3.setLatitude(1);
114 coordinate3.setLongitude(1);
115 QVERIFY(!coordinate.isNull());
118 void TestGeoCoordinate::settersAndGetters()
120 GeoCoordinate coordinate;
121 QCOMPARE(coordinate.latitude(), (double)0);
122 QCOMPARE(coordinate.longitude(), (double)0);
124 coordinate.setLatitude(LATITUDE);
125 coordinate.setLongitude(LONGITUDE);
127 QCOMPARE(coordinate.latitude(), LATITUDE);
128 QCOMPARE(coordinate.longitude(), LONGITUDE);
131 QTEST_APPLESS_MAIN(TestGeoCoordinate);
133 #include "testgeocoordinate.moc"