-
Notifications
You must be signed in to change notification settings - Fork 2
/
qtconceptmapcommandselectedge_test.cpp
148 lines (121 loc) · 4.58 KB
/
qtconceptmapcommandselectedge_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
#include "qtconceptmapcommandselectedge_test.h"
#include "qtconceptmapcommandselectedge.h"
#include "qtconceptmapcommandselectnode.h"
#include "qtconceptmap.h"
#include "conceptmapfactory.h"
#include "qtconceptmapqtedge.h"
#include "qtconceptmapqtnode.h"
void ribi::cmap::QtCommandSelectEdgeTest::SelectAbsentItemFails() const noexcept
{
QtConceptMap q;
q.SetConceptMap(ConceptMapFactory().GetTwoNodeOneEdge());
assert(CountSelectedQtEdges(q) == 0);
assert(CountSelectedQtNodes(q) == 0);
try
{
QtEdge * const first_qtedge = FindFirstQtEdge(q, QtEdgeHasName("absent"));
q.DoCommand(new CommandSelectEdge(q, first_qtedge));
QVERIFY(!"Should not get here");
}
catch (std::exception&)
{
QVERIFY("OK");
}
}
void ribi::cmap::QtCommandSelectEdgeTest::SelectQtEdgeByName() const noexcept
{
QtConceptMap q;
q.SetConceptMap(ConceptMapFactory().GetTwoNodeOneEdgeNoCenter());
assert(CountSelectedQtEdges(q) == 0);
assert(CountSelectedQtNodes(q) == 0);
QtEdge * const first_qtedge = FindFirstQtEdge(q, QtEdgeHasName("second"));
const QtNode * const first_qtnode = first_qtedge->GetQtNode();
q.DoCommand(new CommandSelectEdge(q, first_qtedge));
QVERIFY(CountSelectedQtEdges(q) == 1);
QVERIFY(CountSelectedQtNodes(q) == 0);
QVERIFY(GetQtToolItemBuddy(q) == nullptr);
}
void ribi::cmap::QtCommandSelectEdgeTest::SelectQtEdgeByNameAndUndo() const noexcept
{
QtConceptMap q;
q.SetConceptMap(ConceptMapFactory().GetTwoNodeOneEdgeNoCenter());
QtNode * const first_qtnode = FindFirstQtNode(q, QtNodeHasName("one"));
q.DoCommand(new CommandSelectNode(q, first_qtnode));
assert(CountSelectedQtEdges(q) == 0);
assert(CountSelectedQtNodes(q) == 1);
assert(GetQtToolItemBuddy(q) == first_qtnode);
QtEdge * const first_qtedge = FindFirstQtEdge(q, QtEdgeHasName("second"));
q.DoCommand(new CommandSelectEdge(q, first_qtedge));
assert(CountSelectedQtEdges(q) == 1);
assert(CountSelectedQtNodes(q) == 1);
assert(GetQtToolItemBuddy(q) == nullptr);
q.Undo();
assert(CountSelectedQtEdges(q) == 0);
assert(CountSelectedQtNodes(q) == 1);
assert(GetQtToolItemBuddy(q) == first_qtnode);
}
void ribi::cmap::QtCommandSelectEdgeTest::SelectQtEdgeConnectedToCenterByName() const noexcept
{
QtConceptMap q;
q.SetConceptMap(ConceptMapFactory().GetTwoNodeOneEdge());
assert(CountSelectedQtEdges(q) == 0);
assert(CountSelectedQtNodes(q) == 0);
QtEdge * const first_qtedge = FindFirstQtEdge(q, QtEdgeHasName("first"));
q.DoCommand(new CommandSelectEdge(q, first_qtedge));
QVERIFY(CountSelectedQtEdges(q) == 1);
QVERIFY(CountSelectedQtNodes(q) == 0);
}
void ribi::cmap::QtCommandSelectEdgeTest
::SelectSelectedQtEdgeFails() const noexcept
{
QtConceptMap q;
q.SetConceptMap(ConceptMapFactory().GetTwoNodeOneEdgeNoCenter());
QtEdge * const first_qtedge = FindFirstQtEdge(q, QtEdgeHasName("second"));
q.DoCommand(new CommandSelectEdge(q, first_qtedge));
assert(CountSelectedQtEdges(q) == 1);
assert(CountSelectedQtNodes(q) == 0);
try
{
q.DoCommand(new CommandSelectEdge(q, first_qtedge));
QVERIFY(!"Should not get here"); //!OCLINT accepted idiom
}
catch (std::invalid_argument&)
{
QVERIFY("OK"); //!OCLINT accepted idiom
}
}
void ribi::cmap::QtCommandSelectEdgeTest::SelectTwoQtEdgesByName() const noexcept
{
QtConceptMap q;
q.SetConceptMap(ConceptMapFactory().GetThreeNodeTwoEdgeNoCenter());
assert(CountSelectedQtEdges(q) == 0);
assert(CountSelectedQtNodes(q) == 0);
QtEdge * const first_qtedge = FindFirstQtEdge(q, QtEdgeHasName("first"));
const QtNode * const first_qtnode = first_qtedge->GetQtNode();
q.DoCommand(new CommandSelectEdge(q, first_qtedge));
QVERIFY(CountSelectedQtEdges(q) == 1);
QVERIFY(CountSelectedQtNodes(q) == 0);
QVERIFY(HasExamples(*first_qtedge));
QVERIFY(GetQtToolItemBuddy(q) == nullptr);
QtEdge * const second_qtedge = FindFirstQtEdge(q, QtEdgeHasName("second"));
const QtNode * const second_qtnode = second_qtedge->GetQtNode();
q.DoCommand(new CommandSelectEdge(q, second_qtedge));
QVERIFY(CountSelectedQtEdges(q) == 2);
QVERIFY(CountSelectedQtNodes(q) == 0);
QVERIFY(HasExamples(*second_qtedge));
QVERIFY(GetQtToolItemBuddy(q) == nullptr);
}
void ribi::cmap::QtCommandSelectEdgeTest::Parse() const noexcept
{
QtConceptMap q;
q.SetConceptMap(ConceptMapFactory().GetTwoNodeOneEdge());
const auto c = ParseCommandSelectEdge(q, "select_edge(first)");
assert(c);
QVERIFY(c != nullptr);
QVERIFY(GetText(*c->GetQtEdge()) == "first");
}
void ribi::cmap::QtCommandSelectEdgeTest::ParseNonsenseFails() const noexcept
{
QtConceptMap q;
QVERIFY(ParseCommandSelectEdge(q, "nonsense") == nullptr);
}