X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fcdump%2Ftest%2Frun-forward-decl.c;fp=ccan%2Fcdump%2Ftest%2Frun-forward-decl.c;h=96065e45e2f219d3d33197b491179ebebecbf638;hp=0000000000000000000000000000000000000000;hb=158691ae36fe1da78ec54dbcc0006f603398dae2;hpb=17aa322abd7b785330ab49e348144be940b3d1d8 diff --git a/ccan/cdump/test/run-forward-decl.c b/ccan/cdump/test/run-forward-decl.c new file mode 100644 index 00000000..96065e45 --- /dev/null +++ b/ccan/cdump/test/run-forward-decl.c @@ -0,0 +1,43 @@ +#include +/* Include the C files directly. */ +#include +#include + +int main(void) +{ + struct cdump_definitions *defs; + const struct cdump_type *t, *t2; + char *ctx = tal(NULL, char), *problems; + + /* This is how many tests you plan to run */ + plan_tests(16); + + defs = cdump_extract(ctx, "struct foo { struct bar *bar; };\n" + "struct bar { int x; };", &problems); + ok1(defs); + ok1(tal_parent(defs) == ctx); + ok1(!problems); + + t = strmap_get(&defs->structs, "foo"); + ok1(t); + t2 = strmap_get(&defs->structs, "bar"); + ok1(t2); + + ok1(t2->kind == CDUMP_STRUCT); + ok1(streq(t2->name, "bar")); + ok1(tal_count(t2->u.members) == 1); + ok1(t2->u.members[0].type->kind == CDUMP_UNKNOWN); + ok1(streq(t2->u.members[0].type->name, "int")); + + ok1(t->kind == CDUMP_STRUCT); + ok1(streq(t->name, "foo")); + ok1(tal_count(t->u.members) == 1); + ok1(streq(t->u.members[0].name, "bar")); + ok1(t->u.members[0].type->kind == CDUMP_POINTER); + ok1(t->u.members[0].type->u.ptr == t2); + + tal_free(ctx); + + /* This exits depending on whether all tests passed */ + return exit_status(); +}