1 #include <ccan/tal/tal.h>
2 #include <ccan/tal/tal.c>
3 #include <ccan/tap/tap.h>
5 static enum tal_notify_type expect;
6 static void *expect_info;
8 static unsigned int notified1, notified2;
10 /* Make sure we always move on resize. */
11 static void *my_realloc(void *old, size_t size)
13 void *new = realloc(old, size);
15 void *p = malloc(size);
23 static void notify1(char *p UNNEEDED, enum tal_notify_type notify, void *info)
26 ok1(notify == expect);
27 if (expect_info == &expect_info)
30 ok1(info == expect_info);
34 static void notify2(char *ctx UNNEEDED,
35 enum tal_notify_type notify UNNEEDED,
41 static bool seen_move, seen_resize;
42 static void resize_notifier(char *p, enum tal_notify_type notify, void *info)
44 if (notify == TAL_NOTIFY_MOVE) {
51 } else if (notify == TAL_NOTIFY_RESIZE) {
55 ok1((size_t)info == 100);
58 fail("Unexpected notifier %i", notify);
63 char *child, *new_ctx;
67 ctx = tal(NULL, char);
68 ok1(tal_add_notifier(ctx, 511, notify1));
72 expect = TAL_NOTIFY_STEAL;
74 ok1(tal_steal(NULL, ctx) == ctx);
77 expect = TAL_NOTIFY_ADD_NOTIFIER;
78 expect_info = notify2;
79 ok1(tal_add_notifier(ctx, TAL_NOTIFY_RENAME|TAL_NOTIFY_ADD_NOTIFIER
80 |TAL_NOTIFY_DEL_NOTIFIER, notify2));
84 expect = TAL_NOTIFY_RENAME;
85 expect_info = (char *)"newname";
86 ok1(tal_set_name(ctx, (char *)expect_info));
90 expect = TAL_NOTIFY_DEL_NOTIFIER;
91 expect_info = notify2;
92 ok1(tal_del_notifier(ctx, notify2));
96 /* Failed delete should not call notifier! */
97 expect = TAL_NOTIFY_DEL_NOTIFIER;
98 expect_info = notify2;
99 ok1(!tal_del_notifier(ctx, notify2));
103 expect = TAL_NOTIFY_ADD_CHILD;
104 expect_info = &expect_info;
105 child = tal(ctx, char);
108 ok1(expect_info == child);
110 expect = TAL_NOTIFY_DEL_CHILD;
116 expect = TAL_NOTIFY_FREE;
122 tal_set_backend(NULL, my_realloc, NULL, NULL);
123 ctx = new_ctx = tal(NULL, char);
124 ok1(tal_add_notifier(new_ctx, 511, resize_notifier));
125 ok1(tal_resize(&new_ctx, 100));
128 tal_del_notifier(new_ctx, resize_notifier);
132 return exit_status();