2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Sami Rämö - sami.ramo@ixonos.com
7 Situare is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
11 Situare is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Situare; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 #include <QtTest/QtTest>
24 #include "map/mapengine.h"
26 class TestMapEngine: public QObject
30 //void convertTileNumberToSceneCoordinate();
31 // void setViewLocation();
32 //void convertLatLonToTile();
35 // void removeTilesOutOfBounds();
36 void calculateTileGrid();
41 * @brief Test converting tile numbers to scene coordinates
43 * Different zoom levels are also tested
45 //void TestMapEngine::convertTileNumberToSceneCoordinate()
47 // QCOMPARE(MapEngine::convertTileNumberToSceneCoordinate(18, QPoint(0,0)), QPoint(0,0));
48 // QCOMPARE(MapEngine::convertTileNumberToSceneCoordinate(18, QPoint(1,2)), QPoint(256,512));
49 // QCOMPARE(MapEngine::convertTileNumberToSceneCoordinate(16, QPoint(3,4)), QPoint(3072,4096));
53 * @brief DUMMY TESTCASE!
55 * @todo Actual test should be added when there is something to be tested
57 //void TestMapEngine::setViewLocation()
59 // MapEngine mapEngine;
60 // mapEngine.setViewLocation(QPointF(25.0000, 65.0000));
64 * @brief Test converting real world cordinates to tile numbers
67 //void TestMapEngine::convertLatLonToTile()
69 // QCOMPARE(MapEngine::convertLatLonToTile(7, QPointF(25.5, 65.0)), QPoint(73, 33));
70 // QCOMPARE(MapEngine::convertLatLonToTile(1, QPointF(25.5, 65.0)), QPoint(1, 0));
71 // QCOMPARE(MapEngine::convertLatLonToTile(1, QPointF(-190.0, 65.0)), QPoint(UNDEFINED, UNDEFINED));
72 // QCOMPARE(MapEngine::convertLatLonToTile(100, QPointF(20.0, 65.0)), QPoint(UNDEFINED, UNDEFINED));
75 void TestMapEngine::calculateRect()
78 engine.viewResized(QSize(800, 480));
79 engine.setZoomLevel(14);
81 int zoomFactor = 1 << (MAX_ZOOM_LEVEL - engine.getZoomLevel());
83 QRect grid1 = QRect(-1, 0, 6, 4);
84 QCOMPARE(engine.calculateGrid(QPointF(550.23*zoomFactor, 550.23*zoomFactor)), grid1);
86 QRect grid2 = QRect(-3, -2, 6, 4);
87 QCOMPARE(engine.calculateGrid(QPointF(0.23*zoomFactor, 0.23*zoomFactor)), grid2);
89 QRect grid3 = QRect(1017, 498, 6, 4);
90 QCOMPARE(engine.calculateGrid(QPointF(1020*TILE_SIZE_X*zoomFactor, 500*TILE_SIZE_Y*zoomFactor)), grid3);
92 engine.viewResized(QSize(1280, 1024));
94 QRect grid4 = QRect(1016, 497, 8, 7);
95 QCOMPARE(engine.calculateGrid(QPointF(1020*TILE_SIZE_X*zoomFactor, 500*TILE_SIZE_Y*zoomFactor)), grid4);
98 void TestMapEngine::setLocation()
101 engine.setZoomLevel(14);
102 engine.viewResized(QSize(800, 480));
104 int zoomFactor = 1 << (MAX_ZOOM_LEVEL - engine.getZoomLevel());
106 QSignalSpy fetchImageSpy(&engine, SIGNAL(fetchImage(QUrl)));
108 fetchImageSpy.clear();
110 engine.setLocation(QPointF(1220.23*zoomFactor, 1220.23*zoomFactor));
112 QCOMPARE(fetchImageSpy.count(), 6*4);
113 fetchImageSpy.clear();
115 //Move one tile right and one down = 9 new tiles
116 engine.setLocation(QPointF((1220.23+TILE_SIZE_X)*zoomFactor, (1220.23+TILE_SIZE_Y)*zoomFactor));
118 QCOMPARE(fetchImageSpy.count(), 9);
119 fetchImageSpy.clear();
122 void TestMapEngine::convert()
124 int zoomFactor = 1 << (MAX_ZOOM_LEVEL - 14);
126 QPoint tileNumber = QPoint(1020, 500);
127 QPointF sceneCoordinate = QPointF(tileNumber.x()*TILE_SIZE_X*zoomFactor, tileNumber.y()*TILE_SIZE_Y*zoomFactor);
128 QPoint tile = MapEngine::convertSceneCoordinateToTileNumber(14, sceneCoordinate);
130 QCOMPARE(tileNumber, tile);
133 void TestMapEngine::calculateTileGrid()
137 engine.viewResized(QSize(800, 480));
138 engine.setZoomLevel(14);
140 int zoomFactor = 1 << (MAX_ZOOM_LEVEL - engine.getZoomLevel());
142 engine.calculateTileGrid(QPointF(1020*TILE_SIZE_X*zoomFactor, 500*TILE_SIZE_X*zoomFactor));
145 //void TestMapEngine::removeTilesOutOfBounds()
148 // engine.viewResized(QSize(800, 480));
149 // engine.setZoomLevel(14);
151 // int zoomFactor = 1 << (MAX_ZOOM_LEVEL - engine.getZoomLevel());
153 // engine.setLocation(QPointF(1220.23*zoomFactor, 1220.23*zoomFactor));
154 // qDebug() << "Scene items: " << engine.scene()->items().count();
155 // QTest::qWait(1000);
156 // //Move one tile right and one tile down
157 // engine.setLocation(QPointF((1220.23+TILE_SIZE_X)*zoomFactor, (1220.23+TILE_SIZE_Y)*zoomFactor));
158 // QCOMPARE(engine.scene()->items().count(), 15);
161 QTEST_MAIN(TestMapEngine)
162 #include "testmapengine.moc"