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>
25 #include "map/mapscene.h"
26 #include "map/maptile.h"
27 #include "map/mapengine.h"
29 class TestMapScene : public QObject
37 * @brief Test adding map tiles
39 * Does check that the map tile is found in right coordinates
41 void TestMapScene::addMapTile()
43 const int ZOOM_LEVEL_1ST = 18;
44 const int ZOOM_LEVEL_2ND = 16;
45 const QPoint TILE_INDEX_1ST = QPoint(1, 2);
46 const QPoint TILE_INDEX_2ND = QPoint(2, 3);
51 // Zoom level is 18, so no stretching should occure
52 // Top-left corner x = 256, y = 512
53 // Bottom-right corner x + 255, y + 255
54 mapScene.setZoomLevel(ZOOM_LEVEL_1ST);
55 mapScene.addTile(ZOOM_LEVEL_1ST, TILE_INDEX_1ST, QPixmap("maptile.png"), ZOOM_LEVEL_1ST);
57 // Check that there is only one item in the scene and take a pointer to it
58 QCOMPARE(mapScene.items().count(), 1);
59 MapTile *tile = dynamic_cast<MapTile *>(mapScene.items().at(0));
62 // Check around top-left and bottom-right corners
65 int s = 255; //side length -1
66 QCOMPARE(mapScene.itemAt(x-1, y), (QGraphicsItem *)0);
67 QCOMPARE(mapScene.itemAt(x, y-1), (QGraphicsItem *)0);
68 QCOMPARE(mapScene.itemAt(x, y), dynamic_cast<QGraphicsItem *>(tile));
69 QCOMPARE(mapScene.itemAt(x+s, y+s), dynamic_cast<QGraphicsItem *>(tile));
70 QCOMPARE(mapScene.itemAt(x+s+1, y+s), (QGraphicsItem *)0);
71 QCOMPARE(mapScene.itemAt(x+s, y+s+1), (QGraphicsItem *)0);
74 // Zoom level is 16, so stretching is also tested
75 // Top-left corner x = 2048, y = 3072
76 // Bottom-right corner x + 1023, y + 1023
77 tile->setZoomLevel(ZOOM_LEVEL_2ND, ZOOM_LEVEL_2ND);
78 tile->setTileNumber(TILE_INDEX_2ND);
80 // Check around top-left and bottom-right corners
83 s = 1023; //side length -1
84 QCOMPARE(mapScene.itemAt(x-1, y), (QGraphicsItem *)0);
85 QCOMPARE(mapScene.itemAt(x, y-1), (QGraphicsItem *)0);
86 QCOMPARE(mapScene.itemAt(x, y), dynamic_cast<QGraphicsItem *>(tile));
87 QCOMPARE(mapScene.itemAt(x+s, y+s), dynamic_cast<QGraphicsItem *>(tile));
88 QCOMPARE(mapScene.itemAt(x+s+1, y+s), (QGraphicsItem *)0);
89 QCOMPARE(mapScene.itemAt(x+s, y+s+1), (QGraphicsItem *)0);
92 QTEST_MAIN(TestMapScene)
93 #include "testmapscene.moc"