Debian Codegraph @

tests/2089.c

raw
1 #include <assert.h>
2 #include <graphviz/cgraph.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5
6 int main(void) {
7
8 int ret = EXIT_SUCCESS;
9
10 #define ERR(...) \
11 do { \
12 fprintf(stderr, "%s:%d: ", __FILE__, __LINE__); \
13 fprintf(stderr, __VA_ARGS__); \
14 ret = EXIT_FAILURE; \
15 } while (0)
16
17 // create a new, empty graph
18 Agraph_t *g = agopen("foo", Agdirected, NULL);
19 assert(g != NULL);
20
21 // create a new reference counted string in this graph’s dictionary
22 char bar[] = "bar";
23 char *ag_bar1 = agstrdup(g, bar);
24 assert(ag_bar1 != NULL);
25
26 // this should not be considered an HTML-like string
27 if (aghtmlstr(ag_bar1))
28 ERR("agstrdup result incorrectly considered HTML-like\n");
29
30 // create an HTML-like string with the same content
31 char *ag_bar2 = agstrdup_html(g, bar);
32 assert(ag_bar2 != NULL);
33
34 // this should be considered an HTML-like string
35 if (!aghtmlstr(ag_bar2))
36 ERR("agstrdup_html result incorrectly not considered HTML-like\n");
37
38 // note whether ag_bar1 and ag_bar2 are actually the same pointer, so help
39 // anyone debugging this test case
40 printf("ag_bar1 == %p, ag_bar2 == %p\n", ag_bar1, ag_bar2);
41
42 // attempt the same sequence of steps but in reverse to make sure the HTML bit
43 // is not incorrectly shared in the other direction either
44
45 char baz[] = "baz";
46 char *ag_baz1 = agstrdup_html(g, baz);
47 assert(ag_baz1 != NULL);
48
49 if (!aghtmlstr(ag_baz1))
50 ERR("agstrdup_html result incorrectly not considered HTML-like\n");
51
52 char *ag_baz2 = agstrdup(g, baz);
53 assert(ag_baz2 != NULL);
54
55 if (aghtmlstr(ag_baz2))
56 ERR("agstrdup result incorrectly considered HTML-like\n");
57
58 printf("ag_baz1 == %p, ag_baz2 == %p\n", ag_baz1, ag_baz2);
59
60 agclose(g);
61
62 return ret;
63 }