From 8641bdd614e78cd6905a72349e46c8fcdb91cc41 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sami=20R=C3=A4m=C3=B6?= Date: Fri, 11 Jun 2010 11:07:18 +0300 Subject: [PATCH] Fixed unit tests --- src/map/mapcommon.h | 2 +- tests/map/mapengine/testmapengine.cpp | 7 +++-- tests/map/mapscene/testmapscene.cpp | 28 +++++++++++-------- tests/map/maptile/testmaptile.cpp | 31 +++++++++++---------- tests/map/ownlocationitem/testownlocationitem.cpp | 5 ++-- 5 files changed, 43 insertions(+), 30 deletions(-) diff --git a/src/map/mapcommon.h b/src/map/mapcommon.h index d3ced3f..89cd3c3 100644 --- a/src/map/mapcommon.h +++ b/src/map/mapcommon.h @@ -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 diff --git a/tests/map/mapengine/testmapengine.cpp b/tests/map/mapengine/testmapengine.cpp index c3b1fad..269e845 100644 --- a/tests/map/mapengine/testmapengine.cpp +++ b/tests/map/mapengine/testmapengine.cpp @@ -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(); } diff --git a/tests/map/mapscene/testmapscene.cpp b/tests/map/mapscene/testmapscene.cpp index 40539bf..06221ae 100644 --- a/tests/map/mapscene/testmapscene.cpp +++ b/tests/map/mapscene/testmapscene.cpp @@ -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(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(mapTile)); - QCOMPARE(mapScene.itemAt(x+s, y+s), dynamic_cast(mapTile)); + QCOMPARE(mapScene.itemAt(x, y), dynamic_cast(tile)); + QCOMPARE(mapScene.itemAt(x+s, y+s), dynamic_cast(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(mapTile)); - QCOMPARE(mapScene.itemAt(x+s, y+s), dynamic_cast(mapTile)); + QCOMPARE(mapScene.itemAt(x, y), dynamic_cast(tile)); + QCOMPARE(mapScene.itemAt(x+s, y+s), dynamic_cast(tile)); QCOMPARE(mapScene.itemAt(x+s+1, y+s), (QGraphicsItem *)0); QCOMPARE(mapScene.itemAt(x+s, y+s+1), (QGraphicsItem *)0); } diff --git a/tests/map/maptile/testmaptile.cpp b/tests/map/maptile/testmaptile.cpp index a9caf68..c4706ef 100644 --- a/tests/map/maptile/testmaptile.cpp +++ b/tests/map/maptile/testmaptile.cpp @@ -21,8 +21,11 @@ #include +#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("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); } /** diff --git a/tests/map/ownlocationitem/testownlocationitem.cpp b/tests/map/ownlocationitem/testownlocationitem.cpp index ac309eb..eb842dc 100644 --- a/tests/map/ownlocationitem/testownlocationitem.cpp +++ b/tests/map/ownlocationitem/testownlocationitem.cpp @@ -34,13 +34,14 @@ #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; -- 1.7.9.5