]> git.ozlabs.org Git - ccan/blob - ccan/intmap/test/run-after-exhaustive.c
io/fdpass: don't leak fd if conn closes before we write it.
[ccan] / ccan / intmap / test / run-after-exhaustive.c
1 #include <ccan/bitops/bitops.h>
2 #include <ccan/intmap/intmap.c>
3 #include <ccan/tap/tap.h>
4 #include <stdio.h>
5
6 #define ELEMENTS 8
7
8 int main(void)
9 {
10         UINTMAP(void *) umap;
11
12         plan_tests((1 << ELEMENTS) * ELEMENTS);
13
14         /* Run through every combination of elements */
15         for (int i = 0; i < (1 << ELEMENTS); i++) {
16                 /* Set up map */
17                 uintmap_init(&umap);
18                 for (int j = 0; j < ELEMENTS; j++) {
19                         if ((1 << j) & i)
20                                 uintmap_add(&umap, j, &umap);
21                 }
22
23                 /* Try each uintmap_after value */
24                 for (int j = 0; j < ELEMENTS; j++) {
25                         intmap_index_t idx = j, next;
26
27                         if ((i >> (j + 1)) == 0)
28                                 next = 0;
29                         else
30                                 next = j + 1 + bitops_ls32(i >> (j + 1));
31
32                         if (!uintmap_after(&umap, &idx))
33                                 idx = 0;
34                         ok1(idx == next);
35                 }
36                 uintmap_clear(&umap);
37         }
38
39         /* This exits depending on whether all tests passed */
40         return exit_status();
41 }