From be5b133986b441c3e8a761bfe9e987ddc1ab96e8 Mon Sep 17 00:00:00 2001 From: Magnus Jacobsson Date: Wed, 17 Aug 2022 12:54:36 +0200 Subject: [PATCH] tests: SvgAnalyzer: add a graphvizGraph class --- tests/CMakeLists.txt | 2 ++ tests/graphviz_graph.cpp | 24 +++++++++++++++++++++++ tests/graphviz_graph.h | 42 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 tests/graphviz_graph.cpp create mode 100644 tests/graphviz_graph.h diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9f48cd86e..03d4b1a89 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -14,6 +14,8 @@ add_library(test_common SHARED catch2_main.cpp graphviz_edge.cpp graphviz_edge.h + graphviz_graph.cpp + graphviz_graph.h graphviz_node.h graphviz_node.cpp test_utilities.cpp diff --git a/tests/graphviz_graph.cpp b/tests/graphviz_graph.cpp new file mode 100644 index 000000000..183a723ad --- /dev/null +++ b/tests/graphviz_graph.cpp @@ -0,0 +1,24 @@ +#include "graphviz_graph.h" + +GraphvizGraph::GraphvizGraph(SVG::SVGElement &svg_g_element) + : m_svg_g_element(svg_g_element) {} + +void GraphvizGraph::add_node(SVG::SVGElement &svg_g_element) { + m_nodes.emplace_back(svg_g_element); +} + +const std::vector &GraphvizGraph::nodes() const { + return m_nodes; +} + +const SVG::SVGElement &GraphvizGraph::svg_g_element() const { + return m_svg_g_element; +} + +void GraphvizGraph::add_edge(SVG::SVGElement &svg_g_element) { + m_edges.emplace_back(svg_g_element); +} + +const std::vector &GraphvizGraph::edges() const { + return m_edges; +} diff --git a/tests/graphviz_graph.h b/tests/graphviz_graph.h new file mode 100644 index 000000000..e55551fa3 --- /dev/null +++ b/tests/graphviz_graph.h @@ -0,0 +1,42 @@ +#pragma once + +#include +#include +#include + +#include "graphviz_edge.h" +#include "graphviz_node.h" + +/** + * @brief The GraphvizGraph class represents a Graphviz graph according to the + * DOT language + */ + +class GraphvizGraph { +public: + GraphvizGraph() = delete; + explicit GraphvizGraph(SVG::SVGElement &g_element); + + /// Add a Graphviz edge to the graph + void add_edge(SVG::SVGElement &svg_g_element); + /// Add a Graphviz node to the graph + void add_node(SVG::SVGElement &svg_g_element); + /// Return a non-mutable reference to the list of Graphviz edges + const std::vector &edges() const; + /// Return a non-mutable reference to the list of Graphviz nodes + const std::vector &nodes() const; + /// Return a non-mutable reference to the SVG `g` element corresponding to the + /// graph + const SVG::SVGElement &svg_g_element() const; + +private: + /// A list of edges belonging to this graph + std::vector m_edges; + /// The `ID` according to the DOT language specification. Note that this is + /// not the same as the `id` attribute of a graph + std::string m_graph_id; + /// A list of nodes belonging to this graph + std::vector m_nodes; + /// The SVG `g` element corresponding to the graph + SVG::SVGElement &m_svg_g_element; +}; -- 2.40.0