Merge branch 'map' of https://vcs.maemo.org/git/situare into map
[situare] / tests / map / mapengine / testmapengine.cpp
index d652fd8..40e785e 100644 (file)
@@ -30,11 +30,10 @@ private slots:
     void convertTileNumberToSceneCoordinate();
     void convertLatLonToSceneCoordinate_data();
     void convertLatLonToSceneCoordinate();
-    void calculateRect();
-    void setLocation();
-    void removeTilesOutOfBounds();
-    void calculateTileGrid();
-    void convert();
+    void setLocationNewTilesCount();
+    void setLocationRemovedTilesCount();
+    void zoomOutRemovedTilesCount();
+    void zoomInRemovedTilesCount();
 };
 
 /**
@@ -76,94 +75,86 @@ void TestMapEngine::convertLatLonToSceneCoordinate()
     QCOMPARE(MapEngine::convertLatLonToSceneCoordinate(coordinate), result);
 }
 
-void TestMapEngine::calculateRect()
+void TestMapEngine::setLocationNewTilesCount()
 {
-    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);
+       MapEngine engine;
+    engine.viewResized(QSize(800, 480));
+
+    QSignalSpy fetchImageSpy(&engine, SIGNAL(fetchImage(QUrl)));
+    QTest::qWait(1000);
+    fetchImageSpy.clear();
+
+    engine.setLocation(QPoint(1220*16, 1220*16));
+    QTest::qWait(1000);
+    QCOMPARE(fetchImageSpy.count(), 6*4);
+    fetchImageSpy.clear();
+
+    engine.setLocation(QPoint((1220+TILE_SIZE_X)*16, (1220+TILE_SIZE_Y)*16));
+    QTest::qWait(1000);
+    QCOMPARE(fetchImageSpy.count(), 9);
+    fetchImageSpy.clear();
 }
 
-void TestMapEngine::setLocation()
+void TestMapEngine::setLocationRemovedTilesCount()
 {
-    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();
-}
+    MapEngine engine;
+    engine.viewResized(QSize(800, 480));
 
-void TestMapEngine::convert()
-{
-    int zoomFactor = 1 << (MAX_MAP_ZOOM_LEVEL - 14);
+    const int maxItemsCount = 30;
+
+    engine.setLocation(QPoint(1220*16, 1220*16));
+    QTest::qWait(1000);
+    engine.setLocation(QPoint(2220*16, 2220*16));
+    QTest::qWait(1000);
+    QVERIFY(engine.scene()->items().count() <= maxItemsCount);
 
-    QPoint tileNumber = QPoint(1020, 500);
-    QPoint sceneCoordinate = QPoint(tileNumber.x()*TILE_SIZE_X*zoomFactor, tileNumber.y()*TILE_SIZE_Y*zoomFactor);
-    QPoint tile = MapEngine::convertSceneCoordinateToTileNumber(14, sceneCoordinate);
+    engine.setLocation(QPoint(520*16, 2220*16));
+    QTest::qWait(1000);
+    engine.setLocation(QPoint(2220*16, 520*16));
+    QTest::qWait(1000);
 
-    QCOMPARE(tileNumber, tile);
+    QVERIFY(engine.scene()->items().count() <= maxItemsCount);
 }
 
-void TestMapEngine::calculateTileGrid()
+void TestMapEngine::zoomInRemovedTilesCount()
 {
-    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));
+    MapEngine engine;
+    engine.viewResized(QSize(800, 480));
+
+    const int maxItemsCount = 30;
+
+    engine.setLocation(QPoint(1220*16, 1220*16));
+    QTest::qWait(1000);
+    QTest::qWait(1000);
+    QVERIFY(engine.scene()->items().count() <= maxItemsCount);
+
+    engine.setLocation(QPoint(520*16, 2220*16));
+    QTest::qWait(1000);
+    engine.setLocation(QPoint(2220*16, 520*16));
+    QTest::qWait(1000);
+
+    QVERIFY(engine.scene()->items().count() <= maxItemsCount);
 }
 
-void TestMapEngine::removeTilesOutOfBounds()
+void TestMapEngine::zoomOutRemovedTilesCount()
 {
-    QVERIFY(false);
-//    MapEngine engine;
-//    engine.viewResized(QSize(800, 480));
-//    engine.setZoomLevel(14);
-//
-//    int zoomFactor = 1 << (MAX_ZOOM_LEVEL - engine.getZoomLevel());
-//
-//    engine.setLocation(QPointF(1220.23*zoomFactor, 1220.23*zoomFactor));
-//    qDebug() << "Scene items: " << engine.scene()->items().count();
-//    QTest::qWait(1000);
-//    //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);
+    MapEngine engine;
+    engine.viewResized(QSize(800, 480));
+
+    const int maxItemsCount = 30;
+
+    engine.setLocation(QPoint(1220*16, 1220.23*16));
+    QTest::qWait(1000);
+    engine.setLocation(QPoint(2220*16, 2220.23*16));
+    QTest::qWait(1000);
+    QVERIFY(engine.scene()->items().count() <= maxItemsCount);
+
+    engine.setLocation(QPoint(520*16, 2220*16));
+    QTest::qWait(1000);
+    engine.setLocation(QPoint(2220*16, 520*16));
+    QTest::qWait(1000);
+
+    QVERIFY(engine.scene()->items().count() <= maxItemsCount);
 }
 
 QTEST_MAIN(TestMapEngine)