File: 2641_agattr.c

package info (click to toggle)
graphviz 14.0.5-2
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 139,388 kB
  • sloc: ansic: 141,938; cpp: 11,957; python: 7,766; makefile: 4,043; yacc: 3,030; xml: 2,972; tcl: 2,495; sh: 1,388; objc: 1,159; java: 560; lex: 423; perl: 243; awk: 156; pascal: 139; php: 58; ruby: 49; cs: 31; sed: 1
file content (117 lines) | stat: -rw-r--r-- 4,131 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/// @file
/// @brief Accompanying test code for test_2641[agattr]

#include <assert.h>
#include <graphviz/cgraph.h>
#include <stddef.h>

int main(void) {

  // create a new, empty graph
  Agraph_t *const g = agopen("foo", Agdirected, NULL);
  assert(g != NULL);

  // 1. a regular text attribute should be created as regular text
  {
    Agsym_t *const attr = agattr_text(g, AGRAPH, "bar", "bar value");
    assert(attr != NULL);
    const char *const value = agxget(g, attr);
    assert(value != NULL);
    assert(!aghtmlstr(value) &&
           "regular text attribute was created as HTML-like");
  }

  // 2. an HTML-like text attribute should be created as HTML-like
  {
    Agsym_t *const attr = agattr_html(g, AGRAPH, "baz", "baz value");
    assert(attr != NULL);
    const char *const value = agxget(g, attr);
    assert(value != NULL);
    assert(aghtmlstr(value) &&
           "HTML-like attribute was created as regular text");
  }

  // 3. creating an attribute through the ambiguous `agattr` API should default
  // to regular text
  {
    Agsym_t *const attr = agattr(g, AGRAPH, "qux", "qux value");
    assert(attr != NULL);
    const char *const value = agxget(g, attr);
    assert(value != NULL);
    assert(!aghtmlstr(value) && "agattr created a new attribute as HTML-like");
  }

  // 4. creating an attribute through `agattr` using something we `agstrdup`ed
  // should create a regular text attribute
  {
    char *const quux = agstrdup(g, "quux value");
    Agsym_t *const attr = agattr(g, AGRAPH, "quux", quux);
    assert(attr != NULL);
    const char *const value = agxget(g, attr);
    assert(value != NULL);
    assert(!aghtmlstr(value) && "agattr did not detect agstrdup-ed value");
  }

  // 5. creating an attribute through `agattr` using something we
  // `agstrdup_html`ed should create an HTML-like attribute
  {
    char *const corge = agstrdup_html(g, "corge value");
    Agsym_t *const attr = agattr(g, AGRAPH, "corge", corge);
    assert(attr != NULL);
    const char *const value = agxget(g, attr);
    assert(value != NULL);
    assert(aghtmlstr(value) && "agattr did not detect agstrdup_html-ed value");
  }

  // 6. creating an attribute through `agattr` using something we `agstrdup`ed
  // should create a regular text attribute, even when it aliases a previously
  // created regular text value
  {
    char *const bar = agstrdup(g, "bar value");
    Agsym_t *const attr = agattr(g, AGRAPH, "grault", bar);
    assert(attr != NULL);
    const char *const value = agxget(g, attr);
    assert(value != NULL);
    assert(!aghtmlstr(value) && "agattr did not detect agstrdup-ed value");
  }

  // 7. creating an attribute through `agattr` using something we `agstrdup`ed
  // should create a regular text attribute, even when it aliases a previously
  // created HTML-like value
  {
    char *const baz = agstrdup(g, "baz value");
    Agsym_t *const attr = agattr(g, AGRAPH, "garply", baz);
    assert(attr != NULL);
    const char *const value = agxget(g, attr);
    assert(value != NULL);
    assert(!aghtmlstr(value) && "agattr did not detect agstrdup-ed value");
  }

  // 8. creating an attribute through `agattr` using something we
  // `agstrdup_html`ed should create an HTML-like attribute, even when it
  // aliases a previously created regular text value
  {
    char *const bar = agstrdup_html(g, "bar value");
    Agsym_t *const attr = agattr(g, AGRAPH, "waldo", bar);
    assert(attr != NULL);
    const char *const value = agxget(g, attr);
    assert(value != NULL);
    assert(aghtmlstr(value) && "agattr did not detect agstrdup_html-ed value");
  }

  // 9. creating an attribute through `agattr` using something we
  // `agstrdup_html`ed should create an HTML-like attribute, even when it
  // aliases a previously created HTML-like value
  {
    char *const baz = agstrdup_html(g, "baz value");
    Agsym_t *const attr = agattr(g, AGRAPH, "fred", baz);
    assert(attr != NULL);
    const char *const value = agxget(g, attr);
    assert(value != NULL);
    assert(aghtmlstr(value) && "agattr did not detect agstrdup_html-ed value");
  }

  (void)agclose(g);

  return 0;
}