-
Notifications
You must be signed in to change notification settings - Fork 2
/
qtconceptmapcommands_test.cpp
315 lines (288 loc) · 7.97 KB
/
qtconceptmapcommands_test.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#include "qtconceptmapcommands_test.h"
#include "qtconceptmapcommands.h"
#include "qtconceptmap.h"
#include "qtconceptmaphelper.h"
#include "conceptmaphelper.h"
#include "qtconceptmapqtedge.h"
#include "qtconceptmapqtnode.h"
#include <QDebug>
void ribi::cmap::QtCommandsTest::GetCommandsEmptyWhenOneWord() const noexcept
{
const std::string cmds = "single-word";
const std::vector<std::string> args = { "--command", cmds };
const auto s = ::ribi::cmap::GetCommands(args);
QVERIFY(!s.empty());
QVERIFY(s == cmds);
}
void ribi::cmap::QtCommandsTest::GetCommandsEmptyWhenTwoWords() const noexcept
{
const std::string cmds = "two words";
const std::vector<std::string> args = { "--command", cmds };
const auto s = ::ribi::cmap::GetCommands(args);
QVERIFY(!s.empty());
QVERIFY(s == cmds);
}
void ribi::cmap::QtCommandsTest::GetCommandsEmptyWithManyNonsenseWords() const noexcept
{
const std::string cmds = "many and many nonsense words without minus minus command";
const std::vector<std::string> args = { "--command", cmds };
const auto s = ::ribi::cmap::GetCommands(args);
QVERIFY(!s.empty());
QVERIFY(s == cmds);
}
void ribi::cmap::QtCommandsTest::NonsenseToEmpty() const noexcept
{
QtConceptMap q;
ProcessCommands(q, { "--command", "nonsense" } );
QVERIFY(q.GetUndo().count() == 0);
}
void ribi::cmap::QtCommandsTest::CreateOneNewNodeCommand() const noexcept
{
QtConceptMap q;
ProcessCommands(q, { "--command", "create_new_node(my text, 10, 20, normal)" } );
QVERIFY(q.GetUndo().count() == 1);
QVERIFY(CountQtNodes(q) == 1);
QVERIFY(CountSelectedQtNodes(q) == 1);
CheckInvariants(q);
}
void ribi::cmap::QtCommandsTest::CreateOneNewNodeThenUnselect() const noexcept
{
QtConceptMap q;
ProcessCommands(q,
{
"--command",
"create_new_node(to be unselected, 10, 20, normal); "
"unselect(to be unselected)"
}
);
QVERIFY(q.GetUndo().count() == 2);
QVERIFY(CountQtNodes(q) == 1);
QVERIFY(CountSelectedQtNodes(q) == 0);
}
void ribi::cmap::QtCommandsTest::CreateRelationOverCenterNode() const noexcept
{
QtConceptMap q;
ProcessCommands(q,
{
"--command",
"create_new_node(focal question, 0, 0, center); "
"unselect(focal question); "
"create_new_node(from, 0, -50, normal);"
"create_new_node(to, 0, 50, normal);"
"create_new_edge(relation, from, to);"
}
);
QVERIFY(q.GetUndo().count() == 5);
QVERIFY(CountQtNodes(q) == 3);
}
void ribi::cmap::QtCommandsTest::CreateTwoNewNodeCommands() const noexcept
{
QtConceptMap q;
ProcessCommands(q,
{
"--command",
"create_new_node(my first text, 10, 20, normal); "
"create_new_node(my other text, 10, 40, normal)"
}
);
QVERIFY(q.GetUndo().count() == 2);
}
void ribi::cmap::QtCommandsTest::CreateNewEdgeBetweenTwoSelectedNodesCommand() const noexcept
{
QtConceptMap q;
ProcessCommands(q,
{
"--command",
"create_new_node(from, 10, 20, normal); "
"create_new_node(to, 10, 40, normal); "
"create_new_edge(between)"
}
);
QVERIFY(q.GetUndo().count() == 3);
}
void ribi::cmap::QtCommandsTest
::MoveCommandFailsOnNonexistingItem() const noexcept
{
QtConceptMap q;
try
{
ProcessCommands(q,
{
"--command",
"create_new_node(from, 100, 200, normal); "
"create_new_node(to, 100, 400, normal); "
"create_new_edge(relation); "
"move(nonexisting, 50, 75)"
}
);
QVERIFY(!"Should not get here"); //!OCLINT accepted idiom
}
catch (std::exception&)
{
QVERIFY("Should get here"); //!OCLINT accepted idiom
}
}
void ribi::cmap::QtCommandsTest::MoveCommandOnEdge() const noexcept
{
QtConceptMap q;
ProcessCommands(q,
{
"--command",
"create_new_node(from, 100, 200, normal); "
"create_new_node(to, 100, 400, normal); "
"create_new_edge(relation); "
"move(relation, 50, 75)"
}
);
assert(q.GetUndo().count() == 4);
const double expected_x{150.0};
const double measured_x1{GetX(*GetQtEdges(q).at(0))};
const double measured_x2{GetX(*GetQtEdges(q).at(0)->GetQtNode())};
const double expected_y{375.0};
const double measured_y1{GetY(*GetQtEdges(q).at(0))};
const double measured_y2{GetY(*GetQtEdges(q).at(0)->GetQtNode())};
QVERIFY(std::abs(expected_x - measured_x1) < 1.0);
QVERIFY(std::abs(expected_y - measured_y1) < 1.0);
QVERIFY(std::abs(expected_x - measured_x2) < 1.0);
QVERIFY(std::abs(expected_y - measured_y2) < 1.0);
}
void ribi::cmap::QtCommandsTest::MoveCommandOnNode() const noexcept
{
QtConceptMap q;
ProcessCommands(q,
{
"--command",
"create_new_node(move me, 50, 75, normal); "
"move(move me, 100, 200)"
}
);
QVERIFY(q.GetUndo().count() == 2);
const double expected_x{150.0};
const double measured_x{GetX(*GetQtNodes(q).at(0))};
const double expected_y{275.0};
const double measured_y{GetY(*GetQtNodes(q).at(0))};
QVERIFY(std::abs(expected_x - measured_x) < 1.0);
QVERIFY(std::abs(expected_y - measured_y) < 1.0);
}
void ribi::cmap::QtCommandsTest::MoveNodeCommandOnNode() const noexcept
{
QtConceptMap q;
ProcessCommands(q,
{
"--command",
"create_new_node(from, 50, 75, normal); "
"move_node(from, 100, 200)"
}
);
QVERIFY(q.GetUndo().count() == 2);
const double expected_x{150.0};
const double measured_x{GetX(*GetQtNodes(q).at(0))};
const double expected_y{275.0};
const double measured_y{GetY(*GetQtNodes(q).at(0))};
QVERIFY(std::abs(expected_x - measured_x) < 1.0);
QVERIFY(std::abs(expected_y - measured_y) < 1.0);
}
void ribi::cmap::QtCommandsTest::SelectCommandIsIgnoredOnAbsentItem() const noexcept
{
QtConceptMap q;
ProcessCommands(q,
{
"--command",
"select(absent node)"
}
);
assert(q.GetUndo().count() == 0);
}
void ribi::cmap::QtCommandsTest::SelectAndUnselectAllLonelyCenterNode() const noexcept
{
QtConceptMap q;
ProcessCommands(q,
{
"--command",
"set_mode(edit); create_new_node(focal question, 0, 0, center); unselect_all()"
}
);
assert(q.GetUndo().count() == 3);
assert(CountSelectedQtEdges(q) == 0);
assert(CountSelectedQtNodes(q) == 0);
}
void ribi::cmap::QtCommandsTest::SelectAndUnselectLonelyCenterNode() const noexcept
{
QtConceptMap q;
ProcessCommands(q,
{
"--command",
"set_mode(edit); create_new_node(focal question, 0, 0, center); unselect(focal question)"
}
);
q.show();
assert(CountQtEdges(q) == 0);
assert(CountQtNodes(q) == 1);
QVERIFY(CountSelectedQtEdges(q) == 0);
QVERIFY(CountSelectedQtNodes(q) == 0);
}
void ribi::cmap::QtCommandsTest::SetModeCommand() const noexcept
{
QtConceptMap q;
ProcessCommands(q,
{
"--command",
"set_mode(edit)"
}
);
QVERIFY(q.GetUndo().count() == 1);
}
void ribi::cmap::QtCommandsTest::ToggleArrowHeadCommand() const noexcept
{
QtConceptMap q;
ProcessCommands(q,
{
"--command",
"create_new_node(from, 10, 20, normal); "
"create_new_node(to, 10, 40, normal); "
"create_new_edge(between); "
"toggle_arrow_head()"
}
);
QVERIFY(q.GetUndo().count() == 4);
}
void ribi::cmap::QtCommandsTest::ToggleArrowTailCommand() const noexcept
{
QtConceptMap q;
ProcessCommands(q,
{
"--command",
"create_new_node(from, 10, 20, normal); "
"create_new_node(to, 10, 40, normal); "
"create_new_edge(between); "
"toggle_arrow_tail()"
}
);
QVERIFY(q.GetUndo().count() == 4);
}
void ribi::cmap::QtCommandsTest::UnselectCommandIsIgnoredOnAbsentItem() const noexcept
{
QtConceptMap q;
ProcessCommands(q,
{
"--command",
"unselect(absent node)"
}
);
assert(q.GetUndo().count() == 0);
}
void ribi::cmap::QtCommandsTest::UnselectLonelyCenterNode() const noexcept
{
QtConceptMap q;
q.show();
ProcessCommands(q,
{
"--command",
"set_mode(edit); create_new_node(my name, 0, 0, center); unselect(my name)"
}
);
assert(q.GetUndo().count() == 3);
assert(CountQtCenterNodes(q) == 1);
assert(CountSelectedQtEdges(q) == 0);
QVERIFY(CountSelectedQtNodes(q) == 0);
}