Removed obsolete unittest
[situare] / tests / map / mapengine / testmapengine.cpp
1 /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Sami Rämö - sami.ramo@ixonos.com
6
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.
10
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.
15
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,
19     USA.
20 */
21
22 #include <QtTest/QtTest>
23
24 #include "map/mapengine.h"
25
26 class TestMapEngine: public QObject
27 {
28     Q_OBJECT
29 private slots:
30     void convertTileNumberToSceneCoordinate();
31     void convertLatLonToSceneCoordinate_data();
32     void convertLatLonToSceneCoordinate();
33     void setLocationNewTilesCount();
34     void setLocationRemovedTilesCount();
35     void zoomOutRemovedTilesCount();
36     void zoomInRemovedTilesCount();
37 };
38
39 /**
40 * @brief Test converting tile numbers to scene coordinates
41 *
42 * Different zoom levels are also tested
43 */
44 void TestMapEngine::convertTileNumberToSceneCoordinate()
45 {
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));
49 }
50
51 /**
52   * @brief Test data for converting latitude and longitude coordinates to scene coordinates
53   */
54 void TestMapEngine::convertLatLonToSceneCoordinate_data()
55 {
56     QTest::addColumn<QPointF>("coordinate");
57     QTest::addColumn<QPoint>("result");
58
59     QTest::newRow("top left") << QPointF(MIN_LONGITUDE, MAX_LATITUDE) << QPoint(0, 0);
60
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);
64 }
65
66 /**
67 * @brief Test converting real world cordinates to scene coordinates
68 * @todo Implement
69 */
70 void TestMapEngine::convertLatLonToSceneCoordinate()
71 {
72     QFETCH(QPointF, coordinate);
73     QFETCH(QPoint, result);
74
75     QCOMPARE(MapEngine::convertLatLonToSceneCoordinate(coordinate), result);
76 }
77
78 void TestMapEngine::setLocationNewTilesCount()
79 {
80     MapEngine engine;
81     engine.viewResized(QSize(800, 480));
82
83     QSignalSpy fetchImageSpy(&engine, SIGNAL(fetchImage(int,int,int)));
84     QTest::qWait(1000);
85     fetchImageSpy.clear();
86
87     engine.setLocation(QPoint(1220*16, 1220*16));
88     QTest::qWait(1000);
89     QCOMPARE(fetchImageSpy.count(), 6*4);
90     fetchImageSpy.clear();
91
92     engine.setLocation(QPoint((1220+TILE_SIZE_X)*16, (1220+TILE_SIZE_Y)*16));
93     QTest::qWait(1000);
94     QCOMPARE(fetchImageSpy.count(), 9);
95     fetchImageSpy.clear();
96 }
97
98 void TestMapEngine::setLocationRemovedTilesCount()
99 {
100     MapEngine engine;
101     engine.viewResized(QSize(800, 480));
102
103     const int maxItemsCount = 40;
104
105     engine.setLocation(QPoint(1220*16, 1220*16));
106     QTest::qWait(1000);
107     engine.setLocation(QPoint(2220*16, 2220*16));
108     QTest::qWait(1000);
109     QVERIFY(engine.scene()->items().count() <= maxItemsCount);
110
111     engine.setLocation(QPoint(520*16, 2220*16));
112     QTest::qWait(1000);
113     engine.setLocation(QPoint(2220*16, 520*16));
114     QTest::qWait(1000);
115
116     QVERIFY(engine.scene()->items().count() <= maxItemsCount);
117 }
118
119 void TestMapEngine::zoomInRemovedTilesCount()
120 {
121     MapEngine engine;
122     engine.viewResized(QSize(800, 480));
123
124     const int maxItemsCount = 40;
125
126     engine.setLocation(QPoint(1220*16, 1220*16));
127     QTest::qWait(1000);
128     QTest::qWait(1000);
129     QVERIFY(engine.scene()->items().count() <= maxItemsCount);
130
131     engine.setLocation(QPoint(520*16, 2220*16));
132     QTest::qWait(1000);
133     engine.setLocation(QPoint(2220*16, 520*16));
134     QTest::qWait(1000);
135
136     QVERIFY(engine.scene()->items().count() <= maxItemsCount);
137 }
138
139 void TestMapEngine::zoomOutRemovedTilesCount()
140 {
141     MapEngine engine;
142     engine.viewResized(QSize(800, 480));
143
144     const int maxItemsCount = 40;
145
146     engine.setLocation(QPoint(1220*16, 1220.23*16));
147     QTest::qWait(1000);
148     engine.setLocation(QPoint(2220*16, 2220.23*16));
149     QTest::qWait(1000);
150     QVERIFY(engine.scene()->items().count() <= maxItemsCount);
151
152     engine.setLocation(QPoint(520*16, 2220*16));
153     QTest::qWait(1000);
154     engine.setLocation(QPoint(2220*16, 520*16));
155     QTest::qWait(1000);
156
157     QVERIFY(engine.scene()->items().count() <= maxItemsCount);
158 }
159
160 QTEST_MAIN(TestMapEngine)
161 #include "testmapengine.moc"