Debian Codegraph @

tests/2641_agstrbind.c

raw
1 /// @file
2 /// @brief Accompanying test code for test_2641[agstrbind]
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. regular text should be findable as regular text
15 {
16 const char *const bar = agstrdup_text(g, "bar");
17 assert(bar != NULL);
18 const char *const value = agstrbind_text(g, "bar");
19 assert(value != NULL);
20 assert(!aghtmlstr(value) && "regular text was created as HTML-like text");
21 }
22
23 // 2. HTML-like text should be findable as HTML-like
24 {
25 const char *const baz = agstrdup_html(g, "baz");
26 assert(baz != NULL);
27 const char *const value = agstrbind_html(g, "baz");
28 assert(value != NULL);
29 assert(aghtmlstr(value) && "HTML-like text was created as regular text");
30 }
31
32 // 3. creating text through the ambiguous `agstrdup` API should default to
33 // regular text
34 {
35 const char *const qux = agstrdup(g, "qux");
36 assert(qux != NULL);
37 const char *const value = agstrbind(g, "qux");
38 assert(value != NULL);
39 assert(!aghtmlstr(value) && "agstrdup created new text as HTML-like");
40 }
41
42 // 4. regular text should not be findable as HTML-like text
43 {
44 const char *const quux = agstrdup_text(g, "quux");
45 assert(quux != NULL);
46 const char *const value = agstrbind_html(g, "quux");
47 assert(value == NULL);
48 }
49
50 // 5. HTML-like text should not be findable as regular text
51 {
52 const char *const corge = agstrdup_html(g, "corge");
53 assert(corge != NULL);
54 const char *const value = agstrbind_text(g, "corge");
55 assert(value == NULL);
56 }
57
58 // 6. when regular text and HTML-like text alias one another, the ambiguous
59 // `agstrbind` API should find the regular text version
60 {
61 const char *const grault_text = agstrdup_text(g, "grault");
62 assert(grault_text != NULL);
63
64 const char *const grault_html = agstrdup_html(g, "grault");
65 assert(grault_html != NULL);
66 assert(grault_text != grault_html);
67
68 const char *const value_text = agstrbind(g, "grault");
69 assert(value_text != NULL &&
70 "regular text could not be found when it aliases HTML-like text");
71 assert(!aghtmlstr(value_text) &&
72 "regular text was not found as regular text");
73 assert(value_text == grault_text &&
74 "regular text lookup matched an unexpected dictionary entry");
75
76 const char *const value_html = agstrbind_html(g, "grault");
77 assert(value_html != NULL &&
78 "HTML-like text could not be found when it aliases regular text");
79 assert(aghtmlstr(value_html) &&
80 "HTML-like text was not found as HTML-like text");
81 assert(value_html == grault_html &&
82 "HTML-like text lookup matched an unexpected dictionary entry");
83
84 const char *const value_ambiguous = agstrbind(g, "grault");
85 assert(value_ambiguous != NULL &&
86 "regular text could not be found when it aliases HTML-like text");
87 assert(!aghtmlstr(value_ambiguous) &&
88 "regular text was not found as regular text");
89 assert(value_ambiguous == grault_text &&
90 "regular text lookup matched an unexpected dictionary entry");
91 }
92
93 (void)agclose(g);
94
95 return 0;
96 }