Debian Codegraph @

tests/2641_agset.c

raw
1 /// @file
2 /// @brief Accompanying test code for test_2641[agset]
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 // create the attribute initially as text
17 Agsym_t *const attr = agattr_text(g, AGRAPH, "bar", "bar placeholder");
18 assert(attr != NULL);
19 // assign it a value, explicitly as regular text
20 const int rc = agset_text(g, "bar", "bar value");
21 assert(rc == 0);
22 const char *const value = agget(g, "bar");
23 assert(value != NULL);
24 assert(!aghtmlstr(value) &&
25 "regular text attribute was created as HTML-like");
26 }
27
28 // 2. an HTML-like text attribute should be created as HTML-like
29 {
30 // create the attribute initially as text
31 Agsym_t *const attr = agattr_text(g, AGRAPH, "baz", "baz placeholder");
32 assert(attr != NULL);
33 // assign it a value, explicitly as HTML-like
34 char *const baz = "baz";
35 const int rc = agset_html(g, baz, "baz value");
36 assert(rc == 0);
37 const char *const value = agget(g, "baz");
38 assert(value != NULL);
39 assert(aghtmlstr(value) &&
40 "HTML-like attribute was created as regular text");
41 }
42
43 // 3. creating an attribute through the ambiguous `agset` API should default
44 // to regular text
45 { // create an attribute initially as text
46 Agsym_t *const attr = agattr_text(g, AGRAPH, "qux", "qux placeholder");
47 assert(attr != NULL);
48 // assign it a value, ambiguously
49 const int rc = agset(g, "qux", "qux value");
50 assert(rc == 0);
51 const char *const value = agget(g, "qux");
52 assert(value != NULL);
53 assert(!aghtmlstr(value) && "agset created a new attribute as HTML-like");
54 }
55 {
56 // create an attribute initially as HTML-like
57 Agsym_t *const attr = agattr_html(g, AGRAPH, "quux", "quux placeholder");
58 assert(attr != NULL);
59 // assign it a value, ambiguously
60 const int rc = agset(g, "quux", "quux value");
61 assert(rc == 0);
62 const char *const value = agget(g, "quux");
63 assert(value != NULL);
64 assert(!aghtmlstr(value) && "agset created a new attribute as HTML-like");
65 }
66
67 // 4. creating an attribute through `agset` using something we `agstrdup`ed
68 // should create a regular text attribute
69 { // create an attribute initially as text
70 Agsym_t *const attr = agattr_text(g, AGRAPH, "corge", "corge placeholder");
71 assert(attr != NULL);
72 // assign it a value that was `agstrdup`ed
73 const char *const corge = agstrdup(g, "corge value");
74 const int rc = agset(g, "corge", corge);
75 assert(rc == 0);
76 const char *const value = agget(g, "corge");
77 assert(value != NULL);
78 assert(!aghtmlstr(value) && "agset did not detect agstrdup-ed value");
79 }
80 {
81 // create an attribute initially as HTML-like
82 Agsym_t *const attr =
83 agattr_html(g, AGRAPH, "grault", "grault placeholder");
84 assert(attr != NULL);
85 // assign it a value that was `agstrdup`ed
86 const char *const grault = agstrdup(g, "grault value");
87 const int rc = agset(g, "grault", grault);
88 assert(rc == 0);
89 const char *const value = agget(g, "grault");
90 assert(value != NULL);
91 assert(!aghtmlstr(value) && "agset did not detect agstrdup-ed value");
92 }
93
94 // 5. creating an attribute through `agset` using something we
95 // `agstrdup_html`ed should create an HTML-like attribute
96 { // create an attribute initially as text
97 Agsym_t *const attr =
98 agattr_text(g, AGRAPH, "garply", "garply placeholder");
99 assert(attr != NULL);
100 // assign it a value that was `agstrdup_html`ed
101 const char *const garply = agstrdup_html(g, "garply value");
102 const int rc = agset(g, "garply", garply);
103 assert(rc == 0);
104 const char *const value = agget(g, "garply");
105 assert(value != NULL);
106 assert(aghtmlstr(value) && "agset did not detect agstrdup_html-ed value");
107 }
108 {
109 // create an attribute initially as HTML-like
110 Agsym_t *const attr = agattr_html(g, AGRAPH, "waldo", "waldo placeholder");
111 assert(attr != NULL);
112 // assign it a value that was `agstrdup_html`ed
113 const char *const waldo = agstrdup_html(g, "waldo value");
114 const int rc = agset(g, "waldo", waldo);
115 assert(rc == 0);
116 const char *const value = agget(g, "waldo");
117 assert(value != NULL);
118 assert(aghtmlstr(value) && "agset did not detect agstrdup_html-ed value");
119 }
120
121 // 6. creating an attribute through `agset` using something we `agstrdup`ed
122 // should create a regular text attribute, even when it aliases a previously
123 // created regular text value
124 { // create an attribute initially as text
125 Agsym_t *const attr = agattr_text(g, AGRAPH, "fred", "fred placeholder");
126 assert(attr != NULL);
127 // assign it a value that was `agstrdup`ed
128 const char *const corge = agstrdup(g, "corge value");
129 const int rc = agset(g, "fred", corge);
130 assert(rc == 0);
131 const char *const value = agget(g, "fred");
132 assert(value != NULL);
133 assert(!aghtmlstr(value) && "agset did not detect agstrdup-ed value");
134 }
135 {
136 // create an attribute initially as HTML-like
137 Agsym_t *const attr = agattr_html(g, AGRAPH, "plugh", "plugh placeholder");
138 assert(attr != NULL);
139 // assign it a value that was `agstrdup`ed
140 const char *const grault = agstrdup(g, "grault value");
141 const int rc = agset(g, "plugh", grault);
142 assert(rc == 0);
143 const char *const value = agget(g, "plugh");
144 assert(value != NULL);
145 assert(!aghtmlstr(value) && "agset did not detect agstrdup-ed value");
146 }
147
148 // 7. creating an attribute through `agset` using something we `agstrdup`ed
149 // should create a regular text attribute, even when it aliases a previously
150 // created HTML-like value
151 { // create an attribute initially as text
152 Agsym_t *const attr = agattr_text(g, AGRAPH, "xyzzy", "xyzzy placeholder");
153 assert(attr != NULL);
154 // assign it a value that was `agstrdup`ed
155 const char *const garply = agstrdup_text(g, "garply value");
156 const int rc = agset(g, "xyzzy", garply);
157 assert(rc == 0);
158 const char *const value = agget(g, "xyzzy");
159 assert(value != NULL);
160 assert(!aghtmlstr(value) && "agset did not detect agstrdup-ed value");
161 }
162 {
163 // create an attribute initially as HTML-like
164 Agsym_t *const attr = agattr_html(g, AGRAPH, "thud", "thud placeholder");
165 assert(attr != NULL);
166 // assign it a value that was `agstrdup`ed
167 const char *const waldo = agstrdup_text(g, "waldo value");
168 const int rc = agset(g, "thud", waldo);
169 assert(rc == 0);
170 const char *const value = agget(g, "thud");
171 assert(value != NULL);
172 assert(!aghtmlstr(value) && "agset did not detect agstrdup-ed value");
173 }
174
175 // 8. creating an attribute through `agset` using something we
176 // `agstrdup_html`ed should create an HTML-like attribute, even when it
177 // aliases a previously created regular text value
178 { // create an attribute initially as text
179 Agsym_t *const attr =
180 agattr_text(g, AGRAPH, "bazola", "bazola placeholder");
181 assert(attr != NULL);
182 // assign it a value that was `agstrdup_html`ed
183 const char *const corge = agstrdup_html(g, "corge value");
184 const int rc = agset(g, "bazola", corge);
185 assert(rc == 0);
186 const char *const value = agget(g, "bazola");
187 assert(value != NULL);
188 assert(aghtmlstr(value) && "agset did not detect agstrdup_html-ed value");
189 }
190 {
191 // create an attribute initially as HTML-like
192 Agsym_t *const attr =
193 agattr_html(g, AGRAPH, "ztesch", "ztesch placeholder");
194 assert(attr != NULL);
195 // assign it a value that was `agstrdup_html`ed
196 const char *const grault = agstrdup_html(g, "grault value");
197 const int rc = agset(g, "ztesch", grault);
198 assert(rc == 0);
199 const char *const value = agget(g, "ztesch");
200 assert(value != NULL);
201 assert(aghtmlstr(value) && "agset did not detect agstrdup_html-ed value");
202 }
203
204 // 9. creating an attribute through `agset` using something we
205 // `agstrdup_html`ed should create an HTML-like attribute, even when it
206 // aliases a previously created HTML-like value
207 { // create an attribute initially as text
208 Agsym_t *const attr = agattr_text(g, AGRAPH, "grunt", "grunt placeholder");
209 assert(attr != NULL);
210 // assign it a value that was `agstrdup_html`ed
211 const char *const garply = agstrdup_html(g, "garply value");
212 const int rc = agset(g, "grunt", garply);
213 assert(rc == 0);
214 const char *const value = agget(g, "grunt");
215 assert(value != NULL);
216 assert(aghtmlstr(value) && "agset did not detect agstrdup_html-ed value");
217 }
218 {
219 // create an attribute initially as HTML-like
220 Agsym_t *const attr = agattr_html(g, AGRAPH, "gorp", "gorp placeholder");
221 assert(attr != NULL);
222 // assign it a value that was `agstrdup_html`ed
223 const char *const waldo = agstrdup_html(g, "waldo value");
224 const int rc = agset(g, "gorp", waldo);
225 assert(rc == 0);
226 const char *const value = agget(g, "gorp");
227 assert(value != NULL);
228 assert(aghtmlstr(value) && "agset did not detect agstrdup_html-ed value");
229 }
230
231 (void)agclose(g);
232
233 return 0;
234 }