From: Magnus Jacobsson Date: Tue, 16 Aug 2022 13:38:28 +0000 (+0200) Subject: tests: add new test_rankdir test skeleton X-Git-Tag: 6.0.1~32^2~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=359eb060b9ee9f9bfb52a85031610be0a29a6bf1;p=graphviz tests: add new test_rankdir test skeleton --- diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 03d4b1a89..08bbf5b3a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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 index 000000000..77cdd0604 --- /dev/null +++ b/tests/test_rankdir.cpp @@ -0,0 +1,41 @@ +#include + +#include +#include + +#include "svg_analyzer.h" +#include "test_utilities.h" +#include +#include +#include +#include + +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); +} diff --git a/tests/test_utilities.cpp b/tests/test_utilities.cpp index a155f4648..c9c9dbfc6 100644 --- a/tests/test_utilities.cpp +++ b/tests/test_utilities.cpp @@ -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 all_rank_directions = {"TB", "BT", + "LR", "RL"}; diff --git a/tests/test_utilities.h b/tests/test_utilities.h index 7cbd0de2f..bc78525e3 100644 --- a/tests/test_utilities.h +++ b/tests/test_utilities.h @@ -20,3 +20,6 @@ extern const std::unordered_set 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 all_rank_directions;