From e3eaf48b609b1f61b44f3820c0d791f45af6a289 Mon Sep 17 00:00:00 2001 From: Magnus Jacobsson Date: Thu, 8 Apr 2021 22:51:26 +0200 Subject: [PATCH] add a few first tests of the rendered SVG --- tests/CMakeLists.txt | 1 + tests/test_GVContext_render_svg.cpp | 110 ++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 tests/test_GVContext_render_svg.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9ac50e16b..093c199b9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -63,3 +63,4 @@ create_test(AGraph_construction) create_test(GVContext_construction) create_test(GVLayout_construction) create_test(GVLayout_render) +create_test(GVContext_render_svg) diff --git a/tests/test_GVContext_render_svg.cpp b/tests/test_GVContext_render_svg.cpp new file mode 100644 index 000000000..5d04a3eac --- /dev/null +++ b/tests/test_GVContext_render_svg.cpp @@ -0,0 +1,110 @@ +#include + +#include + +#include "svg_analyzer.h" +#include +#include +#include +#include + +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 svgAnalyzer{result.c_str()}; + REQUIRE(svgAnalyzer.num_svgs() == 1); + REQUIRE(svgAnalyzer.num_groups() == 1); + REQUIRE(svgAnalyzer.num_circles() == 0); + REQUIRE(svgAnalyzer.num_ellipses() == 0); + REQUIRE(svgAnalyzer.num_lines() == 0); + REQUIRE(svgAnalyzer.num_paths() == 0); + REQUIRE(svgAnalyzer.num_polygons() == 1); + REQUIRE(svgAnalyzer.num_polylines() == 0); + REQUIRE(svgAnalyzer.num_rects() == 0); + REQUIRE(svgAnalyzer.num_titles() == 0); + REQUIRE(svgAnalyzer.num_unknowns() == 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 svgAnalyzer{result.c_str()}; + REQUIRE(svgAnalyzer.num_svgs() == 1); + REQUIRE(svgAnalyzer.num_groups() == 2); + REQUIRE(svgAnalyzer.num_ellipses() == 1); + REQUIRE(svgAnalyzer.num_circles() == 0); + REQUIRE(svgAnalyzer.num_lines() == 0); + REQUIRE(svgAnalyzer.num_paths() == 0); + REQUIRE(svgAnalyzer.num_polygons() == 1); + REQUIRE(svgAnalyzer.num_polylines() == 0); + REQUIRE(svgAnalyzer.num_rects() == 0); + REQUIRE(svgAnalyzer.num_titles() == 1); + REQUIRE(svgAnalyzer.num_unknowns() == 0); +} + +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 svgAnalyzer{result.c_str()}; + REQUIRE(svgAnalyzer.num_svgs() == 1); + REQUIRE(svgAnalyzer.num_groups() == 3); + REQUIRE(svgAnalyzer.num_ellipses() == 2); + REQUIRE(svgAnalyzer.num_circles() == 0); + REQUIRE(svgAnalyzer.num_lines() == 0); + REQUIRE(svgAnalyzer.num_paths() == 0); + REQUIRE(svgAnalyzer.num_polygons() == 1); + REQUIRE(svgAnalyzer.num_polylines() == 0); + REQUIRE(svgAnalyzer.num_rects() == 0); + REQUIRE(svgAnalyzer.num_titles() == 2); + REQUIRE(svgAnalyzer.num_unknowns() == 0); +} + +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 svgAnalyzer{result.c_str()}; + REQUIRE(svgAnalyzer.num_svgs() == 1); + REQUIRE(svgAnalyzer.num_groups() == 4); + REQUIRE(svgAnalyzer.num_ellipses() == 2); + REQUIRE(svgAnalyzer.num_circles() == 0); + REQUIRE(svgAnalyzer.num_lines() == 0); + REQUIRE(svgAnalyzer.num_paths() == 1); + REQUIRE(svgAnalyzer.num_polygons() == 2); + REQUIRE(svgAnalyzer.num_polylines() == 0); + REQUIRE(svgAnalyzer.num_rects() == 0); + REQUIRE(svgAnalyzer.num_titles() == 3); + REQUIRE(svgAnalyzer.num_unknowns() == 0); +} -- 2.49.0