Documentation + some little improvements
[situare] / tests / testmap / testmapscene / testmapscene.cpp
1 #include <QtTest/QtTest>
2 #include <QDebug>
3
4 #include "map/mapscene.h"
5 #include "map/maptile.h"
6 #include "map/mapengine.h"
7
8 class TestMapScene : public QObject
9 {
10     Q_OBJECT
11 private slots:
12     void addMapTile();
13 };
14
15 /// \brief Test adding map tiles
16 /// Does check that map tile is found in right coordinates
17 void TestMapScene::addMapTile()
18 {
19     MapScene mapScene;
20
21     // First test:
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"));
29
30     mapScene.addMapTile(mapTile);
31
32     // Check around top-left and bottom-right corners
33     int x = 256;
34     int y = 512;
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);
42
43     // Second test:
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));
49
50     // Check around top-left and bottom-right corners
51     x = 2048;
52     y = 3072;
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);
60 }
61
62 QTEST_MAIN(TestMapScene)
63 #include "testmapscene.moc"