forked from FLAME-HPC/flame_visualiser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_flame_visualiser.cpp
155 lines (122 loc) · 3.68 KB
/
test_flame_visualiser.cpp
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*!
* \file test_flame_visualiser.cpp
* \author Simon Coakley
* \date 2012
* \copyright Copyright (c) 2012 University of Sheffield
* \brief Test suite for flame visualiser
*/
#include <QtTest/QtTest>
#include <QtGui/QApplication>
#include <QFileDialog>
#include "./mainwindow.h"
class TestVisualiser: public QObject {
Q_OBJECT
signals:
void new_config_file();
private slots:
void initTestCase();
void cleanupTestCase();
void create_new_config();
void open_a_config();
void save_a_config();
void open_an_iteration();
void adding_agent_types();
private:
MainWindow w;
int rc;
};
void TestVisualiser::initTestCase() {
/* Show main window */
w.show();
}
void TestVisualiser::cleanupTestCase() {
/* Close main window */
w.close();
}
void TestVisualiser::create_new_config() {
rc = w.create_new_config_file("");
QCOMPARE(rc, 1);
/* Cannot test unwritable file (at least across platforms) */
/*rc = w.create_new_config_file("");
QCOMPARE(rc, 2);*/
rc = w.create_new_config_file("tests/models/new_config_file.xml");
QCOMPARE(rc, 0);
if (!QFile::remove("tests/models/new_config_file.xml")) {
QWARN("Could not delete test file: tests/models/new_config_file.xml");
}
w.close_config_file();
}
void TestVisualiser::open_a_config() {
rc = w.readConfigFile("tests/models/missing.xml", 0);
QCOMPARE(rc, 1);
rc = w.readConfigFile(
"tests/models/malformed_config_xml/visual_config.xml", 0);
QCOMPARE(rc, 2);
rc = w.readConfigFile("tests/models/malformed_1_xml/visual_config.xml", 0);
QCOMPARE(rc, 0);
w.close_config_file();
}
void TestVisualiser::save_a_config() {
rc = w.save_config_file_internal("");
QCOMPARE(rc, 1);
/* Cannot test unwritable file (at least across platforms) */
/*rc = w.save_config_file_internal("");
QCOMPARE(rc, 2);*/
rc = w.save_config_file_internal("tests/models/new_config_file.xml");
QCOMPARE(rc, 0);
if (!QFile::remove("tests/models/new_config_file.xml")) {
QWARN("Could not delete test file: tests/models/new_config_file.xml");
}
w.close_config_file();
}
void TestVisualiser::open_an_iteration() {
rc = w.readConfigFile("tests/models/malformed_1_xml/visual_config.xml", 0);
QCOMPARE(rc, 0);
// Correct 0.xml
w.iteration = 0;
rc = w.readZeroXML();
QCOMPARE(rc, 0);
// Malformed 1.xml
w.iteration = 1;
rc = w.readZeroXML();
QCOMPARE(rc, 2);
// Non existent 2.xml
w.iteration = 2;
rc = w.readZeroXML();
QCOMPARE(rc, 1);
w.close_config_file();
}
void TestVisualiser::adding_agent_types() {
rc = w.readConfigFile(
"tests/models/new_agent_types_added/visual_config.xml", 0);
QCOMPARE(rc, 0);
w.iteration = 0;
rc = w.readZeroXML();
QCOMPARE(rc, 0);
QCOMPARE(w.agentTypes.size(), 2);
QCOMPARE(w.agentTypes.at(0).name, QString("environment"));
QCOMPARE(w.agentTypes.at(1).name, QString("a"));
w.iteration = 1;
rc = w.readZeroXML();
QCOMPARE(rc, 0);
QCOMPARE(w.agentTypes.size(), 3);
QCOMPARE(w.agentTypes.at(2).name, QString("b"));
w.iteration = 2;
rc = w.readZeroXML();
QCOMPARE(rc, 0);
QCOMPARE(w.agentTypes.size(), 4);
QCOMPARE(w.agentTypes.at(3).name, QString("c"));
w.iteration = 3;
rc = w.readZeroXML();
QCOMPARE(rc, 0);
QCOMPARE(w.agentTypes.size(), 6);
QCOMPARE(w.agentTypes.at(4).name, QString("d"));
QCOMPARE(w.agentTypes.at(5).name, QString("e"));
w.iteration = 4;
rc = w.readZeroXML();
QCOMPARE(rc, 0);
QCOMPARE(w.agentTypes.size(), 6);
w.close_config_file();
}
QTEST_MAIN(TestVisualiser)
#include "test_flame_visualiser.moc"