| 1 |
#include <cstring> |
| 2 |
|
| 3 |
#include <catch2/catch_all.hpp> |
| 4 |
|
| 5 |
#include <cgraph++/AGraph.h> |
| 6 |
#include <gvc++/GVContext.h> |
| 7 |
#include <gvc++/GVLayout.h> |
| 8 |
#include <gvc++/GVRenderData.h> |
| 9 |
|
| 10 |
TEST_CASE("Rendered SVG can be retrieved as a string_view or as a C string") { |
| 11 |
const auto demand_loading = false; |
| 12 |
auto gvc = |
| 13 |
std::make_shared<GVC::GVContext>(lt_preloaded_symbols, demand_loading); |
| 14 |
|
| 15 |
auto dot = "digraph {a}"; |
| 16 |
auto g = std::make_shared<CGraph::AGraph>(dot); |
| 17 |
|
| 18 |
const auto layout = GVC::GVLayout(gvc, g, "dot"); |
| 19 |
|
| 20 |
const auto result = layout.render("svg"); |
| 21 |
// just check that we seem to have gotten the correct format |
| 22 |
REQUIRE(result.string_view().find("<!DOCTYPE svg") != std::string_view::npos); |
| 23 |
REQUIRE(result.string_view().compare(result.c_str()) == 0); |
| 24 |
REQUIRE(result.string_view().length() == result.length()); |
| 25 |
REQUIRE(std::strlen(result.c_str()) == result.length()); |
| 26 |
} |
| 27 |
|
| 28 |
TEST_CASE("Rendering in an unknown format throws an exception") { |
| 29 |
const auto demand_loading = false; |
| 30 |
auto gvc = |
| 31 |
std::make_shared<GVC::GVContext>(lt_preloaded_symbols, demand_loading); |
| 32 |
|
| 33 |
auto dot = "digraph {a}"; |
| 34 |
auto g = std::make_shared<CGraph::AGraph>(dot); |
| 35 |
|
| 36 |
const auto layout = GVC::GVLayout(gvc, g, "dot"); |
| 37 |
|
| 38 |
REQUIRE_THROWS_AS(layout.render("UNKNOWN_FORMAT"), std::runtime_error); |
| 39 |
} |