| 1 |
/// @file |
| 2 |
/// @brief accompanying test case for test_regression.py::test_2648 |
| 3 |
|
| 4 |
#include <assert.h> |
| 5 |
#include <graphviz/cgraph.h> |
| 6 |
#include <graphviz/gvc.h> |
| 7 |
#include <graphviz/gvcext.h> |
| 8 |
#include <stddef.h> |
| 9 |
#include <stdio.h> |
| 10 |
|
| 11 |
static GVC_t *gv_global_context_; |
| 12 |
|
| 13 |
#ifdef _WIN32 |
| 14 |
#define IMPORT __declspec(dllimport) |
| 15 |
#else |
| 16 |
#define IMPORT /* nothing */ |
| 17 |
#endif |
| 18 |
|
| 19 |
IMPORT extern gvplugin_library_t gvplugin_dot_layout_LTX_library; |
| 20 |
IMPORT extern gvplugin_library_t gvplugin_core_LTX_library; |
| 21 |
|
| 22 |
lt_symlist_t lt_preloaded_symbols[3]; |
| 23 |
|
| 24 |
static void RenderDot(char *dot_input, char *format) { |
| 25 |
Agraph_t *const gv_graph = agmemread(dot_input); |
| 26 |
assert(gv_graph != NULL); |
| 27 |
|
| 28 |
const int layout_result = gvLayout(gv_global_context_, gv_graph, "dot"); |
| 29 |
|
| 30 |
assert(layout_result == 0 && "layout error"); |
| 31 |
|
| 32 |
#ifdef _WIN32 |
| 33 |
const char devnull[] = "nul"; |
| 34 |
#else |
| 35 |
const char devnull[] = "/dev/null"; |
| 36 |
#endif |
| 37 |
FILE *const f = fopen(devnull, "w"); |
| 38 |
assert(f != NULL); |
| 39 |
|
| 40 |
(void)gvRender(gv_global_context_, gv_graph, format, f); |
| 41 |
(void)fclose(f); |
| 42 |
|
| 43 |
gvFreeLayout(gv_global_context_, gv_graph); |
| 44 |
agclose(gv_graph); |
| 45 |
} |
| 46 |
|
| 47 |
int main(void) { |
| 48 |
|
| 49 |
// Define plugins. This is done here rather than globally in a static |
| 50 |
// initializer because MSVC insists on strict const rules and claims the |
| 51 |
// addresses of the plugins cannot be used at compile time. |
| 52 |
lt_preloaded_symbols[0] = |
| 53 |
(lt_symlist_t){.name = "gvplugin_dot_layout_LTX_library", |
| 54 |
.address = &gvplugin_dot_layout_LTX_library}; |
| 55 |
lt_preloaded_symbols[1] = |
| 56 |
(lt_symlist_t){.name = "gvplugin_core_LTX_library", |
| 57 |
.address = &gvplugin_core_LTX_library}; |
| 58 |
|
| 59 |
gv_global_context_ = |
| 60 |
gvContextPlugins(lt_preloaded_symbols, 0 /* DEMAND_LOADING */); |
| 61 |
|
| 62 |
char *const dot = "digraph \"Root\" { \n" |
| 63 |
" label=\"Root\" \n" |
| 64 |
" graph [rankdir=LR] \n" |
| 65 |
" subgraph child { \n" |
| 66 |
" label=child \n" |
| 67 |
" } \n" |
| 68 |
"}"; |
| 69 |
RenderDot(dot, "svg"); |
| 70 |
RenderDot(dot, "png"); |
| 71 |
RenderDot(dot, "dot"); |
| 72 |
return 0; |
| 73 |
} |