Debian Codegraph @

tests/2641_agxset.c

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