1 #include <ccan/idtree/idtree.c>
2 #include <ccan/tap/tap.h>
5 #define ALLOC_MAX (2 * IDTREE_SIZE)
7 int main(int argc, char *argv[])
10 const char allocated[ALLOC_MAX] = { 0 };
11 struct idtree *idtree;
14 plan_tests(ALLOC_MAX * 5 + 2);
15 ctx = talloc_named_const(NULL, 1, "test root");
16 idtree = idtree_new(ctx);
17 ok1(talloc_find_parent_byname(idtree, "test root") == ctx);
19 for (i = 0; i < ALLOC_MAX; i++) {
20 int id = idtree_add(idtree, &allocated[i], ALLOC_MAX-1);
22 ok1(idtree_lookup(idtree, i) == &allocated[i]);
24 ok1(idtree_add(idtree, &allocated[i], ALLOC_MAX-1) == -1);
26 /* Remove every second one. */
27 for (i = 0; i < ALLOC_MAX; i += 2)
28 ok1(idtree_remove(idtree, i));
30 for (i = 0; i < ALLOC_MAX; i++) {
32 ok1(!idtree_lookup(idtree, i));
34 ok1(idtree_lookup(idtree, i) == &allocated[i]);
37 /* Now, finally, reallocate. */
38 for (i = 0; i < ALLOC_MAX/2; i++) {
39 ok1(idtree_add(idtree, &allocated[i*2], INT_MAX) == i * 2);
42 for (i = 0; i < ALLOC_MAX; i++) {
43 ok1(idtree_lookup(idtree, i) == &allocated[i]);