cdump: new module.
[ccan] / ccan / cdump / test / run-forward-decl.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, *t2;
10         char *ctx = tal(NULL, char), *problems;
11
12         /* This is how many tests you plan to run */
13         plan_tests(16);
14
15         defs = cdump_extract(ctx, "struct foo { struct bar *bar; };\n"
16                              "struct bar { int x; };", &problems);
17         ok1(defs);
18         ok1(tal_parent(defs) == ctx);
19         ok1(!problems);
20
21         t = strmap_get(&defs->structs, "foo");
22         ok1(t);
23         t2 = strmap_get(&defs->structs, "bar");
24         ok1(t2);
25
26         ok1(t2->kind == CDUMP_STRUCT);
27         ok1(streq(t2->name, "bar"));
28         ok1(tal_count(t2->u.members) == 1);
29         ok1(t2->u.members[0].type->kind == CDUMP_UNKNOWN);
30         ok1(streq(t2->u.members[0].type->name, "int"));
31
32         ok1(t->kind == CDUMP_STRUCT);
33         ok1(streq(t->name, "foo"));
34         ok1(tal_count(t->u.members) == 1);
35         ok1(streq(t->u.members[0].name, "bar"));
36         ok1(t->u.members[0].type->kind == CDUMP_POINTER);
37         ok1(t->u.members[0].type->u.ptr == t2);
38
39         tal_free(ctx);
40
41         /* This exits depending on whether all tests passed */
42         return exit_status();
43 }