]> granicus.if.org Git - graphviz/commitdiff
tests: SvgAnalyzer: GraphvizGraph: add retrieval of edge by edgeop
authorMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Wed, 17 Aug 2022 19:49:03 +0000 (21:49 +0200)
committerMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Tue, 23 Aug 2022 06:19:35 +0000 (08:19 +0200)
tests/graphviz_edge.cpp
tests/graphviz_edge.h
tests/graphviz_graph.cpp
tests/graphviz_graph.h
tests/test_rankdir.cpp

index 87800021ccd8f0ca8d3fc4d27928e1ea3d568477..7dcad02a3144fa117698d857874969fb1adc3cca 100644 (file)
@@ -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;
index fc83d3301ad11ff4b3092d71499fbc032663ba84..3e77d5dbe653dfb96352c59a8ecd501a2d188d80 100644 (file)
@@ -1,5 +1,8 @@
 #pragma once
 
+#include <string>
+#include <string_view>
+
 #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;
 };
index 434daec13ca5b0093184b067d48d366a00a1a2f3..9fbd80ff4cb2954dd5441e914408b48a2911a3ac 100644 (file)
@@ -36,3 +36,13 @@ void GraphvizGraph::add_edge(SVG::SVGElement &svg_g_element) {
 const std::vector<GraphvizEdge> &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);
+}
index 317ed32875597b2e8d5afa51307b5a441bf6651d..f1433a8b5f8ac769b8ecd3d749d9dbd05a866747 100644 (file)
@@ -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<GraphvizEdge> &edges() const;
   /// Return the node with the specified `node_id`
index c474d0f5d0f9d9ba03900b6ec246feb3d23d5dbf..16f4c885c8528676e58fa2eb42a3d3d1e22824d6 100644 (file)
@@ -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") {