Debian Codegraph @

tests/test_GVLayout_construction.cpp

raw
1 #include <memory>
2
3 #include <catch2/catch_all.hpp>
4
5 #include <cgraph++/AGraph.h>
6 #include <gvc++/GVContext.h>
7 #include <gvc++/GVLayout.h>
8
9 TEST_CASE("Layout of a graph can use on-demand loaded plugins") {
10 auto gvc = std::make_shared<GVC::GVContext>();
11
12 auto dot = "graph {a}";
13 auto g = std::make_shared<CGraph::AGraph>(dot);
14
15 const auto layout = GVC::GVLayout(gvc, g, "dot");
16 }
17
18 TEST_CASE("Layout of a graph can use built-in plugins") {
19 const auto demand_loading = false;
20 auto gvc =
21 std::make_shared<GVC::GVContext>(lt_preloaded_symbols, demand_loading);
22
23 auto dot = "graph {a}";
24 auto g = std::make_shared<CGraph::AGraph>(dot);
25
26 const auto layout = GVC::GVLayout(gvc, g, "dot");
27 }
28
29 TEST_CASE("A layout can be moved assigned") {
30 auto gvc = std::make_shared<GVC::GVContext>();
31
32 auto dot = "graph {a}";
33 auto g = std::make_shared<CGraph::AGraph>(dot);
34
35 auto layout = GVC::GVLayout(gvc, g, "dot");
36
37 const auto layout2 = std::move(layout);
38 }
39
40 TEST_CASE("A layout can be move constructed") {
41 auto gvc = std::make_shared<GVC::GVContext>();
42
43 auto dot = "graph {a}";
44 auto g = std::make_shared<CGraph::AGraph>(dot);
45
46 auto layout = GVC::GVLayout(gvc, g, "dot");
47 auto other{std::move(layout)};
48 }
49
50 TEST_CASE("Layout of multiple graphs can use the same context") {
51 const auto demand_loading = false;
52 auto gvc =
53 std::make_shared<GVC::GVContext>(lt_preloaded_symbols, demand_loading);
54
55 auto dot1 = "graph {a}";
56 auto g1 = std::make_shared<CGraph::AGraph>(dot1);
57
58 const auto layout1 = GVC::GVLayout(gvc, g1, "dot");
59
60 auto dot2 = "graph {b}";
61 auto g2 = std::make_shared<CGraph::AGraph>(dot2);
62
63 const auto layout2 = GVC::GVLayout(gvc, g2, "dot");
64 }
65
66 TEST_CASE("Multiple layouts of the same graph can use different contexts") {
67 const auto demand_loading = false;
68 auto gvc1 =
69 std::make_shared<GVC::GVContext>(lt_preloaded_symbols, demand_loading);
70 auto dot = "graph {a}";
71 auto g = std::make_shared<CGraph::AGraph>(dot);
72
73 // create a layout and automatically destroy it
74 {
75 const auto layout = GVC::GVLayout(gvc1, g, "dot");
76 }
77
78 auto gvc2 =
79 std::make_shared<GVC::GVContext>(lt_preloaded_symbols, demand_loading);
80
81 // create another layout and automatically destroy it
82 {
83 const auto layout2 = GVC::GVLayout(gvc2, g, "dot");
84 }
85 }
86
87 TEST_CASE("Creating a second layout for the same graph without destroying the "
88 "first throws an exception") {
89 const auto demand_loading = false;
90 auto gvc1 =
91 std::make_shared<GVC::GVContext>(lt_preloaded_symbols, demand_loading);
92 auto dot = "graph {a}";
93 auto g = std::make_shared<CGraph::AGraph>(dot);
94
95 // create a layout and keep it
96 const auto layout = GVC::GVLayout(gvc1, g, "dot");
97
98 auto gvc2 =
99 std::make_shared<GVC::GVContext>(lt_preloaded_symbols, demand_loading);
100
101 // create another layout
102 REQUIRE_THROWS_AS(GVC::GVLayout(gvc2, g, "dot"), std::runtime_error);
103 }
104
105 TEST_CASE("Layout of a graph can use on-demand loaded plugins and pass the "
106 "context and the graph as rvalue refs)") {
107 auto gvc = GVC::GVContext();
108
109 auto dot = "graph {}";
110 auto g = CGraph::AGraph(dot);
111
112 const auto layout = GVC::GVLayout(std::move(gvc), std::move(g), "dot");
113 }
114
115 TEST_CASE("Layout of a graph can use built-in plugins and pass the context and "
116 "the graph as rvalue refs)") {
117 const auto demand_loading = false;
118 auto gvc = GVC::GVContext(lt_preloaded_symbols, demand_loading);
119
120 auto dot = "graph {}";
121 auto g = CGraph::AGraph(dot);
122
123 const auto layout = GVC::GVLayout(std::move(gvc), std::move(g), "dot");
124 }
125
126 TEST_CASE("Layout of multiple graphs can use the same context and pass the "
127 "graphs as rvalue refs") {
128 const auto demand_loading = false;
129 auto gvc = std::make_shared<GVC::GVContext>(
130 GVC::GVContext(lt_preloaded_symbols, demand_loading));
131
132 auto dot1 = "graph {}";
133 auto g1 = CGraph::AGraph(dot1);
134
135 const auto layout1 = GVC::GVLayout(gvc, std::move(g1), "dot");
136
137 auto dot2 = "graph {}";
138 auto g2 = CGraph::AGraph(dot2);
139
140 const auto layout2 = GVC::GVLayout(gvc, std::move(g2), "dot");
141 }
142
143 TEST_CASE("Multiple layouts of the same graph can use different contexts "
144 "passed as rvalue refs") {
145 const auto demand_loading = false;
146 auto gvc1 = GVC::GVContext(lt_preloaded_symbols, demand_loading);
147 auto dot = "graph {}";
148 auto g = std::make_shared<CGraph::AGraph>(dot);
149
150 // create a layout and automatically destroy it
151 {
152 const auto layout1 = GVC::GVLayout(std::move(gvc1), g, "dot");
153 }
154
155 auto gvc2 = GVC::GVContext(lt_preloaded_symbols, demand_loading);
156
157 // create another layout and automatically destroy it
158 {
159 const auto layout2 = GVC::GVLayout(std::move(gvc2), g, "dot");
160 }
161 }
162
163 TEST_CASE("Layout with an unknown engine throws an exception") {
164 auto dot = "digraph {}";
165 auto g = std::make_shared<CGraph::AGraph>(dot);
166
167 const auto demand_loading = false;
168 auto gvc =
169 std::make_shared<GVC::GVContext>(lt_preloaded_symbols, demand_loading);
170
171 REQUIRE_THROWS_AS(GVC::GVLayout(gvc, g, "UNKNOWN_ENGINE"),
172 std::runtime_error);
173 }