Unit tests for converting GeoCoordinate to SceneCoordinate
authorSami Rämö <sami.ramo@ixonos.com>
Wed, 14 Jul 2010 09:01:21 +0000 (12:01 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Wed, 14 Jul 2010 09:01:21 +0000 (12:01 +0300)
 - Copied tests from MapEngine and refactored them

 - fixed SceneCoordinate::convertFrom(GeoCoordinate) assertions

 - mapcommon.h: changed coordinate limit values from qreal to double

src/coordinates/geocoordinate.h
src/coordinates/scenecoordinate.cpp
src/coordinates/scenecoordinate.h
src/map/mapcommon.h
tests/coordinates/scenecoordinate/testscenecoordinate.cpp

index ff4dd6a..c31f9bd 100644 (file)
@@ -24,6 +24,7 @@
 #define GEOCOORDINATE_H
 
 #include <QDebug>
+#include <QMetaType>
 
 /**
 * @brief Geographic coordinate
@@ -88,4 +89,6 @@ private:
 
 QDebug operator<<(QDebug dbg, const GeoCoordinate &c);
 
+Q_DECLARE_METATYPE(GeoCoordinate)
+
 #endif // GEOCOORDINATE_H
index 04388c2..48f5df7 100644 (file)
@@ -51,10 +51,11 @@ void SceneCoordinate::convertFrom(const GeoCoordinate &coordinate)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    Q_ASSERT(coordinate.longitude() > MAX_LONGITUDE);
-    Q_ASSERT(coordinate.longitude() < MIN_LONGITUDE);
-    Q_ASSERT(coordinate.latitude() > MAX_LATITUDE);
-    Q_ASSERT(coordinate.latitude() < MIN_LATITUDE);
+    Q_ASSERT(coordinate.longitude() >= MIN_LONGITUDE);
+    Q_ASSERT(coordinate.longitude() <= MAX_LONGITUDE);
+    Q_ASSERT(coordinate.latitude() >= MIN_LATITUDE);
+    Q_ASSERT(coordinate.latitude() <= MAX_LATITUDE);
+
 
     // calculate x & y positions in the map (0..1)
     double worldX = static_cast<double>((coordinate.longitude() + 180.0) / 360.0);
index aecb37e..7c172fd 100644 (file)
@@ -24,6 +24,7 @@
 #define SCENECOORDINATE_H
 
 #include <QDebug>
+#include <QMetaType>
 
 class GeoCoordinate;
 
@@ -112,4 +113,6 @@ private:
 
 QDebug operator<<(QDebug dbg, const SceneCoordinate &c);
 
+Q_DECLARE_METATYPE(SceneCoordinate)
+
 #endif // SCENECOORDINATE_H
index 6f5f422..710d2a7 100644 (file)
@@ -87,10 +87,10 @@ const int PRESS_MANHATTAN_LENGTH = 30;   ///< Friend/group item press manhattan
 */
 const int OWN_LOCATION_ICON_Z_LEVEL = FRIEND_LOCATION_ICON_Z_LEVEL + 1;
 
-const qreal MAX_LATITUDE = 85.05112877980659237802;  ///< Maximum latitude value
-const qreal MIN_LATITUDE = -MAX_LATITUDE; ///< Minimum latitude value
-const qreal MIN_LONGITUDE = -180.0;  ///< Minimum longitude value
-const qreal MAX_LONGITUDE = 180.0;  ///< Maximum longitude value
+const double MAX_LATITUDE = 85.05112877980659237802;  ///< Maximum latitude value
+const double MIN_LATITUDE = -MAX_LATITUDE; ///< Minimum latitude value
+const double MIN_LONGITUDE = -180.0;  ///< Minimum longitude value
+const double MAX_LONGITUDE = 180.0;  ///< Maximum longitude value
 
 const int DEFAULT_ZOOM_LEVEL = 14;       ///< Default zoom level
 const qreal DEFAULT_LONGITUDE = 0.0000;  ///< Default longitude value
index c8ee955..a607c96 100644 (file)
@@ -22,6 +22,9 @@
 #include <QtCore/QString>
 #include <QtTest/QtTest>
 
+#include "coordinates/geocoordinate.h"
+#include "map/mapcommon.h"
+
 #include "coordinates/scenecoordinate.h"
 
 const double X = 12.345678;
@@ -31,20 +34,14 @@ class TestSceneCoordinate : public QObject
 {
     Q_OBJECT
 
-public:
-    TestSceneCoordinate();
-
 private Q_SLOTS:
     void constructors();
     void conversion();
+    void conversion_data();
     void isNull();
     void settersAndGetters();
 };
 
-TestSceneCoordinate::TestSceneCoordinate()
-{
-}
-
 void TestSceneCoordinate::constructors()
 {
     SceneCoordinate coordinate;
@@ -54,12 +51,32 @@ void TestSceneCoordinate::constructors()
     QCOMPARE(coordinate2.x(), X);
     QCOMPARE(coordinate2.y(), Y);
 
-    QVERIFY2(false, "constructor with conversion from GeoCoordinate is not tested");
+    // NOTE: constructor with conversion from GeoCoordinate is tested in conversion() test slot
 }
 
 void TestSceneCoordinate::conversion()
 {
-    QVERIFY2(false, "not implemented, transfer from MapEngine");
+    QFETCH(GeoCoordinate, geoCoordinate);
+    QFETCH(SceneCoordinate, result);
+
+    SceneCoordinate sceneCoordinate(geoCoordinate);
+
+    QCOMPARE(sceneCoordinate.x(), result.x());
+    QCOMPARE(sceneCoordinate.y(), result.y());
+}
+
+void TestSceneCoordinate::conversion_data()
+{
+    QTest::addColumn<GeoCoordinate>("geoCoordinate");
+    QTest::addColumn<SceneCoordinate>("result");
+
+    QTest::newRow("top left") << GeoCoordinate(MAX_LATITUDE, MIN_LONGITUDE)
+                              << SceneCoordinate(0, 0);
+
+    int x = (1 << MAX_MAP_ZOOM_LEVEL) * TILE_SIZE_X;
+    int y = (1 << MAX_MAP_ZOOM_LEVEL) * TILE_SIZE_Y;
+    QTest::newRow("bottom right") << GeoCoordinate(MIN_LATITUDE, MAX_LONGITUDE)
+                                  << SceneCoordinate(x, y);
 }
 
 void TestSceneCoordinate::isNull()