1 #include <ccan/tal/talloc/talloc.h>
2 #include <ccan/tal/talloc/talloc.c>
3 #include <ccan/tap/tap.h>
5 static char *parent, *child;
6 static int destroy_count;
8 /* Parent gets destroyed first. */
9 static void destroy_parent(char *p)
12 ok1(destroy_count == 0);
13 /* Can still access child. */
18 static void destroy_child(char *p)
21 ok1(destroy_count == 1);
22 /* Can still access parent (though destructor has been called). */
27 static void destroy_inc(char *p)
39 parent = tal(NULL, char);
40 child = tal(parent, char);
41 ok1(tal_add_destructor(parent, destroy_parent));
42 ok1(tal_add_destructor(child, destroy_child));
44 ok1(destroy_count == 2);
47 parent = tal(NULL, char);
48 child = tal(parent, char);
49 ok1(tal_add_destructor(parent, destroy_parent));
50 ok1(tal_add_destructor(child, destroy_child));
51 ok1(tal_del_destructor(child, destroy_child));
53 ok1(destroy_count == 1);
56 parent = tal(NULL, char);
57 child = tal(parent, char);
58 child2 = tal(parent, char);
59 ok1(tal_add_destructor(parent, destroy_inc));
60 ok1(tal_add_destructor(parent, destroy_inc));
61 ok1(tal_add_destructor(child, destroy_inc));
62 ok1(tal_add_destructor(child2, destroy_inc));
64 ok1(destroy_count == 4);