1 #include <ccan/tal/link/link.c>
2 #include <ccan/tap/tap.h>
6 static unsigned int destroy_count = 0;
7 static void destroy_obj(void *obj)
12 int main(int argc, char *argv[])
14 char *linkable, *p1, *p2, *p3;
19 linkable = tal(NULL, char);
20 ok1(tal_linkable(linkable) == linkable);
21 ok1(tal_add_destructor(linkable, destroy_obj));
22 /* First, free it immediately. */
24 ok1(destroy_count == 1);
26 /* Now create and remove a single link. */
27 linkable = tal_linkable(tal(NULL, char));
28 ok1(tal_add_destructor(linkable, destroy_obj));
29 ok1(p1 = tal_link(NULL, linkable));
31 tal_delink(NULL, linkable);
32 ok1(destroy_count == 2);
35 linkable = tal_linkable(tal(NULL, char));
36 ok1(tal_add_destructor(linkable, destroy_obj));
37 ok1(p1 = tal_link(NULL, linkable));
39 ok1(p2 = tal_link(NULL, linkable));
41 tal_delink(NULL, linkable);
42 tal_delink(NULL, linkable);
43 ok1(destroy_count == 3);
46 linkable = tal_linkable(tal(NULL, char));
47 ok1(tal_add_destructor(linkable, destroy_obj));
48 ok1(p1 = tal_link(NULL, linkable));
50 ok1(p2 = tal_link(NULL, linkable));
52 ok1(p3 = tal_link(NULL, linkable));
54 tal_delink(NULL, linkable);
55 tal_delink(NULL, linkable);
56 tal_delink(NULL, linkable);
57 ok1(destroy_count == 4);
59 /* Now, indirectly. */
60 voidpp = tal(NULL, void *);
61 linkable = tal_linkable(tal(NULL, char));
62 ok1(tal_add_destructor(linkable, destroy_obj));
63 /* Suppress gratuitous warning with tests_compile_without_features */
64 #if HAVE_STATEMENT_EXPR
65 tal_link(voidpp, linkable);
67 (void)tal_link(voidpp, linkable);
70 ok1(destroy_count == 5);