1 #include <ccan/cdump/cdump.h>
2 /* Include the C files directly. */
3 #include <ccan/cdump/cdump.c>
4 #include <ccan/tap/tap.h>
8 struct cdump_definitions *defs;
9 const struct cdump_type *t;
10 char *ctx = tal(NULL, char), *problems;
12 /* This is how many tests you plan to run */
15 defs = cdump_extract(ctx, "__attribute__((xxx)) enum foo __attribute__((xxx)) { BAR } __attribute__((xxx));", NULL);
17 ok1(tal_parent(defs) == ctx);
19 ok1(strmap_empty(&defs->structs));
20 ok1(strmap_empty(&defs->unions));
21 t = strmap_get(&defs->enums, "foo");
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);
29 defs = cdump_extract(ctx, "__attribute__((xxx)) struct foo __attribute__((xxx)) { int __attribute__((xxx)) x __attribute__((xxx)); } __attribute__((xxx));", &problems);
31 ok1(tal_parent(defs) == ctx);
34 ok1(strmap_empty(&defs->enums));
35 ok1(strmap_empty(&defs->unions));
36 t = strmap_get(&defs->structs, "foo");
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"));
45 defs = cdump_extract(ctx, "struct foo { int x, __attribute__((xxx)) y; };", &problems);
47 ok1(tal_parent(defs) == ctx);
50 ok1(strmap_empty(&defs->enums));
51 ok1(strmap_empty(&defs->unions));
52 t = strmap_get(&defs->structs, "foo");
54 ok1(t->kind == CDUMP_STRUCT);
55 ok1(streq(t->name, "foo"));
56 ok1(tal_count(t->u.members) == 2);
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"));
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"));
66 /* This exits depending on whether all tests passed */