Updated unit tests
[situare] / tests / map / mapscene / testmapscene.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 #include <QDebug>
24
25 #include "map/mapscene.h"
26 #include "map/maptile.h"
27 #include "map/mapengine.h"
28
29 class TestMapScene : public QObject
30 {
31     Q_OBJECT
32 private slots:
33     void addMapTile();
34 };
35
36 /**
37 * @brief Test adding map tiles
38 *
39 * Does check that the map tile is found in right coordinates
40 */
41 void TestMapScene::addMapTile()
42 {
43     MapScene mapScene;
44
45     // First test:
46     // Zoom level is 18, so no stretching should occure
47     // Top-left corner x = 256, y = 512
48     // Bottom-right corner x + 255, y + 255
49     MapTile *mapTile = new MapTile();
50     mapTile->setZoomLevel(18, 14);
51     mapTile->setTileNumber(QPoint(1, 2));
52     mapTile->setPixmap(QPixmap("maptile.png"));
53
54     mapScene.addTile(mapTile, "dymmyTestKey");
55
56     // Check around top-left and bottom-right corners
57     int x = 256;
58     int y = 512;
59     int s = 255; //side length -1
60     QCOMPARE(mapScene.itemAt(x-1, y), (QGraphicsItem *)0);
61     QCOMPARE(mapScene.itemAt(x, y-1), (QGraphicsItem *)0);
62     QCOMPARE(mapScene.itemAt(x, y), dynamic_cast<QGraphicsItem *>(mapTile));
63     QCOMPARE(mapScene.itemAt(x+s, y+s), dynamic_cast<QGraphicsItem *>(mapTile));
64     QCOMPARE(mapScene.itemAt(x+s+1, y+s), (QGraphicsItem *)0);
65     QCOMPARE(mapScene.itemAt(x+s, y+s+1), (QGraphicsItem *)0);
66
67     // Second test:
68     // Zoom level is 16, so stretching is also tested
69     // Top-left corner x = 2048, y = 3072
70     // Bottom-right corner x + 1023, y + 1023
71     mapTile->setZoomLevel(16, 14);
72     mapTile->setTileNumber(QPoint(2, 3));
73
74     // Check around top-left and bottom-right corners
75     x = 2048;
76     y = 3072;
77     s = 1023; //side length -1
78     QCOMPARE(mapScene.itemAt(x-1, y), (QGraphicsItem *)0);
79     QCOMPARE(mapScene.itemAt(x, y-1), (QGraphicsItem *)0);
80     QCOMPARE(mapScene.itemAt(x, y), dynamic_cast<QGraphicsItem *>(mapTile));
81     QCOMPARE(mapScene.itemAt(x+s, y+s), dynamic_cast<QGraphicsItem *>(mapTile));
82     QCOMPARE(mapScene.itemAt(x+s+1, y+s), (QGraphicsItem *)0);
83     QCOMPARE(mapScene.itemAt(x+s, y+s+1), (QGraphicsItem *)0);
84 }
85
86 QTEST_MAIN(TestMapScene)
87 #include "testmapscene.moc"