Debian Codegraph @

tests/test_GVContext_render_svg.cpp

raw
1 #include <string_view>
2
3 #include <catch2/catch_all.hpp>
4
5 #include "svg_analyzer.h"
6 #include <cgraph++/AGraph.h>
7 #include <gvc++/GVContext.h>
8 #include <gvc++/GVLayout.h>
9 #include <gvc++/GVRenderData.h>
10
11 TEST_CASE(
12 "Rendering an SVG from a graph without any nodes outputs an SVG containing "
13 "a single (transparent) polygon") {
14 const auto demand_loading = false;
15 auto gvc = GVC::GVContext(lt_preloaded_symbols, demand_loading);
16
17 auto dot = "digraph {}";
18 auto g = CGraph::AGraph(dot);
19
20 const auto layout = GVC::GVLayout(std::move(gvc), std::move(g), "dot");
21
22 const auto result = layout.render("svg");
23 SVGAnalyzer svg_analyzer{result.c_str()};
24 REQUIRE(svg_analyzer.num_svgs() == 1);
25 REQUIRE(svg_analyzer.num_groups() == 1);
26 REQUIRE(svg_analyzer.num_circles() == 0);
27 REQUIRE(svg_analyzer.num_ellipses() == 0);
28 REQUIRE(svg_analyzer.num_lines() == 0);
29 REQUIRE(svg_analyzer.num_paths() == 0);
30 REQUIRE(svg_analyzer.num_polygons() == 1);
31 REQUIRE(svg_analyzer.num_polylines() == 0);
32 REQUIRE(svg_analyzer.num_rects() == 0);
33 REQUIRE(svg_analyzer.num_titles() == 0);
34 }
35
36 TEST_CASE("Rendering an SVG from a graph with a single node outputs an SVG "
37 "containing an ellipse") {
38 const auto demand_loading = false;
39 auto gvc = GVC::GVContext(lt_preloaded_symbols, demand_loading);
40
41 auto dot = "digraph {a}";
42 auto g = CGraph::AGraph(dot);
43
44 const auto layout = GVC::GVLayout(std::move(gvc), std::move(g), "dot");
45
46 const auto result = layout.render("svg");
47 SVGAnalyzer svg_analyzer{result.c_str()};
48 REQUIRE(svg_analyzer.num_svgs() == 1);
49 REQUIRE(svg_analyzer.num_groups() == 2);
50 REQUIRE(svg_analyzer.num_ellipses() == 1);
51 REQUIRE(svg_analyzer.num_circles() == 0);
52 REQUIRE(svg_analyzer.num_lines() == 0);
53 REQUIRE(svg_analyzer.num_paths() == 0);
54 REQUIRE(svg_analyzer.num_polygons() == 1);
55 REQUIRE(svg_analyzer.num_polylines() == 0);
56 REQUIRE(svg_analyzer.num_rects() == 0);
57 REQUIRE(svg_analyzer.num_titles() == 1);
58 }
59
60 TEST_CASE("Rendering an SVG from a graph with two nodes outputs an SVG "
61 "containing two ellipses") {
62 const auto demand_loading = false;
63 auto gvc = GVC::GVContext(lt_preloaded_symbols, demand_loading);
64
65 auto dot = "digraph {a b}";
66 auto g = CGraph::AGraph(dot);
67
68 const auto layout = GVC::GVLayout(std::move(gvc), std::move(g), "dot");
69
70 const auto result = layout.render("svg");
71 SVGAnalyzer svg_analyzer{result.c_str()};
72 REQUIRE(svg_analyzer.num_svgs() == 1);
73 REQUIRE(svg_analyzer.num_groups() == 3);
74 REQUIRE(svg_analyzer.num_ellipses() == 2);
75 REQUIRE(svg_analyzer.num_circles() == 0);
76 REQUIRE(svg_analyzer.num_lines() == 0);
77 REQUIRE(svg_analyzer.num_paths() == 0);
78 REQUIRE(svg_analyzer.num_polygons() == 1);
79 REQUIRE(svg_analyzer.num_polylines() == 0);
80 REQUIRE(svg_analyzer.num_rects() == 0);
81 REQUIRE(svg_analyzer.num_titles() == 2);
82 }
83
84 TEST_CASE("Rendering an SVG from a graph with two nodes and one edge outputs "
85 "an SVG containing two polygons, two ellipses and one path") {
86 const auto demand_loading = false;
87 auto gvc = GVC::GVContext(lt_preloaded_symbols, demand_loading);
88
89 auto dot = "digraph {a -> b}";
90 auto g = CGraph::AGraph(dot);
91
92 const auto layout = GVC::GVLayout(std::move(gvc), std::move(g), "dot");
93
94 const auto result = layout.render("svg");
95 SVGAnalyzer svg_analyzer{result.c_str()};
96 REQUIRE(svg_analyzer.num_svgs() == 1);
97 REQUIRE(svg_analyzer.num_groups() == 4);
98 REQUIRE(svg_analyzer.num_ellipses() == 2);
99 REQUIRE(svg_analyzer.num_circles() == 0);
100 REQUIRE(svg_analyzer.num_lines() == 0);
101 REQUIRE(svg_analyzer.num_paths() == 1);
102 REQUIRE(svg_analyzer.num_polygons() == 2);
103 REQUIRE(svg_analyzer.num_polylines() == 0);
104 REQUIRE(svg_analyzer.num_rects() == 0);
105 REQUIRE(svg_analyzer.num_titles() == 3);
106 }