From: Magnus Jacobsson Date: Wed, 17 Aug 2022 19:49:03 +0000 (+0200) Subject: tests: SvgAnalyzer: GraphvizGraph: add retrieval of edge by edgeop X-Git-Tag: 6.0.1~32^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=feebf8905e5a6216ee30377cb2ce8418e80ca5cc;p=graphviz tests: SvgAnalyzer: GraphvizGraph: add retrieval of edge by edgeop --- diff --git a/tests/graphviz_edge.cpp b/tests/graphviz_edge.cpp index 87800021c..7dcad02a3 100644 --- a/tests/graphviz_edge.cpp +++ b/tests/graphviz_edge.cpp @@ -1,7 +1,9 @@ #include "graphviz_edge.h" GraphvizEdge::GraphvizEdge(SVG::SVGElement &svg_g_element) - : m_svg_g_element(svg_g_element) {} + : m_edgeop(svg_g_element.graphviz_id), m_svg_g_element(svg_g_element) {} + +std::string_view GraphvizEdge::edgeop() const { return m_edgeop; } const SVG::SVGElement &GraphvizEdge::svg_g_element() const { return m_svg_g_element; diff --git a/tests/graphviz_edge.h b/tests/graphviz_edge.h index fc83d3301..3e77d5dbe 100644 --- a/tests/graphviz_edge.h +++ b/tests/graphviz_edge.h @@ -1,5 +1,8 @@ #pragma once +#include +#include + #include "svg_element.h" /** @@ -12,11 +15,15 @@ public: GraphvizEdge() = delete; explicit GraphvizEdge(SVG::SVGElement &svg_g_element); + std::string_view edgeop() const; /// Return a non-mutable reference to the SVG `g` element corresponding to the /// edge const SVG::SVGElement &svg_g_element() const; private: + /// The 'edgeop' according to the DOT language specification. Note that this + /// is not the same as the 'id' attribute of an edge + std::string m_edgeop; /// The SVG `g` element corresponding to the edge SVG::SVGElement &m_svg_g_element; }; diff --git a/tests/graphviz_graph.cpp b/tests/graphviz_graph.cpp index 434daec13..9fbd80ff4 100644 --- a/tests/graphviz_graph.cpp +++ b/tests/graphviz_graph.cpp @@ -36,3 +36,13 @@ void GraphvizGraph::add_edge(SVG::SVGElement &svg_g_element) { const std::vector &GraphvizGraph::edges() const { return m_edges; } + +const GraphvizEdge &GraphvizGraph::edge(std::string_view edgeop) const { + for (auto &edge : m_edges) { + if (edge.edgeop() == edgeop) { + return edge; + } + } + throw std::runtime_error("Unknown edge '" + std::string{edgeop} + + "' in graph " + m_graph_id); +} diff --git a/tests/graphviz_graph.h b/tests/graphviz_graph.h index 317ed3287..f1433a8b5 100644 --- a/tests/graphviz_graph.h +++ b/tests/graphviz_graph.h @@ -21,6 +21,7 @@ public: void add_edge(SVG::SVGElement &svg_g_element); /// Add a Graphviz node to the graph void add_node(SVG::SVGElement &svg_g_element); + const GraphvizEdge &edge(std::string_view edgeop) const; /// Return a non-mutable reference to the list of Graphviz edges const std::vector &edges() const; /// Return the node with the specified `node_id` diff --git a/tests/test_rankdir.cpp b/tests/test_rankdir.cpp index c474d0f5d..16f4c885c 100644 --- a/tests/test_rankdir.cpp +++ b/tests/test_rankdir.cpp @@ -41,6 +41,7 @@ TEST_CASE("Graph rankdir", "Test that the Graphviz `rankdir` attribute affects " const auto &graph = svgAnalyzer.graphs().back(); const auto node_a = graph.node("a"); const auto node_b = graph.node("b"); + const auto edge_ab = graph.edge("a->b"); if (rankdir == "TB") { CHECK(node_a.center().is_higher_than(node_b.center())); } else if (rankdir == "BT") {