From b45f2c0c7876f002054ecbfd3e5b60a8cb0344cf Mon Sep 17 00:00:00 2001 From: Magnus Jacobsson Date: Sat, 20 Aug 2022 18:12:54 +0200 Subject: [PATCH] tests: SVGAnalyzer: extend 'make_from_dot' method and use in test_svg_analyzer This change adds support to the SVGAnalyzer for saving a copy of the Graphviz version and build ID which are needed to exactly re-create the SVG document. Upcoming commits will extend the SVG analyzer's ability to handle new SVG attributes and add new test cases verifying its ability to re-create correct SVG containing those attributes. This change will facilitate the creation of those tests and keep the code DRY. --- tests/svg_analyzer.cpp | 14 +++++++++++--- tests/test_svg_analyzer.cpp | 21 ++------------------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/tests/svg_analyzer.cpp b/tests/svg_analyzer.cpp index 9f69376ba..eb17b8de4 100644 --- a/tests/svg_analyzer.cpp +++ b/tests/svg_analyzer.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -251,12 +252,19 @@ SVGAnalyzer SVGAnalyzer::make_from_dot(const std::string &dot_source, auto g = CGraph::AGraph{dot_source}; const auto demand_loading = false; - auto gvc = GVC::GVContext{lt_preloaded_symbols, demand_loading}; + auto gvc = + std::make_shared(lt_preloaded_symbols, demand_loading); - const auto layout = GVC::GVLayout(std::move(gvc), std::move(g), engine); + const auto layout = GVC::GVLayout(gvc, std::move(g), engine); const auto result = layout.render("svg"); - return SVGAnalyzer{result.c_str()}; + + auto svg_analyzer = SVGAnalyzer{result.c_str()}; + + svg_analyzer.set_graphviz_version(gvc->version()); + svg_analyzer.set_graphviz_build_date(gvc->buildDate()); + + return svg_analyzer; } std::string_view SVGAnalyzer::original_svg() const { return m_original_svg; } diff --git a/tests/test_svg_analyzer.cpp b/tests/test_svg_analyzer.cpp index 82286b200..3543b135c 100644 --- a/tests/test_svg_analyzer.cpp +++ b/tests/test_svg_analyzer.cpp @@ -4,11 +4,6 @@ #include #include "svg_analyzer.h" -#include -#include -#include -#include - #include "test_utilities.h" TEST_CASE("SvgAnalyzer", @@ -21,20 +16,7 @@ TEST_CASE("SvgAnalyzer", auto dot = fmt::format("digraph g1 {{node [shape={}]; a -> b}}", shape); - auto g = CGraph::AGraph{dot}; - - const auto demand_loading = false; - auto gvc = GVC::GVContext{lt_preloaded_symbols, demand_loading}; - const auto graphviz_version = gvc.version(); - const auto graphviz_build_date = gvc.buildDate(); - - const auto layout = GVC::GVLayout(std::move(gvc), std::move(g), "dot"); - - const auto result = layout.render("svg"); - const std::string original_svg{result.string_view()}; - SVGAnalyzer svg_analyzer{result.c_str()}; - svg_analyzer.set_graphviz_version(graphviz_version); - svg_analyzer.set_graphviz_build_date(graphviz_build_date); + auto svg_analyzer = SVGAnalyzer::make_from_dot(dot); const std::size_t expected_num_graphs = 1; const std::size_t expected_num_nodes = 2; @@ -133,6 +115,7 @@ TEST_CASE("SvgAnalyzer", CHECK(svg_analyzer.num_titles() == expected_num_titles); CHECK(svg_analyzer.num_texts() == expected_num_texts); + auto original_svg = svg_analyzer.original_svg(); const auto indent_size = 0; auto recreated_svg = svg_analyzer.svg_string(indent_size); -- 2.40.0