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()
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"));
54 mapScene.addTile(mapTile, "dymmyTestKey");
56 // Check around top-left and bottom-right corners
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);
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));
74 // Check around top-left and bottom-right corners
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);
86 QTEST_MAIN(TestMapScene)
87 #include "testmapscene.moc"