-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathtest_mapreader.cpp
More file actions
85 lines (65 loc) · 2.08 KB
/
test_mapreader.cpp
File metadata and controls
85 lines (65 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "map.h"
#include "mapobject.h"
#include "objectgroup.h"
#include "tilelayer.h"
#include "mapreader.h"
#include <QtTest/QtTest>
using namespace Tiled;
class test_MapReader : public QObject
{
Q_OBJECT
private slots:
void loadMap();
void loadMap_missingExternalTileset();
void loadMap_nestedExternalTileset();
void loadMap_internalTileset();
};
void test_MapReader::loadMap_missingExternalTileset()
{
MapReader reader;
auto map = reader.readMap("../data/missing_tileset.tmx");
QVERIFY(map.get());
QVERIFY(!reader.errorString().isEmpty());
}
void test_MapReader::loadMap_nestedExternalTileset()
{
MapReader reader;
auto map = reader.readMap("../data/nested_tileset.tmx");
QVERIFY(map.get());
}
void test_MapReader::loadMap_internalTileset()
{
MapReader reader;
auto map = reader.readMap("../data/internal_tileset.tmx");
QVERIFY(map.get());
}
void test_MapReader::loadMap()
{
MapReader reader;
auto map = reader.readMap("../data/mapobject.tmx");
// TODO: Also test tilesets (internal and external), properties and tile
// layer data.
QVERIFY(map.get());
QCOMPARE(map->layerCount(), 2);
QCOMPARE(map->width(), 100);
QCOMPARE(map->height(), 80);
QCOMPARE(map->tileWidth(), 32);
QCOMPARE(map->tileHeight(), 32);
TileLayer *tileLayer = dynamic_cast<TileLayer*>(map->layerAt(0));
QVERIFY(tileLayer);
QCOMPARE(tileLayer->width(), 100);
QCOMPARE(tileLayer->height(), 80);
ObjectGroup *objectGroup = dynamic_cast<ObjectGroup*>(map->layerAt(1));
QVERIFY(objectGroup);
QCOMPARE(objectGroup->name(), QLatin1String("Objects"));
QCOMPARE(objectGroup->objects().count(), 1);
MapObject *mapObject = objectGroup->objects().at(0);
QCOMPARE(mapObject->name(), QLatin1String("Some object"));
QCOMPARE(mapObject->className(), QLatin1String("WARP"));
QCOMPARE(mapObject->x(), qreal(200));
QCOMPARE(mapObject->y(), qreal(200));
QCOMPARE(mapObject->width(), qreal(128));
QCOMPARE(mapObject->height(), qreal(64));
}
QTEST_MAIN(test_MapReader)
#include "test_mapreader.moc"