File: test_GVLayout_construction.cpp

package info (click to toggle)
graphviz 14.1.1-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 139,440 kB
  • sloc: ansic: 142,129; cpp: 11,960; python: 7,770; makefile: 4,043; yacc: 3,030; xml: 2,972; tcl: 2,495; sh: 1,388; objc: 1,159; java: 560; lex: 423; perl: 243; awk: 156; pascal: 139; php: 58; ruby: 49; cs: 31; sed: 1
file content (173 lines) | stat: -rw-r--r-- 5,090 bytes parent folder | download
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
#include <memory>

#include <catch2/catch_all.hpp>

#include <cgraph++/AGraph.h>
#include <gvc++/GVContext.h>
#include <gvc++/GVLayout.h>

TEST_CASE("Layout of a graph can use on-demand loaded plugins") {
  auto gvc = std::make_shared<GVC::GVContext>();

  auto dot = "graph {a}";
  auto g = std::make_shared<CGraph::AGraph>(dot);

  const auto layout = GVC::GVLayout(gvc, g, "dot");
}

TEST_CASE("Layout of a graph can use built-in plugins") {
  const auto demand_loading = false;
  auto gvc =
      std::make_shared<GVC::GVContext>(lt_preloaded_symbols, demand_loading);

  auto dot = "graph {a}";
  auto g = std::make_shared<CGraph::AGraph>(dot);

  const auto layout = GVC::GVLayout(gvc, g, "dot");
}

TEST_CASE("A layout can be moved assigned") {
  auto gvc = std::make_shared<GVC::GVContext>();

  auto dot = "graph {a}";
  auto g = std::make_shared<CGraph::AGraph>(dot);

  auto layout = GVC::GVLayout(gvc, g, "dot");

  const auto layout2 = std::move(layout);
}

TEST_CASE("A layout can be move constructed") {
  auto gvc = std::make_shared<GVC::GVContext>();

  auto dot = "graph {a}";
  auto g = std::make_shared<CGraph::AGraph>(dot);

  auto layout = GVC::GVLayout(gvc, g, "dot");
  auto other{std::move(layout)};
}

TEST_CASE("Layout of multiple graphs can use the same context") {
  const auto demand_loading = false;
  auto gvc =
      std::make_shared<GVC::GVContext>(lt_preloaded_symbols, demand_loading);

  auto dot1 = "graph {a}";
  auto g1 = std::make_shared<CGraph::AGraph>(dot1);

  const auto layout1 = GVC::GVLayout(gvc, g1, "dot");

  auto dot2 = "graph {b}";
  auto g2 = std::make_shared<CGraph::AGraph>(dot2);

  const auto layout2 = GVC::GVLayout(gvc, g2, "dot");
}

TEST_CASE("Multiple layouts of the same graph can use different contexts") {
  const auto demand_loading = false;
  auto gvc1 =
      std::make_shared<GVC::GVContext>(lt_preloaded_symbols, demand_loading);
  auto dot = "graph {a}";
  auto g = std::make_shared<CGraph::AGraph>(dot);

  // create a layout and automatically destroy it
  {
    const auto layout = GVC::GVLayout(gvc1, g, "dot");
  }

  auto gvc2 =
      std::make_shared<GVC::GVContext>(lt_preloaded_symbols, demand_loading);

  // create another layout and automatically destroy it
  {
    const auto layout2 = GVC::GVLayout(gvc2, g, "dot");
  }
}

TEST_CASE("Creating a second layout for the same graph without destroying the "
          "first throws an exception") {
  const auto demand_loading = false;
  auto gvc1 =
      std::make_shared<GVC::GVContext>(lt_preloaded_symbols, demand_loading);
  auto dot = "graph {a}";
  auto g = std::make_shared<CGraph::AGraph>(dot);

  // create a layout and keep it
  const auto layout = GVC::GVLayout(gvc1, g, "dot");

  auto gvc2 =
      std::make_shared<GVC::GVContext>(lt_preloaded_symbols, demand_loading);

  // create another layout
  REQUIRE_THROWS_AS(GVC::GVLayout(gvc2, g, "dot"), std::runtime_error);
}

TEST_CASE("Layout of a graph can use on-demand loaded plugins and pass the "
          "context and the graph as rvalue refs)") {
  auto gvc = GVC::GVContext();

  auto dot = "graph {}";
  auto g = CGraph::AGraph(dot);

  const auto layout = GVC::GVLayout(std::move(gvc), std::move(g), "dot");
}

TEST_CASE("Layout of a graph can use built-in plugins and pass the context and "
          "the graph as rvalue refs)") {
  const auto demand_loading = false;
  auto gvc = GVC::GVContext(lt_preloaded_symbols, demand_loading);

  auto dot = "graph {}";
  auto g = CGraph::AGraph(dot);

  const auto layout = GVC::GVLayout(std::move(gvc), std::move(g), "dot");
}

TEST_CASE("Layout of multiple graphs can use the same context and pass the "
          "graphs as rvalue refs") {
  const auto demand_loading = false;
  auto gvc = std::make_shared<GVC::GVContext>(
      GVC::GVContext(lt_preloaded_symbols, demand_loading));

  auto dot1 = "graph {}";
  auto g1 = CGraph::AGraph(dot1);

  const auto layout1 = GVC::GVLayout(gvc, std::move(g1), "dot");

  auto dot2 = "graph {}";
  auto g2 = CGraph::AGraph(dot2);

  const auto layout2 = GVC::GVLayout(gvc, std::move(g2), "dot");
}

TEST_CASE("Multiple layouts of the same graph can use different contexts "
          "passed as rvalue refs") {
  const auto demand_loading = false;
  auto gvc1 = GVC::GVContext(lt_preloaded_symbols, demand_loading);
  auto dot = "graph {}";
  auto g = std::make_shared<CGraph::AGraph>(dot);

  // create a layout and automatically destroy it
  {
    const auto layout1 = GVC::GVLayout(std::move(gvc1), g, "dot");
  }

  auto gvc2 = GVC::GVContext(lt_preloaded_symbols, demand_loading);

  // create another layout and automatically destroy it
  {
    const auto layout2 = GVC::GVLayout(std::move(gvc2), g, "dot");
  }
}

TEST_CASE("Layout with an unknown engine throws an exception") {
  auto dot = "digraph {}";
  auto g = std::make_shared<CGraph::AGraph>(dot);

  const auto demand_loading = false;
  auto gvc =
      std::make_shared<GVC::GVContext>(lt_preloaded_symbols, demand_loading);

  REQUIRE_THROWS_AS(GVC::GVLayout(gvc, g, "UNKNOWN_ENGINE"),
                    std::runtime_error);
}