X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fcdump%2Ftest%2Frun-attributes.c;fp=ccan%2Fcdump%2Ftest%2Frun-attributes.c;h=1034bde99f4466d5ce19e411687b72f9755005c6;hb=ed95d8600afe1564ffd1783ae9ea0ef6324904dc;hp=0000000000000000000000000000000000000000;hpb=3d6fe8391ab0b6e6b9da0a715a4a8308303fc72e;p=ccan diff --git a/ccan/cdump/test/run-attributes.c b/ccan/cdump/test/run-attributes.c new file mode 100644 index 00000000..1034bde9 --- /dev/null +++ b/ccan/cdump/test/run-attributes.c @@ -0,0 +1,68 @@ +#include +/* Include the C files directly. */ +#include +#include + +int main(void) +{ + struct cdump_definitions *defs; + const struct cdump_type *t; + char *ctx = tal(NULL, char), *problems; + + /* This is how many tests you plan to run */ + plan_tests(37); + + defs = cdump_extract(ctx, "__attribute__((xxx)) enum foo __attribute__((xxx)) { BAR } __attribute__((xxx));", NULL); + ok1(defs); + ok1(tal_parent(defs) == ctx); + + ok1(strmap_empty(&defs->structs)); + ok1(strmap_empty(&defs->unions)); + t = strmap_get(&defs->enums, "foo"); + ok1(t); + ok1(t->kind == CDUMP_ENUM); + ok1(streq(t->name, "foo")); + ok1(tal_count(t->u.enum_vals) == 1); + ok1(streq(t->u.enum_vals[0].name, "BAR")); + ok1(!t->u.enum_vals[0].value); + + defs = cdump_extract(ctx, "__attribute__((xxx)) struct foo __attribute__((xxx)) { int __attribute__((xxx)) x __attribute__((xxx)); } __attribute__((xxx));", &problems); + ok1(defs); + ok1(tal_parent(defs) == ctx); + ok1(!problems); + + ok1(strmap_empty(&defs->enums)); + ok1(strmap_empty(&defs->unions)); + t = strmap_get(&defs->structs, "foo"); + ok1(t); + ok1(t->kind == CDUMP_STRUCT); + ok1(streq(t->name, "foo")); + ok1(tal_count(t->u.members) == 1); + ok1(streq(t->u.members[0].name, "x")); + ok1(t->u.members[0].type->kind == CDUMP_UNKNOWN); + ok1(streq(t->u.members[0].type->name, "int")); + + defs = cdump_extract(ctx, "struct foo { int x, __attribute__((xxx)) y; };", &problems); + ok1(defs); + ok1(tal_parent(defs) == ctx); + ok1(!problems); + + ok1(strmap_empty(&defs->enums)); + ok1(strmap_empty(&defs->unions)); + t = strmap_get(&defs->structs, "foo"); + ok1(t); + ok1(t->kind == CDUMP_STRUCT); + ok1(streq(t->name, "foo")); + ok1(tal_count(t->u.members) == 2); + + ok1(streq(t->u.members[0].name, "x")); + ok1(t->u.members[0].type->kind == CDUMP_UNKNOWN); + ok1(streq(t->u.members[0].type->name, "int")); + + ok1(streq(t->u.members[1].name, "y")); + ok1(t->u.members[1].type->kind == CDUMP_UNKNOWN); + ok1(streq(t->u.members[1].type->name, "int")); + + /* This exits depending on whether all tests passed */ + return exit_status(); +}