]> git.ozlabs.org Git - ccan/blob - ccan/cdump/test/run-attributes.c
cdump: ignore __attribute__ (gcc extension).
[ccan] / ccan / cdump / test / run-attributes.c
1 #include <ccan/cdump/cdump.h>
2 /* Include the C files directly. */
3 #include <ccan/cdump/cdump.c>
4 #include <ccan/tap/tap.h>
5
6 int main(void)
7 {
8         struct cdump_definitions *defs;
9         const struct cdump_type *t;
10         char *ctx = tal(NULL, char), *problems;
11
12         /* This is how many tests you plan to run */
13         plan_tests(37);
14
15         defs = cdump_extract(ctx, "__attribute__((xxx)) enum foo __attribute__((xxx)) { BAR } __attribute__((xxx));", NULL);
16         ok1(defs);
17         ok1(tal_parent(defs) == ctx);
18
19         ok1(strmap_empty(&defs->structs));
20         ok1(strmap_empty(&defs->unions));
21         t = strmap_get(&defs->enums, "foo");
22         ok1(t);
23         ok1(t->kind == CDUMP_ENUM);
24         ok1(streq(t->name, "foo"));
25         ok1(tal_count(t->u.enum_vals) == 1);
26         ok1(streq(t->u.enum_vals[0].name, "BAR"));
27         ok1(!t->u.enum_vals[0].value);
28
29         defs = cdump_extract(ctx, "__attribute__((xxx)) struct foo __attribute__((xxx)) { int __attribute__((xxx)) x __attribute__((xxx)); } __attribute__((xxx));", &problems);
30         ok1(defs);
31         ok1(tal_parent(defs) == ctx);
32         ok1(!problems);
33
34         ok1(strmap_empty(&defs->enums));
35         ok1(strmap_empty(&defs->unions));
36         t = strmap_get(&defs->structs, "foo");
37         ok1(t);
38         ok1(t->kind == CDUMP_STRUCT);
39         ok1(streq(t->name, "foo"));
40         ok1(tal_count(t->u.members) == 1);
41         ok1(streq(t->u.members[0].name, "x"));
42         ok1(t->u.members[0].type->kind == CDUMP_UNKNOWN);
43         ok1(streq(t->u.members[0].type->name, "int"));
44
45         defs = cdump_extract(ctx, "struct foo { int x, __attribute__((xxx)) y; };", &problems);
46         ok1(defs);
47         ok1(tal_parent(defs) == ctx);
48         ok1(!problems);
49
50         ok1(strmap_empty(&defs->enums));
51         ok1(strmap_empty(&defs->unions));
52         t = strmap_get(&defs->structs, "foo");
53         ok1(t);
54         ok1(t->kind == CDUMP_STRUCT);
55         ok1(streq(t->name, "foo"));
56         ok1(tal_count(t->u.members) == 2);
57
58         ok1(streq(t->u.members[0].name, "x"));
59         ok1(t->u.members[0].type->kind == CDUMP_UNKNOWN);
60         ok1(streq(t->u.members[0].type->name, "int"));
61
62         ok1(streq(t->u.members[1].name, "y"));
63         ok1(t->u.members[1].type->kind == CDUMP_UNKNOWN);
64         ok1(streq(t->u.members[1].type->name, "int"));
65
66         /* This exits depending on whether all tests passed */
67         return exit_status();
68 }