1 #include <ccan/idtree/idtree.c>
2 #include <ccan/tap/tap.h>
5 #define ALLOC_MAX (2 * IDTREE_SIZE)
7 static bool check_tal_parent(const tal_t *parent, const tal_t *ctx)
12 ctx = tal_parent(ctx);
17 int main(int argc, char *argv[])
20 const char allocated[ALLOC_MAX] = { 0 };
21 struct idtree *idtree;
24 plan_tests(ALLOC_MAX * 5 + 2);
25 ctx = tal(NULL, char);
26 idtree = idtree_new(ctx);
27 ok1(check_tal_parent(ctx, idtree));
29 for (i = 0; i < ALLOC_MAX; i++) {
30 int id = idtree_add(idtree, &allocated[i], ALLOC_MAX-1);
32 ok1(idtree_lookup(idtree, i) == &allocated[i]);
34 ok1(idtree_add(idtree, &allocated[i], ALLOC_MAX-1) == -1);
36 /* Remove every second one. */
37 for (i = 0; i < ALLOC_MAX; i += 2)
38 ok1(idtree_remove(idtree, i));
40 for (i = 0; i < ALLOC_MAX; i++) {
42 ok1(!idtree_lookup(idtree, i));
44 ok1(idtree_lookup(idtree, i) == &allocated[i]);
47 /* Now, finally, reallocate. */
48 for (i = 0; i < ALLOC_MAX/2; i++) {
49 ok1(idtree_add(idtree, &allocated[i*2], INT_MAX) == i * 2);
52 for (i = 0; i < ALLOC_MAX; i++) {
53 ok1(idtree_lookup(idtree, i) == &allocated[i]);