File: test_GVContext_render_svg.cpp

package info (click to toggle)
graphviz 14.0.5-2
  • links: PTS
  • area: main
  • in suites: forky
  • size: 139,388 kB
  • sloc: ansic: 141,938; cpp: 11,957; python: 7,766; 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 (106 lines) | stat: -rw-r--r-- 3,777 bytes parent folder | download | duplicates (2)
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
#include <string_view>

#include <catch2/catch_all.hpp>

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

TEST_CASE(
    "Rendering an SVG from a graph without any nodes outputs an SVG containing "
    "a single (transparent) polygon") {
  const auto demand_loading = false;
  auto gvc = GVC::GVContext(lt_preloaded_symbols, demand_loading);

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

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

  const auto result = layout.render("svg");
  SVGAnalyzer svg_analyzer{result.c_str()};
  REQUIRE(svg_analyzer.num_svgs() == 1);
  REQUIRE(svg_analyzer.num_groups() == 1);
  REQUIRE(svg_analyzer.num_circles() == 0);
  REQUIRE(svg_analyzer.num_ellipses() == 0);
  REQUIRE(svg_analyzer.num_lines() == 0);
  REQUIRE(svg_analyzer.num_paths() == 0);
  REQUIRE(svg_analyzer.num_polygons() == 1);
  REQUIRE(svg_analyzer.num_polylines() == 0);
  REQUIRE(svg_analyzer.num_rects() == 0);
  REQUIRE(svg_analyzer.num_titles() == 0);
}

TEST_CASE("Rendering an SVG from a graph with a single node outputs an SVG "
          "containing an ellipse") {
  const auto demand_loading = false;
  auto gvc = GVC::GVContext(lt_preloaded_symbols, demand_loading);

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

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

  const auto result = layout.render("svg");
  SVGAnalyzer svg_analyzer{result.c_str()};
  REQUIRE(svg_analyzer.num_svgs() == 1);
  REQUIRE(svg_analyzer.num_groups() == 2);
  REQUIRE(svg_analyzer.num_ellipses() == 1);
  REQUIRE(svg_analyzer.num_circles() == 0);
  REQUIRE(svg_analyzer.num_lines() == 0);
  REQUIRE(svg_analyzer.num_paths() == 0);
  REQUIRE(svg_analyzer.num_polygons() == 1);
  REQUIRE(svg_analyzer.num_polylines() == 0);
  REQUIRE(svg_analyzer.num_rects() == 0);
  REQUIRE(svg_analyzer.num_titles() == 1);
}

TEST_CASE("Rendering an SVG from a graph with two nodes outputs an SVG "
          "containing two ellipses") {
  const auto demand_loading = false;
  auto gvc = GVC::GVContext(lt_preloaded_symbols, demand_loading);

  auto dot = "digraph {a b}";
  auto g = CGraph::AGraph(dot);

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

  const auto result = layout.render("svg");
  SVGAnalyzer svg_analyzer{result.c_str()};
  REQUIRE(svg_analyzer.num_svgs() == 1);
  REQUIRE(svg_analyzer.num_groups() == 3);
  REQUIRE(svg_analyzer.num_ellipses() == 2);
  REQUIRE(svg_analyzer.num_circles() == 0);
  REQUIRE(svg_analyzer.num_lines() == 0);
  REQUIRE(svg_analyzer.num_paths() == 0);
  REQUIRE(svg_analyzer.num_polygons() == 1);
  REQUIRE(svg_analyzer.num_polylines() == 0);
  REQUIRE(svg_analyzer.num_rects() == 0);
  REQUIRE(svg_analyzer.num_titles() == 2);
}

TEST_CASE("Rendering an SVG from a graph with two nodes and one edge outputs "
          "an SVG containing two polygons, two ellipses and one path") {
  const auto demand_loading = false;
  auto gvc = GVC::GVContext(lt_preloaded_symbols, demand_loading);

  auto dot = "digraph {a -> b}";
  auto g = CGraph::AGraph(dot);

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

  const auto result = layout.render("svg");
  SVGAnalyzer svg_analyzer{result.c_str()};
  REQUIRE(svg_analyzer.num_svgs() == 1);
  REQUIRE(svg_analyzer.num_groups() == 4);
  REQUIRE(svg_analyzer.num_ellipses() == 2);
  REQUIRE(svg_analyzer.num_circles() == 0);
  REQUIRE(svg_analyzer.num_lines() == 0);
  REQUIRE(svg_analyzer.num_paths() == 1);
  REQUIRE(svg_analyzer.num_polygons() == 2);
  REQUIRE(svg_analyzer.num_polylines() == 0);
  REQUIRE(svg_analyzer.num_rects() == 0);
  REQUIRE(svg_analyzer.num_titles() == 3);
}