Fixed unit tests
authorSami Rämö <sami.ramo@ixonos.com>
Fri, 11 Jun 2010 08:07:18 +0000 (11:07 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Fri, 11 Jun 2010 08:07:18 +0000 (11:07 +0300)
src/map/mapcommon.h
tests/map/mapengine/testmapengine.cpp
tests/map/mapscene/testmapscene.cpp
tests/map/maptile/testmaptile.cpp
tests/map/ownlocationitem/testownlocationitem.cpp

index d3ced3f..89cd3c3 100644 (file)
@@ -102,6 +102,6 @@ const QString ERROR_VALUE_NOT_FOUND_ON_SETTINGS = "Value_not_found";
 * @var UNDEFINED
 * @brief Value to be used when zoom level, tile numbers or position are not defined
 */
-const int UNDEFINED = -1;
+const int UNDEFINED = INT_MIN;
 
 #endif // MAPCOMMON_H
index c3b1fad..269e845 100644 (file)
@@ -93,14 +93,17 @@ void TestMapEngine::setLocationNewTilesCount()
     QTest::qWait(1000);
     fetchImageSpy.clear();
 
+    // first test, scene is empty so all tiles should be downloaded
     engine.setLocation(QPoint(1220*16, 1220*16));
     QTest::qWait(1000);
-    QCOMPARE(fetchImageSpy.count(), 6*4);
+    QCOMPARE(fetchImageSpy.count(), 5*4);
     fetchImageSpy.clear();
 
+    // move one tile to east and south, only most right one column and most bottom one row tiles
+    // should be downloaded
     engine.setLocation(QPoint((1220+TILE_SIZE_X)*16, (1220+TILE_SIZE_Y)*16));
     QTest::qWait(1000);
-    QCOMPARE(fetchImageSpy.count(), 9);
+    QCOMPARE(fetchImageSpy.count(), 4 + 4);
     fetchImageSpy.clear();
 }
 
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);
 }
index a9caf68..c4706ef 100644 (file)
 
 #include <QtTest/QtTest>
 
+#include "map/mapcommon.h"
 #include "map/maptile.h"
 
+const QPointF UNDEFINED_POSITION(UNDEFINED, UNDEFINED);
+
 class TestMapTile : public QObject
 {
     Q_OBJECT
@@ -30,7 +33,7 @@ private slots:
     void zoomLevel();
     void tileNumber();
     void position_data();
-    void position();    
+    void position();
     void positionUnsetValues();
     void sceneLevel_data();
     void sceneLevel();
@@ -66,20 +69,20 @@ void TestMapTile::position_data()
     QTest::addColumn<QPointF>("result");
 
     QTest::newRow("allowed values") << 16 << QPoint(24, 17) << QPointF(24576, 17408); //ok
-    QTest::newRow("x position negative") << 16 << QPoint(-1, 0) << QPointF(-1, -1); //fail
-    QTest::newRow("y position negative") << 16 << QPoint(0, -1) << QPointF(-1, -1); //fail
+    QTest::newRow("x position negative") << 16 << QPoint(-1, 0) << QPointF(-1024, 0); //ok
+    QTest::newRow("y position negative") << 16 << QPoint(0, -1) << UNDEFINED_POSITION; //fail
 
     QTest::newRow("min zoom") << 0 << QPoint(0, 0) << QPointF(0, 0); //ok
-    QTest::newRow("min zoom - 1") << -1 << QPoint(0, 0) << QPointF(-1, -1); //fail
-    QTest::newRow("min zoom & x out of range (upper limit)") << 0 << QPoint(1, 0) << QPointF(-1, -1); //fail
-    QTest::newRow("min zoom & y out of range (upper limit)") << 0 << QPoint(0, 1) << QPointF(-1, -1); //fail
-    QTest::newRow("min zoom, x & y out of range (upper limit)") << 0 << QPoint(1, 1) << QPointF(-1, -1); //fail
+    QTest::newRow("min zoom - 1") << -1 << QPoint(0, 0) << UNDEFINED_POSITION; //fail
+    QTest::newRow("min zoom & x out of world (east)") << 0 << QPoint(1, 0) << QPointF(256*(1<<18), 0); //ok
+    QTest::newRow("min zoom & y out of range (upper limit)") << 0 << QPoint(0, 1) << UNDEFINED_POSITION; //fail
+    QTest::newRow("min zoom, x & y out of range (upper limit)") << 0 << QPoint(1, 1) << UNDEFINED_POSITION; //fail
 
     QTest::newRow("max zoom") << 18 << QPoint(2, 3) << QPointF(512, 768); //ok
-    QTest::newRow("max zoom + 1") << 19 << QPoint(2, 3) << QPointF(-1, -1); //fail
-    QTest::newRow("max zoom & x out of range (upper limit)") << 18 << QPoint(262144, 0) << QPointF(-1, -1); //fail
-    QTest::newRow("max zoom & y out of range (upper limit)") << 18 << QPoint(0, 262144) << QPointF(-1, -1); //fail
-    QTest::newRow("max zoom, x & y out of range(upper limit) ") << 18 << QPoint(262144, 262144) << QPointF(-1, -1); //fail
+    QTest::newRow("max zoom + 1") << 19 << QPoint(2, 3) << UNDEFINED_POSITION; //fail
+    QTest::newRow("max zoom & x out of world (east)") << 18 << QPoint(262144, 0) << QPointF(256*(1<<18), 0); //ok
+    QTest::newRow("max zoom & y out of range (upper limit)") << 18 << QPoint(0, 262144) << UNDEFINED_POSITION; //fail
+    QTest::newRow("max zoom, x & y out of range(upper limit) ") << 18 << QPoint(262144, 262144) << UNDEFINED_POSITION; //fail
 }
 
 /**
@@ -105,11 +108,11 @@ void TestMapTile::positionUnsetValues()
     MapTile mapTile;
 
     // zoom level and tile numbers unset
-    QCOMPARE(mapTile.pos(), QPointF(-1, -1));
+    QCOMPARE(mapTile.pos(), UNDEFINED_POSITION);
 
     // only tile numbers set
     mapTile.setTileNumber(QPoint(24, 17));
-    QCOMPARE(mapTile.pos(), QPointF(-1, -1));
+    QCOMPARE(mapTile.pos(), UNDEFINED_POSITION);
 
     // both set
     mapTile.setZoomLevel(16, 14);
@@ -118,7 +121,7 @@ void TestMapTile::positionUnsetValues()
     // only zoom level set
     MapTile anotherMapTile;
     anotherMapTile.setZoomLevel(14, 14);
-    QCOMPARE(anotherMapTile.pos(), QPointF(-1, -1));
+    QCOMPARE(anotherMapTile.pos(), UNDEFINED_POSITION);
 }
 
 /**
index ac309eb..eb842dc 100644 (file)
 #include "map/friendlocationitem.h"
 
 namespace TestOwnLocation  //  Test data for function is defined in namespace
-{   
+{
     const qreal xCoordinate = 65.525;
     const qreal yCoordinate = 25.345;
     const QPointF testLocationPoint(65.525, 25.345);
     const QPointF defaultLocationPoint(UNDEFINED, UNDEFINED);
+    const int MAP_OWN_LOCATION_ICON_SIZE = 24;
     const QPointF locationIconOffset(-MAP_OWN_LOCATION_ICON_SIZE/2, -MAP_OWN_LOCATION_ICON_SIZE/2);
-    const int itemIgnoresTransformationsFlagValue = 0x20;    
+    const int itemIgnoresTransformationsFlagValue = 0x20;
 }
 
 using namespace TestOwnLocation;