1 #include <QtTest/QtTest>
4 #include "map/mapscene.h"
5 #include "map/maptile.h"
6 #include "map/mapengine.h"
8 class TestMapScene : public QObject
15 /// \brief Test adding map tiles
16 /// Does check that map tile is found in right coordinates
17 void TestMapScene::addMapTile()
22 // Zoom level is 18, so no stretching should occure
23 // Top-left corner x = 256, y = 512
24 // Bottom-right corner x + 255, y + 255
25 MapTile *mapTile = new MapTile();
26 mapTile->setZoomLevel(18);
27 mapTile->setTileNumber(QPoint(1, 2));
28 mapTile->setPixmap(QPixmap("maptile.png"));
30 mapScene.addMapTile(mapTile);
32 // Check around top-left and bottom-right corners
35 int s = 255; //side length -1
36 QCOMPARE(mapScene.itemAt(x-1, y), (QGraphicsItem *)0);
37 QCOMPARE(mapScene.itemAt(x, y-1), (QGraphicsItem *)0);
38 QCOMPARE(mapScene.itemAt(x, y), dynamic_cast<QGraphicsItem *>(mapTile));
39 QCOMPARE(mapScene.itemAt(x+s, y+s), dynamic_cast<QGraphicsItem *>(mapTile));
40 QCOMPARE(mapScene.itemAt(x+s+1, y+s), (QGraphicsItem *)0);
41 QCOMPARE(mapScene.itemAt(x+s, y+s+1), (QGraphicsItem *)0);
44 // Zoom level is 16, so stretching is also tested
45 // Top-left corner x = 2048, y = 3072
46 // Bottom-right corner x + 1023, y + 1023
47 mapTile->setZoomLevel(16);
48 mapTile->setTileNumber(QPoint(2, 3));
50 // Check around top-left and bottom-right corners
53 s = 1023; //side length -1
54 QCOMPARE(mapScene.itemAt(x-1, y), (QGraphicsItem *)0);
55 QCOMPARE(mapScene.itemAt(x, y-1), (QGraphicsItem *)0);
56 QCOMPARE(mapScene.itemAt(x, y), dynamic_cast<QGraphicsItem *>(mapTile));
57 QCOMPARE(mapScene.itemAt(x+s, y+s), dynamic_cast<QGraphicsItem *>(mapTile));
58 QCOMPARE(mapScene.itemAt(x+s+1, y+s), (QGraphicsItem *)0);
59 QCOMPARE(mapScene.itemAt(x+s, y+s+1), (QGraphicsItem *)0);
62 QTEST_MAIN(TestMapScene)
63 #include "testmapscene.moc"