1 #include <ccan/tal/tal.h>
2 #include <ccan/tal/tal.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 UNNEEDED)
32 static void remove_own_destructor(char *p)
35 ok1(!tal_del_destructor(p, remove_own_destructor));
45 parent = tal(NULL, char);
46 child = tal(parent, char);
47 ok1(tal_add_destructor(parent, destroy_parent));
48 ok1(tal_add_destructor(child, destroy_child));
50 ok1(destroy_count == 2);
53 parent = tal(NULL, char);
54 child = tal(parent, char);
55 ok1(tal_add_destructor(parent, destroy_parent));
56 ok1(tal_add_destructor(child, destroy_child));
57 ok1(tal_del_destructor(child, destroy_child));
59 ok1(destroy_count == 1);
62 parent = tal(NULL, char);
63 child = tal(parent, char);
64 child2 = tal(parent, char);
65 ok1(tal_add_destructor(parent, destroy_inc));
66 ok1(tal_add_destructor(parent, destroy_inc));
67 ok1(tal_add_destructor(child, destroy_inc));
68 ok1(tal_add_destructor(child2, destroy_inc));
70 ok1(destroy_count == 4);
73 parent = tal(NULL, char);
74 ok1(tal_add_destructor(parent, remove_own_destructor));
76 ok1(destroy_count == 1);