1 #include <ccan/cdump/cdump.h>
2 #include <ccan/cdump/cdump.c>
3 #include <ccan/cdump/cdump_internal.h>
4 #include <ccan/cdump/test/test_header.h>
5 #include <ccan/str/str.h>
6 #include <ccan/tap/tap.h>
10 /* This is as generated by cdump_parse: see run-parse.c */
11 #include <ccan/cdump/test/example_generated-decls.h>
12 #include <ccan/cdump/test/example_generated-defs.h>
14 static struct test2 *new_test2(const void *ctx, struct test2 *next)
18 t = talloc(ctx, struct test2);
20 t->foo = talloc_strdup(t, "foo");
21 memset(t->fstring, 'a', 20);
23 t->dfoo = talloc_array(t, char, t->dlen);
24 memset(t->dfoo, 7, t->dlen);
30 static bool test2eq(const struct test2 *a, const struct test2 *b)
34 if (!a->foo != !b->foo)
36 if (a->foo && !streq(a->foo, b->foo))
38 if (memcmp(a->fstring, b->fstring, 20) != 0)
40 if (a->dlen != b->dlen)
42 if (!a->dfoo != !b->dfoo)
44 if (memcmp(a->dfoo, b->dfoo, a->dlen) != 0)
46 if (a->fvalue != b->fvalue)
48 if (!a->next != !b->next)
51 return test2eq(a->next, b->next);
59 char *toplevel = talloc_strdup(NULL, "toplevel");
62 a = new_test2(toplevel, NULL);
63 astr = cdump_bundle(toplevel, cdump_struct_test2, a);
65 ok1(talloc_find_parent_byname(astr, "toplevel") == toplevel);
67 b = talloc_zero(toplevel, struct test2);
68 ok1(cdump_unbundle(toplevel, cdump_struct_test2, b, astr));
75 astr = cdump_bundle(toplevel, cdump_struct_test2, a);
77 ok1(talloc_find_parent_byname(astr, "toplevel") == toplevel);
79 b = talloc_zero(toplevel, struct test2);
80 ok1(cdump_unbundle(toplevel, cdump_struct_test2, b, astr));
81 ok1(talloc_find_parent_byname(b, "toplevel") == toplevel);
84 talloc_free(toplevel);