]> granicus.if.org Git - graphviz/commitdiff
change the always pass test to a simple Graphviz test
authorMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Mon, 5 Jul 2021 09:54:05 +0000 (11:54 +0200)
committerMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Wed, 7 Jul 2021 04:53:27 +0000 (06:53 +0200)
The test now uses the existing C API to render SVG from DOT source
code.

To support this, the commit also adds the necessary Graphviz libraries
and the dot_builtins to the common test library and the necessary
include directories to the macro creating the individual test
executables.

tests/CMakeLists.txt
tests/test_simple.cpp

index 5d87a446306e0eb758a3fd18f9a3f1952cc338f8..c2169ab6e56a290da762ffc19f1d64bba3b81835 100644 (file)
@@ -12,16 +12,35 @@ endif()
 # separate test can be as small as possible
 add_library(test_common STATIC
             catch2_main.cpp
+            ../cmd/dot/dot_builtins.c
     )
 set_target_properties(test_common PROPERTIES CXX_STANDARD 20)
 set_target_properties(test_common PROPERTIES CXX_STANDARD_REQUIRED ON)
+target_include_directories(test_common PRIVATE
+    ${GRAPHVIZ_LIB_DIR}
+)
 target_link_libraries(test_common PUBLIC Catch2::Catch2)
+target_link_libraries(test_common PUBLIC
+    gvplugin_core
+    gvplugin_dot_layout
+    gvplugin_gd
+    gvplugin_neato_layout
+    cgraph
+)
 
 macro(create_test testname)
     add_executable(test_${testname} test_${testname}.cpp)
     set_target_properties(test_${testname} PROPERTIES CXX_STANDARD 20)
     set_target_properties(test_${testname} PROPERTIES CXX_STANDARD_REQUIRED ON)
     add_test(NAME test_${testname} COMMAND test_${testname})
+    target_include_directories(test_${testname} PRIVATE
+        ${GRAPHVIZ_LIB_DIR}
+        ${GRAPHVIZ_LIB_DIR}/cdt
+        ${GRAPHVIZ_LIB_DIR}/cgraph
+        ${GRAPHVIZ_LIB_DIR}/common
+        ${GRAPHVIZ_LIB_DIR}/gvc
+        ${GRAPHVIZ_LIB_DIR}/pathplan
+    )
     target_link_libraries(test_${testname} PRIVATE
         test_common
     )
index f01f5c41ccab9da874576ef025f8f2c6d4094d28..78daf2e0e11c8c7c65145d1088479906bad84341 100644 (file)
@@ -1,4 +1,40 @@
+#include <string_view>
+
 #include <catch2/catch.hpp>
 
-TEST_CASE("always pass") {
+#include <cgraph/cgraph.h>
+#include <gvc/gvc.h>
+
+TEST_CASE("digraph without any nodes") {
+  auto gvc = gvContextPlugins(lt_preloaded_symbols, false);
+
+  auto dot = "digraph {}";
+  auto g = agmemread(dot);
+
+  REQUIRE(g != nullptr);
+
+  {
+    const auto rc = gvLayout(gvc, g, "dot");
+
+    REQUIRE(rc == 0);
+  }
+
+  char *result = nullptr;
+  unsigned length = 0;
+  {
+    const auto rc = gvRenderData(gvc, g, "svg", &result, &length);
+
+    REQUIRE(rc == 0);
+  }
+
+  REQUIRE(result != nullptr);
+  REQUIRE(length > 0);
+
+  REQUIRE(std::string_view(result, length).find("svg") !=
+          std::string_view::npos);
+
+  gvFreeRenderData(result);
+  gvFreeLayout(gvc, g);
+  agclose(g);
+  gvFreeContext(gvc);
 }