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, 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, enum tal_notify_type notify, void *info)
39 static bool seen_move, seen_resize;
40 static void resize_notifier(char *p, enum tal_notify_type notify, void *info)
42 if (notify == TAL_NOTIFY_MOVE) {
49 } else if (notify == TAL_NOTIFY_RESIZE) {
53 ok1((size_t)info == 100);
56 fail("Unexpected notifier %i", notify);
61 char *child, *new_ctx;
65 ctx = tal(NULL, char);
66 ok1(tal_add_notifier(ctx, 511, notify1));
70 expect = TAL_NOTIFY_STEAL;
72 ok1(tal_steal(NULL, ctx) == ctx);
75 expect = TAL_NOTIFY_ADD_NOTIFIER;
76 expect_info = notify2;
77 ok1(tal_add_notifier(ctx, TAL_NOTIFY_RENAME|TAL_NOTIFY_ADD_NOTIFIER
78 |TAL_NOTIFY_DEL_NOTIFIER, notify2));
82 expect = TAL_NOTIFY_RENAME;
83 expect_info = (char *)"newname";
84 ok1(tal_set_name(ctx, (char *)expect_info));
88 expect = TAL_NOTIFY_DEL_NOTIFIER;
89 expect_info = notify2;
90 ok1(tal_del_notifier(ctx, notify2));
94 /* Failed delete should not call notifier! */
95 expect = TAL_NOTIFY_DEL_NOTIFIER;
96 expect_info = notify2;
97 ok1(!tal_del_notifier(ctx, notify2));
101 expect = TAL_NOTIFY_ADD_CHILD;
102 expect_info = &expect_info;
103 child = tal(ctx, char);
106 ok1(expect_info == child);
108 expect = TAL_NOTIFY_DEL_CHILD;
114 expect = TAL_NOTIFY_FREE;
120 tal_set_backend(NULL, my_realloc, NULL, NULL);
121 ctx = new_ctx = tal(NULL, char);
122 ok1(tal_add_notifier(new_ctx, 511, resize_notifier));
123 ok1(tal_resize(&new_ctx, 100));
126 tal_del_notifier(new_ctx, resize_notifier);
130 return exit_status();