1 #define intmap_index_t uint8_t
3 #include <ccan/intmap/intmap.c>
4 #include <ccan/tap/tap.h>
9 typedef UINTMAP(uint8_t *) umap;
10 typedef SINTMAP(int8_t *) smap;
12 static bool check_umap(const umap *map)
14 /* This is a larger type than unsigned, and allows negative */
17 /* Must be in order, must contain value. */
19 for (i = uintmap_first(map);
20 i != UINTMAP_NONE || errno == 0;
21 i = uintmap_after(map, i)) {
24 if (*(uint8_t *)uintmap_get(map, i) != i)
31 static bool check_smap(const smap *map)
33 /* This is a larger type than int, and allows negative */
36 /* Must be in order, must contain value. */
37 prev = -0x80000001ULL;
38 for (i = sintmap_first(map);
39 i != 127 || errno == 0;
40 i = sintmap_after(map, i)) {
43 if (*(int8_t *)sintmap_get(map, i) != i)
55 uint8_t urandoms[NUM];
58 plan_tests(6 * NUM + 2);
62 for (i = 0; i < NUM; i++) {
63 urandoms[i] = random();
64 srandoms[i] = random();
66 for (i = 0; i < NUM; i++) {
67 /* In case we have duplicates. */
68 while (!uintmap_add(&umap, urandoms[i], urandoms+i))
69 urandoms[i] = random();
70 ok1(check_umap(&umap));
72 for (i = 0; i < NUM; i++) {
73 ok1(uintmap_del(&umap, urandoms[i]) == urandoms+i);
74 ok1(check_umap(&umap));
76 ok1(uintmap_empty(&umap));
78 for (i = 0; i < NUM; i++) {
79 /* In case we have duplicates. */
80 while (!sintmap_add(&smap, srandoms[i], srandoms+i))
81 srandoms[i] = random();
82 ok1(check_smap(&smap));
84 for (i = 0; i < NUM; i++) {
85 ok1(sintmap_del(&smap, srandoms[i]) == srandoms+i);
86 ok1(check_smap(&smap));
88 ok1(sintmap_empty(&smap));
90 /* This exits depending on whether all tests passed */