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();
33 void setLocationNewTilesCount();
34 void setLocationRemovedTilesCount();
35 void zoomOutRemovedTilesCount();
36 void zoomInRemovedTilesCount();
40 * @brief Test converting tile numbers to scene coordinates
42 * Different zoom levels are also tested
44 void TestMapEngine::convertTileNumberToSceneCoordinate()
46 QCOMPARE(MapEngine::convertTileNumberToSceneCoordinate(18, QPoint(0,0)), QPoint(0,0));
47 QCOMPARE(MapEngine::convertTileNumberToSceneCoordinate(18, QPoint(1,2)), QPoint(256,512));
48 QCOMPARE(MapEngine::convertTileNumberToSceneCoordinate(16, QPoint(3,4)), QPoint(3072,4096));
52 * @brief Test data for converting latitude and longitude coordinates to scene coordinates
54 void TestMapEngine::convertLatLonToSceneCoordinate_data()
56 QTest::addColumn<QPointF>("coordinate");
57 QTest::addColumn<QPoint>("result");
59 QTest::newRow("top left") << QPointF(MIN_LONGITUDE, MAX_LATITUDE) << QPoint(0, 0);
61 int x = (1 << MAX_MAP_ZOOM_LEVEL) * TILE_SIZE_X;
62 int y = (1 << MAX_MAP_ZOOM_LEVEL) * TILE_SIZE_Y;
63 QTest::newRow("bottom right") << QPointF(MAX_LONGITUDE, MIN_LATITUDE) << QPoint(x, y);
67 * @brief Test converting real world cordinates to scene coordinates
70 void TestMapEngine::convertLatLonToSceneCoordinate()
72 QFETCH(QPointF, coordinate);
73 QFETCH(QPoint, result);
75 QCOMPARE(MapEngine::convertLatLonToSceneCoordinate(coordinate), result);
78 void TestMapEngine::setLocationNewTilesCount()
81 engine.viewResized(QSize(800, 480));
83 QSignalSpy fetchImageSpy(&engine, SIGNAL(fetchImage(int,int,int)));
85 fetchImageSpy.clear();
87 engine.setLocation(QPoint(1220*16, 1220*16));
89 QCOMPARE(fetchImageSpy.count(), 6*4);
90 fetchImageSpy.clear();
92 engine.setLocation(QPoint((1220+TILE_SIZE_X)*16, (1220+TILE_SIZE_Y)*16));
94 QCOMPARE(fetchImageSpy.count(), 9);
95 fetchImageSpy.clear();
98 void TestMapEngine::setLocationRemovedTilesCount()
101 engine.viewResized(QSize(800, 480));
103 const int maxItemsCount = 40;
105 engine.setLocation(QPoint(1220*16, 1220*16));
107 engine.setLocation(QPoint(2220*16, 2220*16));
109 QVERIFY(engine.scene()->items().count() <= maxItemsCount);
111 engine.setLocation(QPoint(520*16, 2220*16));
113 engine.setLocation(QPoint(2220*16, 520*16));
116 QVERIFY(engine.scene()->items().count() <= maxItemsCount);
119 void TestMapEngine::zoomInRemovedTilesCount()
122 engine.viewResized(QSize(800, 480));
124 const int maxItemsCount = 40;
126 engine.setLocation(QPoint(1220*16, 1220*16));
129 QVERIFY(engine.scene()->items().count() <= maxItemsCount);
131 engine.setLocation(QPoint(520*16, 2220*16));
133 engine.setLocation(QPoint(2220*16, 520*16));
136 QVERIFY(engine.scene()->items().count() <= maxItemsCount);
139 void TestMapEngine::zoomOutRemovedTilesCount()
142 engine.viewResized(QSize(800, 480));
144 const int maxItemsCount = 40;
146 engine.setLocation(QPoint(1220*16, 1220.23*16));
148 engine.setLocation(QPoint(2220*16, 2220.23*16));
150 QVERIFY(engine.scene()->items().count() <= maxItemsCount);
152 engine.setLocation(QPoint(520*16, 2220*16));
154 engine.setLocation(QPoint(2220*16, 520*16));
157 QVERIFY(engine.scene()->items().count() <= maxItemsCount);
160 QTEST_MAIN(TestMapEngine)
161 #include "testmapengine.moc"