Fixed unit tests, more accurate limits for latitude coordinates.
authorSami Rämö <sami.ramo@ixonos.com>
Thu, 15 Apr 2010 12:26:44 +0000 (15:26 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Thu, 15 Apr 2010 12:26:44 +0000 (15:26 +0300)
src/common.h
tests/map/mapengine/testmapengine.cpp

index dcd3399..a794669 100644 (file)
@@ -13,8 +13,8 @@ static const int MIN_MAP_SCENE_NORMAL_LEVEL = MAX_MAP_ZOOM_LEVEL + 1;
 static const int ZOOM_FPS = 30; ///< FPS for the zoom effect
 static const qreal ZOOM_TIME = 0.25; ///< Length of the zoom effect (seconds)
 
-static const qreal MIN_LATITUDE = -85.0511; ///< Minimum latitude value
-static const qreal MAX_LATITUDE = 85.0511;  ///< Maximum latitude value
+static const qreal MAX_LATITUDE = 85.05112877980659237802;  ///< Maximum latitude value
+static const qreal MIN_LATITUDE = -MAX_LATITUDE; ///< Minimum latitude value
 static const qreal MIN_LONGITUDE = -180.0;  ///< Minimum longitude value
 static const qreal MAX_LONGITUDE = 180.0;  ///< Maximum longitude value
 
index eaf9895..d652fd8 100644 (file)
@@ -28,12 +28,11 @@ class TestMapEngine: public QObject
     Q_OBJECT
 private slots:
     void convertTileNumberToSceneCoordinate();
-//    void setViewLocation();
     void convertLatLonToSceneCoordinate_data();
     void convertLatLonToSceneCoordinate();
     void calculateRect();
     void setLocation();
-//    void removeTilesOutOfBounds();
+    void removeTilesOutOfBounds();
     void calculateTileGrid();
     void convert();
 };
