Debian Codegraph @

tests/2641_agsafeset.c

raw
1 /// @file
2 /// @brief Accompanying test code for test_2641[agsafeset]
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 const int rc = agsafeset_text(g, "bar", "bar value", "bar default");
17 assert(rc == 0);
18 const char *const value = agget(g, "bar");
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 const int rc = agsafeset_html(g, "baz", "baz value", "baz default");
27 assert(rc == 0);
28 const char *const value = agget(g, "baz");
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 `agsafeset` API should
35 // default to regular text
36 {
37 const int rc = agsafeset(g, "qux", "qux value", "qux default");
38 assert(rc == 0);
39 const char *const value = agget(g, "qux");
40 assert(value != NULL);
41 assert(!aghtmlstr(value) &&
42 "agsafeset created a new attribute as HTML-like");
43 }
44
45 // 4. creating an attribute through `agsafeset` using something we
46 // `agstrdup`ed should create a regular text attribute
47 {
48 const char *const quux = agstrdup(g, "quux value");
49 assert(quux != NULL);
50 const int rc = agsafeset(g, "quux", quux, "quux default");
51 assert(rc == 0);
52 const char *const value = agget(g, "quux");
53 assert(value != NULL);
54 assert(!aghtmlstr(value) && "agsafeset did not detect agstrdup-ed value");
55 }
56
57 // 5. creating an attribute through `agsafeset` using something we
58 // `agstrdup_html`ed should create an HTML-like attribute
59 {
60 const char *const corge = agstrdup_html(g, "corge value");
61 assert(corge != NULL);
62 const int rc = agsafeset(g, "corge", corge, "corge default");
63 assert(rc == 0);
64 const char *const value = agget(g, "corge");
65 assert(value != NULL);
66 assert(aghtmlstr(value) &&
67 "agsafeset did not detect agstrdup_html-ed value");
68 }
69
70 // 6. creating an attribute through `agsafeset` using something we
71 // `agstrdup`ed should create a regular text attribute, even when it aliases
72 // a previously created regular text value
73 {
74 const char *const bar = agstrdup(g, "bar value");
75 assert(bar != NULL);
76 const int rc = agsafeset(g, "bar", bar, "bar default");
77 assert(rc == 0);
78 const char *const value = agget(g, "bar");
79 assert(value != NULL);
80 assert(!aghtmlstr(value) && "agsafeset did not detect agstrdup-ed value");
81 }
82
83 // 7. creating an attribute through `agsafeset` using something we
84 // `agstrdup`ed should create a regular text attribute, even when it aliases a
85 // previously created HTML-like value
86 {
87 const char *const baz = agstrdup(g, "baz value");
88 assert(baz != NULL);
89 const int rc = agsafeset(g, "baz", baz, "baz default");
90 assert(rc == 0);
91 const char *const value = agget(g, "baz");
92 assert(value != NULL);
93 assert(!aghtmlstr(value) && "agsafeset did not detect agstrdup-ed value");
94 }
95
96 // 8. creating an attribute through `agsafeset` using something we
97 // `agstrdup_html`ed should create an HTML-like attribute, even when it
98 // aliases a previously created regular text value
99 {
100 const char *const bar = agstrdup_html(g, "bar value");
101 assert(bar != NULL);
102 const int rc = agsafeset(g, "bar", bar, "bar default");
103 assert(rc == 0);
104 const char *const value = agget(g, "bar");
105 assert(value != NULL);
106 assert(aghtmlstr(value) &&
107 "agsafeset did not detect agstrdup_html-ed value");
108 }
109
110 // 9. creating an attribute through `agsafeset` using something we
111 // `agstrdup_html`ed should create an HTML-like attribute, even when it
112 // aliases a previously created HTML-like value
113 {
114 const char *const baz = agstrdup_html(g, "baz value");
115 assert(baz != NULL);
116 const int rc = agsafeset(g, "baz", baz, "baz default");
117 assert(rc == 0);
118 const char *const value = agget(g, "baz");
119 assert(value != NULL);
120 assert(aghtmlstr(value) &&
121 "agsafeset did not detect agstrdup_html-ed value");
122 }
123
124 (void)agclose(g);
125
126 return 0;
127 }