intmap: new module.
[ccan] / ccan / intmap / test / run-signed-int.c
1 #include <ccan/intmap/intmap.h>
2 #include <ccan/intmap/intmap.c>
3 #include <ccan/tap/tap.h>
4
5 int main(void)
6 {
7         SINTMAP(const char *) map;
8         const char *first = "first", *second = "second";
9
10         /* This is how many tests you plan to run */
11         plan_tests(35);
12
13         sintmap_init(&map);
14         /* Test boundaries. */
15         ok1(!sintmap_get(&map, 0x7FFFFFFFFFFFFFFFLL));
16         ok1(!sintmap_get(&map, -0x8000000000000000LL));
17         ok1(sintmap_first(&map) == 0x7FFFFFFFFFFFFFFFLL);
18         ok1(errno == ENOENT);
19         ok1(sintmap_after(&map, 0x7FFFFFFFFFFFFFFFLL) == 0x7FFFFFFFFFFFFFFFLL);
20         ok1(errno == ENOENT);
21         ok1(sintmap_after(&map, -0x8000000000000000LL) == 0x7FFFFFFFFFFFFFFFLL);
22         ok1(errno == ENOENT);
23         ok1(sintmap_after(&map, 0x7FFFFFFFFFFFFFFELL) == 0x7FFFFFFFFFFFFFFFLL);
24         ok1(errno == ENOENT);
25         ok1(sintmap_add(&map, 0x7FFFFFFFFFFFFFFFLL, first));
26         ok1(sintmap_get(&map, 0x7FFFFFFFFFFFFFFFLL) == first);
27         ok1(sintmap_first(&map) == 0x7FFFFFFFFFFFFFFFLL);
28         ok1(errno == 0);
29         ok1(sintmap_add(&map, -0x8000000000000000LL, second));
30         ok1(sintmap_get(&map, 0x7FFFFFFFFFFFFFFFLL) == first);
31         ok1(sintmap_get(&map, -0x8000000000000000LL) == second);
32         ok1(sintmap_first(&map) == -0x8000000000000000LL);
33         ok1(sintmap_after(&map, -0x8000000000000000LL) == 0x7FFFFFFFFFFFFFFFLL);
34         ok1(errno == 0);
35         ok1(sintmap_after(&map, 0x7FFFFFFFFFFFFFFELL) == 0x7FFFFFFFFFFFFFFFLL);
36         ok1(errno == 0);
37         ok1(sintmap_after(&map, -0x7FFFFFFFFFFFFFFFLL) == 0x7FFFFFFFFFFFFFFFLL);
38         ok1(errno == 0);
39         ok1(sintmap_after(&map, 0x7FFFFFFFFFFFFFFFLL) == 0x7FFFFFFFFFFFFFFFLL);
40         ok1(errno == ENOENT);
41         ok1(sintmap_del(&map, 0x7FFFFFFFFFFFFFFFLL) == first);
42         ok1(sintmap_after(&map, -0x8000000000000000LL) == 0x7FFFFFFFFFFFFFFFLL);
43         ok1(errno == ENOENT);
44         ok1(sintmap_add(&map, 0x7FFFFFFFFFFFFFFFLL, first));
45         ok1(sintmap_del(&map, 0x8000000000000000LL) == second);
46         ok1(sintmap_after(&map, -0x8000000000000000LL) == 0x7FFFFFFFFFFFFFFFLL);
47         ok1(errno == 0);
48         ok1(sintmap_del(&map, 0x7FFFFFFFFFFFFFFFLL) == first);
49         ok1(sintmap_empty(&map));
50         
51         /* This exits depending on whether all tests passed */
52         return exit_status();
53 }