Debian Codegraph @

tests/2641_agattr.c

raw
1 /// @file
2 /// @brief Accompanying test code for test_2641[agattr]
3
4 #include <assert.h>
5 #include <graphviz/cgraph.h>
6 #include <stddef.h>
7
8 int main(void) {
9
10 // create a new, empty graph
11 Agraph_t *const g = agopen("foo", Agdirected, NULL);
12 assert(g != NULL);
13
14 // 1. a regular text attribute should be created as regular text
15 {
16 Agsym_t *const attr = agattr_text(g, AGRAPH, "bar", "bar value");
17 assert(attr != NULL);
18 const char *const value = agxget(g, attr);
19 assert(value != NULL);
20 assert(!aghtmlstr(value) &&
21 "regular text attribute was created as HTML-like");
22 }
23
24 // 2. an HTML-like text attribute should be created as HTML-like
25 {
26 Agsym_t *const attr = agattr_html(g, AGRAPH, "baz", "baz value");
27 assert(attr != NULL);
28 const char *const value = agxget(g, attr);
29 assert(value != NULL);
30 assert(aghtmlstr(value) &&
31 "HTML-like attribute was created as regular text");
32 }
33
34 // 3. creating an attribute through the ambiguous `agattr` API should default
35 // to regular text
36 {
37 Agsym_t *const attr = agattr(g, AGRAPH, "qux", "qux value");
38 assert(attr != NULL);
39 const char *const value = agxget(g, attr);
40 assert(value != NULL);
41 assert(!aghtmlstr(value) && "agattr created a new attribute as HTML-like");
42 }
43
44 // 4. creating an attribute through `agattr` using something we `agstrdup`ed
45 // should create a regular text attribute
46 {
47 char *const quux = agstrdup(g, "quux value");
48 Agsym_t *const attr = agattr(g, AGRAPH, "quux", quux);
49 assert(attr != NULL);
50 const char *const value = agxget(g, attr);
51 assert(value != NULL);
52 assert(!aghtmlstr(value) && "agattr did not detect agstrdup-ed value");
53 }
54
55 // 5. creating an attribute through `agattr` using something we
56 // `agstrdup_html`ed should create an HTML-like attribute
57 {
58 char *const corge = agstrdup_html(g, "corge value");
59 Agsym_t *const attr = agattr(g, AGRAPH, "corge", corge);
60 assert(attr != NULL);
61 const char *const value = agxget(g, attr);
62 assert(value != NULL);
63 assert(aghtmlstr(value) && "agattr did not detect agstrdup_html-ed value");
64 }
65
66 // 6. creating an attribute through `agattr` using something we `agstrdup`ed
67 // should create a regular text attribute, even when it aliases a previously
68 // created regular text value
69 {
70 char *const bar = agstrdup(g, "bar value");
71 Agsym_t *const attr = agattr(g, AGRAPH, "grault", bar);
72 assert(attr != NULL);
73 const char *const value = agxget(g, attr);
74 assert(value != NULL);
75 assert(!aghtmlstr(value) && "agattr did not detect agstrdup-ed value");
76 }
77
78 // 7. creating an attribute through `agattr` using something we `agstrdup`ed
79 // should create a regular text attribute, even when it aliases a previously
80 // created HTML-like value
81 {
82 char *const baz = agstrdup(g, "baz value");
83 Agsym_t *const attr = agattr(g, AGRAPH, "garply", baz);
84 assert(attr != NULL);
85 const char *const value = agxget(g, attr);
86 assert(value != NULL);
87 assert(!aghtmlstr(value) && "agattr did not detect agstrdup-ed value");
88 }
89
90 // 8. creating an attribute through `agattr` using something we
91 // `agstrdup_html`ed should create an HTML-like attribute, even when it
92 // aliases a previously created regular text value
93 {
94 char *const bar = agstrdup_html(g, "bar value");
95 Agsym_t *const attr = agattr(g, AGRAPH, "waldo", bar);
96 assert(attr != NULL);
97 const char *const value = agxget(g, attr);
98 assert(value != NULL);
99 assert(aghtmlstr(value) && "agattr did not detect agstrdup_html-ed value");
100 }
101
102 // 9. creating an attribute through `agattr` using something we
103 // `agstrdup_html`ed should create an HTML-like attribute, even when it
104 // aliases a previously created HTML-like value
105 {
106 char *const baz = agstrdup_html(g, "baz value");
107 Agsym_t *const attr = agattr(g, AGRAPH, "fred", baz);
108 assert(attr != NULL);
109 const char *const value = agxget(g, attr);
110 assert(value != NULL);
111 assert(aghtmlstr(value) && "agattr did not detect agstrdup_html-ed value");
112 }
113
114 (void)agclose(g);
115
116 return 0;
117 }