-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
110 lines (81 loc) · 2.17 KB
/
test.cpp
File metadata and controls
110 lines (81 loc) · 2.17 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <QTemporaryFile>
#include <QTest>
#include <QSignalSpy>
#include "world.hpp"
#include "test.hpp"
using namespace Headway;
void Test::randomTooHigh()
{
World biotope;
biotope.createWorld(2, 2);
QSignalSpy spy(&biotope, &World::error);
QVERIFY(!biotope.random(50000));
QCOMPARE(spy.count(), 1);
}
void Test::cellWriteInvalid()
{
World biotope;
biotope.createWorld(10, 11);
QVERIFY(!biotope.isValid(10, 10));
QVERIFY(!biotope.createCell(10, 10));
}
void Test::cellWriteTwice()
{
World biotope;
biotope.createWorld(10, 15);
biotope.createCell(1, 2);
QVERIFY(!biotope.createCell(1, 2));
}
void Test::nextEq()
{
World w1;
w1.createWorld(40, 30, 2);
w1.random(100);
World w2(w1);
w1.next();
QVERIFY(w1 != w2);
w2.next();
QVERIFY(w1 == w2);
}
void Test::saveLoadEq()
{
World genesis;
genesis.createWorld(8, 20, 4);
genesis.random(10);
QTemporaryFile xmlFile(QDir::temp().filePath("XXXXXX.xml")); xmlFile.open();
QTemporaryFile jsonFile(QDir::temp().filePath("XXXXXX.json")); jsonFile.open();
const QUrl xmlUrl = QUrl::fromLocalFile(xmlFile.fileName());
const QUrl jsonUrl = QUrl::fromLocalFile(jsonFile.fileName());
QVERIFY(genesis.saveFile(xmlUrl));
QVERIFY(genesis.saveFile(jsonUrl));
World xmlWorld;
QVERIFY(xmlWorld.loadFile(xmlUrl));
World jsonWorld;
QVERIFY(jsonWorld.loadFile(jsonUrl));
QCOMPARE(xmlWorld, genesis);
QCOMPARE(jsonWorld, genesis);
xmlFile.close();
jsonFile.close();
}
void Test::loadInvalid()
{
QTemporaryFile invalidFile(QDir::temp().filePath("XXXXXX.xml"));
invalidFile.open();
QTextStream stream(&invalidFile);
stream << "Lorem ipsum";
stream.flush();
const QUrl fileUrl = QUrl::fromLocalFile(invalidFile.fileName());
World invalidWorld;
QSignalSpy spy(&invalidWorld, &World::error);
QVERIFY(!invalidWorld.loadFile(fileUrl));
QCOMPARE(spy.count(), 1);
invalidFile.close();
}
void Test::createInvalid()
{
World biotope;
QSignalSpy spy(&biotope, &World::error);
QVERIFY(!biotope.createWorld(0, 2));
QCOMPARE(spy.count(), 1);
}
QTEST_MAIN(Headway::Test)