Fixed unit tests
[situare] / tests / map / mapscene / testmapscene.cpp
index 40539bf..06221ae 100644 (file)
@@ -40,18 +40,24 @@ private slots:
 */
 void TestMapScene::addMapTile()
 {
+    const int ZOOM_LEVEL_1ST = 18;
+    const int ZOOM_LEVEL_2ND = 16;
+    const QPoint TILE_INDEX_1ST = QPoint(1, 2);
+    const QPoint TILE_INDEX_2ND = QPoint(2, 3);
+
     MapScene mapScene;
 
     // First test:
     // Zoom level is 18, so no stretching should occure
     // Top-left corner x = 256, y = 512
     // Bottom-right corner x + 255, y + 255
-    MapTile *mapTile = new MapTile();
-    mapTile->setZoomLevel(18, 14);
-    mapTile->setTileNumber(QPoint(1, 2));
-    mapTile->setPixmap(QPixmap("maptile.png"));
+    mapScene.setZoomLevel(ZOOM_LEVEL_1ST);
+    mapScene.addTile(ZOOM_LEVEL_1ST, TILE_INDEX_1ST, QPixmap("maptile.png"), ZOOM_LEVEL_1ST);
 
-    mapScene.addTile(mapTile, "dymmyTestKey");
+    // Check that there is only one item in the scene and take a pointer to it
+    QCOMPARE(mapScene.items().count(), 1);
+    MapTile *tile = dynamic_cast<MapTile *>(mapScene.items().at(0));
+    QVERIFY(tile);
 
     // Check around top-left and bottom-right corners
     int x = 256;
@@ -59,8 +65,8 @@ void TestMapScene::addMapTile()
     int s = 255; //side length -1
     QCOMPARE(mapScene.itemAt(x-1, y), (QGraphicsItem *)0);
     QCOMPARE(mapScene.itemAt(x, y-1), (QGraphicsItem *)0);
-    QCOMPARE(mapScene.itemAt(x, y), dynamic_cast<QGraphicsItem *>(mapTile));
-    QCOMPARE(mapScene.itemAt(x+s, y+s), dynamic_cast<QGraphicsItem *>(mapTile));
+    QCOMPARE(mapScene.itemAt(x, y), dynamic_cast<QGraphicsItem *>(tile));
+    QCOMPARE(mapScene.itemAt(x+s, y+s), dynamic_cast<QGraphicsItem *>(tile));
     QCOMPARE(mapScene.itemAt(x+s+1, y+s), (QGraphicsItem *)0);
     QCOMPARE(mapScene.itemAt(x+s, y+s+1), (QGraphicsItem *)0);
 
@@ -68,8 +74,8 @@ void TestMapScene::addMapTile()
     // Zoom level is 16, so stretching is also tested
     // Top-left corner x = 2048, y = 3072
     // Bottom-right corner x + 1023, y + 1023
-    mapTile->setZoomLevel(16, 14);
-    mapTile->setTileNumber(QPoint(2, 3));
+    tile->setZoomLevel(ZOOM_LEVEL_2ND, ZOOM_LEVEL_2ND);
+    tile->setTileNumber(TILE_INDEX_2ND);
 
     // Check around top-left and bottom-right corners
     x = 2048;
@@ -77,8 +83,8 @@ void TestMapScene::addMapTile()
     s = 1023; //side length -1
     QCOMPARE(mapScene.itemAt(x-1, y), (QGraphicsItem *)0);
     QCOMPARE(mapScene.itemAt(x, y-1), (QGraphicsItem *)0);
-    QCOMPARE(mapScene.itemAt(x, y), dynamic_cast<QGraphicsItem *>(mapTile));
-    QCOMPARE(mapScene.itemAt(x+s, y+s), dynamic_cast<QGraphicsItem *>(mapTile));
+    QCOMPARE(mapScene.itemAt(x, y), dynamic_cast<QGraphicsItem *>(tile));
+    QCOMPARE(mapScene.itemAt(x+s, y+s), dynamic_cast<QGraphicsItem *>(tile));
     QCOMPARE(mapScene.itemAt(x+s+1, y+s), (QGraphicsItem *)0);
     QCOMPARE(mapScene.itemAt(x+s, y+s+1), (QGraphicsItem *)0);
 }