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 <QGraphicsScene>
23 #include <QtTest/QtTest>
25 #include "map/mapcommon.h"
26 #include "map/mapengine.h"
28 class TestMapEngine: public QObject
33 void convertTileNumberToSceneCoordinate();
34 void convertLatLonToSceneCoordinate_data();
35 void convertLatLonToSceneCoordinate();
36 void setLocationNewTilesCount();
37 void setLocationRemovedTilesCount();
38 void zoomOutRemovedTilesCount();
39 void zoomInRemovedTilesCount();
43 * @brief Test converting tile numbers to scene coordinates
45 * Different zoom levels are also tested
47 void TestMapEngine::convertTileNumberToSceneCoordinate()
49 QCOMPARE(MapEngine::convertTileNumberToSceneCoordinate(18, QPoint(0,0)), QPoint(0,0));
50 QCOMPARE(MapEngine::convertTileNumberToSceneCoordinate(18, QPoint(1,2)), QPoint(256,512));
51 QCOMPARE(MapEngine::convertTileNumberToSceneCoordinate(16, QPoint(3,4)), QPoint(3072,4096));
55 * @brief Test data for converting latitude and longitude coordinates to scene coordinates
57 void TestMapEngine::convertLatLonToSceneCoordinate_data()
59 QTest::addColumn<QPointF>("coordinate");
60 QTest::addColumn<QPoint>("result");
62 QTest::newRow("top left") << QPointF(MIN_LONGITUDE, MAX_LATITUDE) << QPoint(0, 0);
64 int x = (1 << MAX_MAP_ZOOM_LEVEL) * TILE_SIZE_X;
65 int y = (1 << MAX_MAP_ZOOM_LEVEL) * TILE_SIZE_Y;
66 QTest::newRow("bottom right") << QPointF(MAX_LONGITUDE, MIN_LATITUDE) << QPoint(x, y);
70 * @brief Test converting real world cordinates to scene coordinates
73 void TestMapEngine::convertLatLonToSceneCoordinate()
75 QFETCH(QPointF, coordinate);
76 QFETCH(QPoint, result);
78 QCOMPARE(MapEngine::convertLatLonToSceneCoordinate(coordinate), result);
81 void TestMapEngine::setLocationNewTilesCount()
84 engine.viewResized(QSize(800, 480));
86 QSignalSpy fetchImageSpy(&engine, SIGNAL(fetchImage(int,int,int)));
88 fetchImageSpy.clear();
90 engine.setLocation(QPoint(1220*16, 1220*16));
92 QCOMPARE(fetchImageSpy.count(), 6*4);
93 fetchImageSpy.clear();
95 engine.setLocation(QPoint((1220+TILE_SIZE_X)*16, (1220+TILE_SIZE_Y)*16));
97 QCOMPARE(fetchImageSpy.count(), 9);
98 fetchImageSpy.clear();
101 void TestMapEngine::setLocationRemovedTilesCount()
104 engine.viewResized(QSize(800, 480));
106 const int maxItemsCount = 40;
108 engine.setLocation(QPoint(1220*16, 1220*16));
110 engine.setLocation(QPoint(2220*16, 2220*16));
112 QVERIFY(engine.scene()->items().count() <= maxItemsCount);
114 engine.setLocation(QPoint(520*16, 2220*16));
116 engine.setLocation(QPoint(2220*16, 520*16));
119 QVERIFY(engine.scene()->items().count() <= maxItemsCount);
122 void TestMapEngine::zoomInRemovedTilesCount()
125 engine.viewResized(QSize(800, 480));
127 const int maxItemsCount = 40;
129 engine.setLocation(QPoint(1220*16, 1220*16));
132 QVERIFY(engine.scene()->items().count() <= maxItemsCount);
134 engine.setLocation(QPoint(520*16, 2220*16));
136 engine.setLocation(QPoint(2220*16, 520*16));
139 QVERIFY(engine.scene()->items().count() <= maxItemsCount);
142 void TestMapEngine::zoomOutRemovedTilesCount()
145 engine.viewResized(QSize(800, 480));
147 const int maxItemsCount = 40;
149 engine.setLocation(QPoint(1220*16, 1220.23*16));
151 engine.setLocation(QPoint(2220*16, 2220.23*16));
153 QVERIFY(engine.scene()->items().count() <= maxItemsCount);
155 engine.setLocation(QPoint(520*16, 2220*16));
157 engine.setLocation(QPoint(2220*16, 520*16));
160 QVERIFY(engine.scene()->items().count() <= maxItemsCount);
163 QTEST_MAIN(TestMapEngine)
164 #include "testmapengine.moc"