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 convertLatLonToSceneCoordinate_data();
32 void convertLatLonToSceneCoordinate();
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 Test data for converting latitude and longitude coordinates to scene coordinates
55 void TestMapEngine::convertLatLonToSceneCoordinate_data()
57 QTest::addColumn<QPointF>("coordinate");
58 QTest::addColumn<QPoint>("result");
60 QTest::newRow("top left") << QPointF(MIN_LONGITUDE, MAX_LATITUDE) << QPoint(0, 0);
62 int x = (1 << MAX_MAP_ZOOM_LEVEL) * TILE_SIZE_X;
63 int y = (1 << MAX_MAP_ZOOM_LEVEL) * TILE_SIZE_Y;
64 QTest::newRow("bottom right") << QPointF(MAX_LONGITUDE, MIN_LATITUDE) << QPoint(x, y);
68 * @brief Test converting real world cordinates to scene coordinates
71 void TestMapEngine::convertLatLonToSceneCoordinate()
73 QFETCH(QPointF, coordinate);
74 QFETCH(QPoint, result);
76 QCOMPARE(MapEngine::convertLatLonToSceneCoordinate(coordinate), result);
79 void TestMapEngine::calculateRect()
83 // engine.viewResized(QSize(800, 480));
84 // engine.setZoomLevel(14);
86 // int zoomFactor = 1 << (MAX_MAP_ZOOM_LEVEL - engine.getZoomLevel());
88 // QRect grid1 = QRect(-1, 0, 6, 4);
89 // QCOMPARE(engine.calculateGrid(QPointF(550.23*zoomFactor, 550.23*zoomFactor)), grid1);
91 // QRect grid2 = QRect(-3, -2, 6, 4);
92 // QCOMPARE(engine.calculateGrid(QPointF(0.23*zoomFactor, 0.23*zoomFactor)), grid2);
94 // QRect grid3 = QRect(1017, 498, 6, 4);
95 // QCOMPARE(engine.calculateGrid(QPointF(1020*TILE_SIZE_X*zoomFactor, 500*TILE_SIZE_Y*zoomFactor)), grid3);
97 // engine.viewResized(QSize(1280, 1024));
99 // QRect grid4 = QRect(1016, 497, 8, 7);
100 // QCOMPARE(engine.calculateGrid(QPointF(1020*TILE_SIZE_X*zoomFactor, 500*TILE_SIZE_Y*zoomFactor)), grid4);
103 void TestMapEngine::setLocation()
107 // engine.setZoomLevel(14);
108 // engine.viewResized(QSize(800, 480));
110 // int zoomFactor = 1 << (MAX_MAP_ZOOM_LEVEL - engine.getZoomLevel());
112 // QSignalSpy fetchImageSpy(&engine, SIGNAL(fetchImage(QUrl)));
113 // QTest::qWait(1000);
114 // fetchImageSpy.clear();
116 // engine.setLocation(QPointF(1220.23*zoomFactor, 1220.23*zoomFactor));
117 // QTest::qWait(1000);
118 // QCOMPARE(fetchImageSpy.count(), 6*4);
119 // fetchImageSpy.clear();
121 // //Move one tile right and one down = 9 new tiles
122 // engine.setLocation(QPointF((1220.23+TILE_SIZE_X)*zoomFactor, (1220.23+TILE_SIZE_Y)*zoomFactor));
123 // QTest::qWait(1000);
124 // QCOMPARE(fetchImageSpy.count(), 9);
125 // fetchImageSpy.clear();
128 void TestMapEngine::convert()
130 int zoomFactor = 1 << (MAX_MAP_ZOOM_LEVEL - 14);
132 QPoint tileNumber = QPoint(1020, 500);
133 QPoint sceneCoordinate = QPoint(tileNumber.x()*TILE_SIZE_X*zoomFactor, tileNumber.y()*TILE_SIZE_Y*zoomFactor);
134 QPoint tile = MapEngine::convertSceneCoordinateToTileNumber(14, sceneCoordinate);
136 QCOMPARE(tileNumber, tile);
139 void TestMapEngine::calculateTileGrid()
144 // engine.viewResized(QSize(800, 480));
145 // engine.setZoomLevel(14);
147 // int zoomFactor = 1 << (MAX_MAP_ZOOM_LEVEL - engine.getZoomLevel());
149 // engine.calculateTileGrid(QPointF(1020*TILE_SIZE_X*zoomFactor, 500*TILE_SIZE_X*zoomFactor));
152 void TestMapEngine::removeTilesOutOfBounds()
156 // engine.viewResized(QSize(800, 480));
157 // engine.setZoomLevel(14);
159 // int zoomFactor = 1 << (MAX_ZOOM_LEVEL - engine.getZoomLevel());
161 // engine.setLocation(QPointF(1220.23*zoomFactor, 1220.23*zoomFactor));
162 // qDebug() << "Scene items: " << engine.scene()->items().count();
163 // QTest::qWait(1000);
164 // //Move one tile right and one tile down
165 // engine.setLocation(QPointF((1220.23+TILE_SIZE_X)*zoomFactor, (1220.23+TILE_SIZE_Y)*zoomFactor));
166 // QCOMPARE(engine.scene()->items().count(), 15);
169 QTEST_MAIN(TestMapEngine)
170 #include "testmapengine.moc"