@@ -51,26 +50,18 @@ void TestMapEngine::convertTileNumberToSceneCoordinate()
 }
 
 /**
-* @brief DUMMY TESTCASE!
-*
-* @todo Actual test should be added when there is something to be tested
-*/
-//void TestMapEngine::setViewLocation()
-//{
-//    MapEngine mapEngine;
-//    mapEngine.setViewLocation(QPointF(25.0000, 65.0000));
-//}
-
-/**
   * @brief Test data for converting latitude and longitude coordinates to scene coordinates
   */
 void TestMapEngine::convertLatLonToSceneCoordinate_data()
 {
     QTest::addColumn<QPointF>("coordinate");
-    QTest::addColumn<QPointF>("result");
+    QTest::addColumn<QPoint>("result");
+
+    QTest::newRow("top left") << QPointF(MIN_LONGITUDE, MAX_LATITUDE) << QPoint(0, 0);
 
-    QTest::newRow("top left") << QPointF(-180, 85.0511) << QPointF(0, 0);
-    QTest::newRow("bottom right") << QPointF(180, -85.0511) << QPointF(67108863, 67108863);
+    int x = (1 << MAX_MAP_ZOOM_LEVEL) * TILE_SIZE_X;
+    int y = (1 << MAX_MAP_ZOOM_LEVEL) * TILE_SIZE_Y;
+    QTest::newRow("bottom right") << QPointF(MAX_LONGITUDE, MIN_LATITUDE) << QPoint(x, y);
 }
 
 /**
@@ -80,56 +71,58 @@ void TestMapEngine::convertLatLonToSceneCoordinate_data()
 void TestMapEngine::convertLatLonToSceneCoordinate()
 {
     QFETCH(QPointF, coordinate);
-    QFETCH(QPointF, result);
+    QFETCH(QPoint, result);
 
     QCOMPARE(MapEngine::convertLatLonToSceneCoordinate(coordinate), result);
 }
 
 void TestMapEngine::calculateRect()
 {
-    MapEngine engine;
-    engine.viewResized(QSize(800, 480));
-    engine.setZoomLevel(14);
-
-    int zoomFactor = 1 << (MAX_MAP_ZOOM_LEVEL - engine.getZoomLevel());
-
-    QRect grid1 = QRect(-1, 0, 6, 4);
-    QCOMPARE(engine.calculateGrid(QPointF(550.23*zoomFactor, 550.23*zoomFactor)), grid1);
-
-    QRect grid2 = QRect(-3, -2, 6, 4);
-    QCOMPARE(engine.calculateGrid(QPointF(0.23*zoomFactor, 0.23*zoomFactor)), grid2);
-
-    QRect grid3 = QRect(1017, 498, 6, 4);
-    QCOMPARE(engine.calculateGrid(QPointF(1020*TILE_SIZE_X*zoomFactor, 500*TILE_SIZE_Y*zoomFactor)), grid3);
-
-    engine.viewResized(QSize(1280, 1024));
-
-    QRect grid4 = QRect(1016, 497, 8, 7);
-    QCOMPARE(engine.calculateGrid(QPointF(1020*TILE_SIZE_X*zoomFactor, 500*TILE_SIZE_Y*zoomFactor)), grid4);
+    QVERIFY(false);
+//    MapEngine engine;
+//    engine.viewResized(QSize(800, 480));
+//    engine.setZoomLevel(14);
+//
+//    int zoomFactor = 1 << (MAX_MAP_ZOOM_LEVEL - engine.getZoomLevel());
+//
+//    QRect grid1 = QRect(-1, 0, 6, 4);
+//    QCOMPARE(engine.calculateGrid(QPointF(550.23*zoomFactor, 550.23*zoomFactor)), grid1);
+//
+//    QRect grid2 = QRect(-3, -2, 6, 4);
+//    QCOMPARE(engine.calculateGrid(QPointF(0.23*zoomFactor, 0.23*zoomFactor)), grid2);
+//
+//    QRect grid3 = QRect(1017, 498, 6, 4);
+//    QCOMPARE(engine.calculateGrid(QPointF(1020*TILE_SIZE_X*zoomFactor, 500*TILE_SIZE_Y*zoomFactor)), grid3);
+//
+//    engine.viewResized(QSize(1280, 1024));
+//
+//    QRect grid4 = QRect(1016, 497, 8, 7);
+//    QCOMPARE(engine.calculateGrid(QPointF(1020*TILE_SIZE_X*zoomFactor, 500*TILE_SIZE_Y*zoomFactor)), grid4);
 }
 
 void TestMapEngine::setLocation()
 {
-    MapEngine engine;
-    engine.setZoomLevel(14);
-    engine.viewResized(QSize(800, 480));
-
-    int zoomFactor = 1 << (MAX_MAP_ZOOM_LEVEL - engine.getZoomLevel());
-
-    QSignalSpy fetchImageSpy(&engine, SIGNAL(fetchImage(QUrl)));
-    QTest::qWait(1000);
-    fetchImageSpy.clear();
-
-    engine.setLocation(QPointF(1220.23*zoomFactor, 1220.23*zoomFactor));
-    QTest::qWait(1000);
-    QCOMPARE(fetchImageSpy.count(), 6*4);
-    fetchImageSpy.clear();
-
-    //Move one tile right and one down = 9 new tiles
-    engine.setLocation(QPointF((1220.23+TILE_SIZE_X)*zoomFactor, (1220.23+TILE_SIZE_Y)*zoomFactor));
-    QTest::qWait(1000);
-    QCOMPARE(fetchImageSpy.count(), 9);
-    fetchImageSpy.clear();
+    QVERIFY(false);
+//    MapEngine engine;
+//    engine.setZoomLevel(14);
+//    engine.viewResized(QSize(800, 480));
+//
+//    int zoomFactor = 1 << (MAX_MAP_ZOOM_LEVEL - engine.getZoomLevel());
+//
+//    QSignalSpy fetchImageSpy(&engine, SIGNAL(fetchImage(QUrl)));
+//    QTest::qWait(1000);
+//    fetchImageSpy.clear();
+//
+//    engine.setLocation(QPointF(1220.23*zoomFactor, 1220.23*zoomFactor));
+//    QTest::qWait(1000);
+//    QCOMPARE(fetchImageSpy.count(), 6*4);
+//    fetchImageSpy.clear();
+//
+//    //Move one tile right and one down = 9 new tiles
+//    engine.setLocation(QPointF((1220.23+TILE_SIZE_X)*zoomFactor, (1220.23+TILE_SIZE_Y)*zoomFactor));
+//    QTest::qWait(1000);
+//    QCOMPARE(fetchImageSpy.count(), 9);
+//    fetchImageSpy.clear();
 }
 
 void TestMapEngine::convert()
@@ -137,7 +130,7 @@ void TestMapEngine::convert()
     int zoomFactor = 1 << (MAX_MAP_ZOOM_LEVEL - 14);
 
     QPoint tileNumber = QPoint(1020, 500);
-    QPointF sceneCoordinate = QPointF(tileNumber.x()*TILE_SIZE_X*zoomFactor, tileNumber.y()*TILE_SIZE_Y*zoomFactor);
+    QPoint sceneCoordinate = QPoint(tileNumber.x()*TILE_SIZE_X*zoomFactor, tileNumber.y()*TILE_SIZE_Y*zoomFactor);
     QPoint tile = MapEngine::convertSceneCoordinateToTileNumber(14, sceneCoordinate);
 
     QCOMPARE(tileNumber, tile);
@@ -145,18 +138,20 @@ void TestMapEngine::convert()
 
 void TestMapEngine::calculateTileGrid()
 {
-    MapEngine engine;
-
-    engine.viewResized(QSize(800, 480));
-    engine.setZoomLevel(14);
-
-    int zoomFactor = 1 << (MAX_MAP_ZOOM_LEVEL - engine.getZoomLevel());
-
-    engine.calculateTileGrid(QPointF(1020*TILE_SIZE_X*zoomFactor, 500*TILE_SIZE_X*zoomFactor));
+    QVERIFY(false);
+//    MapEngine engine;
+//
+//    engine.viewResized(QSize(800, 480));
+//    engine.setZoomLevel(14);
+//
+//    int zoomFactor = 1 << (MAX_MAP_ZOOM_LEVEL - engine.getZoomLevel());
+//
+//    engine.calculateTileGrid(QPointF(1020*TILE_SIZE_X*zoomFactor, 500*TILE_SIZE_X*zoomFactor));
 }
 
-//void TestMapEngine::removeTilesOutOfBounds()
-//{
+void TestMapEngine::removeTilesOutOfBounds()
+{
+    QVERIFY(false);
 //    MapEngine engine;
 //    engine.viewResized(QSize(800, 480));
 //    engine.setZoomLevel(14);
@@ -169,7 +164,7 @@ void TestMapEngine::calculateTileGrid()
 //    //Move one tile right and one tile down
 //    engine.setLocation(QPointF((1220.23+TILE_SIZE_X)*zoomFactor, (1220.23+TILE_SIZE_Y)*zoomFactor));
 //    QCOMPARE(engine.scene()->items().count(), 15);
-//}
+}
 
 QTEST_MAIN(TestMapEngine)
 #include "testmapengine.moc"