From: Magnus Jacobsson Date: Mon, 5 Jul 2021 09:54:05 +0000 (+0200) Subject: change the always pass test to a simple Graphviz test X-Git-Tag: 2.48.0~12^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=40c3c1d66ddf3669013e4007279cc42a0612557b;p=graphviz change the always pass test to a simple Graphviz test 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. --- diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5d87a4463..c2169ab6e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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 ) diff --git a/tests/test_simple.cpp b/tests/test_simple.cpp index f01f5c41c..78daf2e0e 100644 --- a/tests/test_simple.cpp +++ b/tests/test_simple.cpp @@ -1,4 +1,40 @@ +#include + #include -TEST_CASE("always pass") { +#include +#include + +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); }