1 #include <ccan/talloc/talloc.c>
2 #include <ccan/tap/tap.h>
5 /* Much testing already done in run.c */
7 static int ext_alloc_count, ext_free_count, ext_realloc_count, lock_count, unlock_count;
8 static void *expected_parent;
10 static void *ext_realloc(const void *parent, void *ptr, size_t size)
12 ok1(parent == expected_parent);
19 return realloc(ptr, size);
22 static void ext_lock(const void *ctx)
27 static void ext_unlock(void)
37 expected_parent = NULL;
38 head = talloc_add_external(NULL, ext_realloc, ext_lock, ext_unlock);
40 ok1(ext_alloc_count == 1);
42 expected_parent = head;
43 p = talloc_array(head, char, 1);
44 ok1(ext_alloc_count == 2);
47 /* Child is also externally allocated */
50 ok1(ext_alloc_count == 3);
52 expected_parent = head;
53 p = talloc_realloc(NULL, p, char, 1000);
54 ok1(ext_realloc_count == 1);
59 ok1(ext_free_count == 1);
61 expected_parent = head;
63 ok1(ext_free_count == 2);
65 expected_parent = NULL;
67 ok1(ext_free_count == 3);
69 ok1(lock_count == unlock_count);