{
Q_OBJECT
private slots:
- //void convertTileNumberToSceneCoordinate();
+ void convertTileNumberToSceneCoordinate();
// void setViewLocation();
- //void convertLatLonToTile();
- // void calculateRect();
- void moveLocation();
- // void removeTilesOutOfBounds();
- void convertLatLonToSceneCoordinate();
- void calculateRect();
- void setLocation();
-// void removeTilesOutOfBounds();
- void calculateTileGrid();
- void convert();
++// void convertLatLonToSceneCoordinate();
++ void setLocationNewTilesCount();
++ void setLocationRemovedTilesCount();
+// void calculateTileGrid();
+// void convert();
};
/**
//}
/**
- * @brief Test converting real world cordinates to tile numbers
+ * @brief Test converting real world cordinates to scene coordinates
* @todo Implement
*/
- //void TestMapEngine::convertLatLonToTile()
- //{
- // QCOMPARE(MapEngine::convertLatLonToTile(7, QPointF(25.5, 65.0)), QPoint(73, 33));
- // QCOMPARE(MapEngine::convertLatLonToTile(1, QPointF(25.5, 65.0)), QPoint(1, 0));
- // QCOMPARE(MapEngine::convertLatLonToTile(1, QPointF(-190.0, 65.0)), QPoint(UNDEFINED, UNDEFINED));
- // QCOMPARE(MapEngine::convertLatLonToTile(100, QPointF(20.0, 65.0)), QPoint(UNDEFINED, UNDEFINED));
- //}
-
- //void TestMapEngine::calculateRect()
-void TestMapEngine::convertLatLonToSceneCoordinate()
-{
- QCOMPARE(MapEngine::convertLatLonToSceneCoordinate(QPointF(25.5, 65.0)), QPointF(73, 33));
- QCOMPARE(MapEngine::convertLatLonToSceneCoordinate(QPointF(25.5, 65.0)), QPointF(1, 0));
- QCOMPARE(MapEngine::convertLatLonToSceneCoordinate(QPointF(-190.0, 65.0)), QPointF(UNDEFINED, UNDEFINED));
- QCOMPARE(MapEngine::convertLatLonToSceneCoordinate(QPointF(20.0, 65.0)), QPointF(UNDEFINED, UNDEFINED));
-}
-
-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);
-}
++//void TestMapEngine::convertLatLonToSceneCoordinate()
+//{
- // MapEngine engine;
- // engine.viewResized(QSize(800, 480));
- // engine.setZoomLevel(14);
- //
- // int zoomFactor = 1 << (MAX_ZOOM_LEVEL - engine.getZoomLevel());
- //
- // QRect grid1 = QRect(-1, 0, 6, 4);
- // QCOMPARE(engine.calculateGrid(QPointF(550.23*16, 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);
++// QCOMPARE(MapEngine::convertLatLonToSceneCoordinate(QPointF(25.5, 65.0)), QPointF(73, 33));
++// QCOMPARE(MapEngine::convertLatLonToSceneCoordinate(QPointF(25.5, 65.0)), QPointF(1, 0));
++// QCOMPARE(MapEngine::convertLatLonToSceneCoordinate(QPointF(-190.0, 65.0)), QPointF(UNDEFINED, UNDEFINED));
++// QCOMPARE(MapEngine::convertLatLonToSceneCoordinate(QPointF(20.0, 65.0)), QPointF(UNDEFINED, UNDEFINED));
+//}
- void TestMapEngine::moveLocation()
-void TestMapEngine::setLocation()
++void TestMapEngine::setLocationNewTilesCount()
{
-- MapEngine engine;
- engine.setZoomLevel(14);
++ MapEngine engine;
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();
fetchImageSpy.clear();
}
- //void TestMapEngine::convert()
- //{
- // int zoomFactor = 1 << (MAX_ZOOM_LEVEL - 14);
- //
- // QPoint tileNumber = QPoint(1020, 500);
- // QPointF sceneCoordinate = QPointF(tileNumber.x()*TILE_SIZE_X*zoomFactor, tileNumber.y()*TILE_SIZE_Y*zoomFactor);
- // QPoint tile = MapEngine::convertSceneCoordinateToTileNumber(14, sceneCoordinate);
- //
- // QCOMPARE(tileNumber, tile);
- //}
-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 tile = MapEngine::convertSceneCoordinateToTileNumber(14, sceneCoordinate);
-
- QCOMPARE(tileNumber, tile);
-}
-
-void TestMapEngine::calculateTileGrid()
++void TestMapEngine::setLocationRemovedTilesCount()
+ {
+ MapEngine engine;
-
+ engine.viewResized(QSize(800, 480));
- engine.setZoomLevel(14);
- //void TestMapEngine::calculateTileGrid()
- //{
- // MapEngine engine;
- //
- // engine.viewResized(QSize(800, 480));
- // engine.setZoomLevel(14);
- //
- // int zoomFactor = 1 << (MAX_ZOOM_LEVEL - engine.getZoomLevel());
- //
- // engine.calculateTileGrid(QPointF(1020*TILE_SIZE_X*zoomFactor, 500*TILE_SIZE_X*zoomFactor));
- //}
- int zoomFactor = 1 << (MAX_MAP_ZOOM_LEVEL - engine.getZoomLevel());
++ const int maxItemsCount = 30;
- //void TestMapEngine::removeTilesOutOfBounds()
- //{
- // 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);
- //}
- engine.calculateTileGrid(QPointF(1020*TILE_SIZE_X*zoomFactor, 500*TILE_SIZE_X*zoomFactor));
-}
++ engine.setLocation(QPointF(1220.23*16, 1220.23*16));
++ QTest::qWait(1000);
++ engine.setLocation(QPointF(2220.23*16, 2220.23*16));
++ QTest::qWait(1000);
++ QVERIFY(engine.scene()->items().count() <= maxItemsCount);
+
-//void TestMapEngine::removeTilesOutOfBounds()
-//{
-// 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);
-//}
++ engine.setLocation(QPointF(520.23*16, 2220.23*16));
++ QTest::qWait(1000);
++ engine.setLocation(QPointF(2220.23*16, 520.23*16));
++ QTest::qWait(1000);
++
++ QVERIFY(engine.scene()->items().count() <= maxItemsCount);
++}
QTEST_MAIN(TestMapEngine)
#include "testmapengine.moc"