]> granicus.if.org Git - graphviz/commitdiff
tests: add new test_rankdir test skeleton
authorMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Tue, 16 Aug 2022 13:38:28 +0000 (15:38 +0200)
committerMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Tue, 23 Aug 2022 06:19:35 +0000 (08:19 +0200)
tests/CMakeLists.txt
tests/test_rankdir.cpp [new file with mode: 0644]
tests/test_utilities.cpp
tests/test_utilities.h

index 03d4b1a89bd701aba965f6cfed6ae03e28d3bb78..08bbf5b3a365770500c8468af5fe1406faf4c1da 100644 (file)
@@ -83,6 +83,7 @@ CREATE_TEST(GVContext_render_svg)
 CREATE_TEST(GVLayout_construction)
 CREATE_TEST(GVLayout_render)
 CREATE_TEST(neatopack)
+CREATE_TEST(rankdir)
 CREATE_TEST(simple)
 CREATE_TEST(subgraph_layout)
 CREATE_TEST(subgraphs)
diff --git a/tests/test_rankdir.cpp b/tests/test_rankdir.cpp
new file mode 100644 (file)
index 0000000..77cdd06
--- /dev/null
@@ -0,0 +1,41 @@
+#include <string_view>
+
+#include <catch2/catch.hpp>
+#include <fmt/format.h>
+
+#include "svg_analyzer.h"
+#include "test_utilities.h"
+#include <cgraph++/AGraph.h>
+#include <gvc++/GVContext.h>
+#include <gvc++/GVLayout.h>
+#include <gvc++/GVRenderData.h>
+
+TEST_CASE("Graph rankdir", "Test that the Graphviz `rankdir` attribute affects "
+                           "the relative placement of nodes and edges "
+                           "correctly when the 'dot` layout engine is used") {
+
+  const auto rankdir = GENERATE(from_range(all_rank_directions));
+  INFO(fmt::format("Rankdir: {}", rankdir));
+
+  const auto shape = GENERATE_COPY(filter(
+      [](std::string_view shape) {
+        return !node_shapes_without_svg_shape.contains(shape);
+      },
+      from_range(all_node_shapes)));
+  INFO(fmt::format("Shape: {}", shape));
+
+  auto dot = fmt::format(
+      "digraph g1 {{rankdir={}; node [shape={} fontname=Courier]; a -> b}}",
+      rankdir, shape);
+  auto g = CGraph::AGraph{dot};
+
+  const auto demand_loading = false;
+  auto gvc = GVC::GVContext{lt_preloaded_symbols, demand_loading};
+
+  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.graphs().size() == 1);
+}
index a155f4648aab37b8b51f086fdd5ab106e5fc9a63..c9c9dbfc65ecce0846d21cc369577917bbcbcc45 100644 (file)
@@ -153,3 +153,6 @@ bool contains_ellipse_shape(std::string_view shape) {
   return node_shapes_consisting_of_ellipse.contains(shape) ||
          node_shapes_consisting_of_ellipse_and_polyline.contains(shape);
 }
+
+const std::unordered_set<std::string_view> all_rank_directions = {"TB", "BT",
+                                                                  "LR", "RL"};
index 7cbd0de2fbabd25ac1521c1e46bf56a399a77170..bc78525e3cbf5956497c7cb319077bf9e3ccdaa7 100644 (file)
@@ -20,3 +20,6 @@ extern const std::unordered_set<std::string_view> node_shapes_without_svg_shape;
 
 bool contains_ellipse_shape(std::string_view shape);
 bool contains_polygon_shape(std::string_view shape);
+
+/// rank directions
+extern const std::unordered_set<std::string_view> all_rank_directions;