]> git.ozlabs.org Git - ccan/blob - ccan/intmap/test/run-signed-int.c
7c86a940c8538ef9a28e66099ed4e1fe57c473cb
[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         int64_t s;
10
11         /* This is how many tests you plan to run */
12         plan_tests(35);
13
14         sintmap_init(&map);
15         /* Test boundaries. */
16         ok1(!sintmap_get(&map, 0x7FFFFFFFFFFFFFFFLL));
17         ok1(!sintmap_get(&map, -0x8000000000000000LL));
18         ok1(sintmap_first(&map, &s) == NULL);
19         ok1(errno == ENOENT);
20         s = 0x7FFFFFFFFFFFFFFFLL;
21         ok1(sintmap_after(&map, &s) == NULL);
22         ok1(errno == ENOENT);
23         s = -0x8000000000000000LL;
24         ok1(sintmap_after(&map, &s) == NULL);
25         ok1(errno == ENOENT);
26         s = 0x7FFFFFFFFFFFFFFELL;
27         ok1(sintmap_after(&map, &s) == NULL);
28         ok1(errno == ENOENT);
29         ok1(sintmap_add(&map, 0x7FFFFFFFFFFFFFFFLL, first));
30         ok1(sintmap_get(&map, 0x7FFFFFFFFFFFFFFFLL) == first);
31         ok1(sintmap_first(&map, &s) == first && s == 0x7FFFFFFFFFFFFFFFLL);
32         ok1(errno == 0);
33         ok1(sintmap_add(&map, -0x8000000000000000LL, second));
34         ok1(sintmap_get(&map, 0x7FFFFFFFFFFFFFFFLL) == first);
35         ok1(sintmap_get(&map, -0x8000000000000000LL) == second);
36         ok1(sintmap_first(&map, &s) == second && s == -0x8000000000000000LL);
37         ok1(sintmap_after(&map, &s) == first && s == 0x7FFFFFFFFFFFFFFFLL);
38         ok1(errno == 0);
39         s = 0x7FFFFFFFFFFFFFFELL;
40         ok1(sintmap_after(&map, &s) == first && s == 0x7FFFFFFFFFFFFFFFLL);
41         ok1(errno == 0);
42         s = -0x7FFFFFFFFFFFFFFFLL;
43         ok1(sintmap_after(&map, &s) == first && s == 0x7FFFFFFFFFFFFFFFLL);
44         ok1(errno == 0);
45         ok1(sintmap_after(&map, &s) == NULL);
46         ok1(errno == ENOENT);
47         ok1(sintmap_del(&map, 0x7FFFFFFFFFFFFFFFLL) == first);
48         s = -0x8000000000000000LL;
49         ok1(sintmap_after(&map, &s) == NULL);
50         ok1(errno == ENOENT);
51         ok1(sintmap_add(&map, 0x7FFFFFFFFFFFFFFFLL, first));
52         ok1(sintmap_del(&map, 0x8000000000000000LL) == second);
53         s = -0x8000000000000000LL;
54         ok1(sintmap_after(&map, &s) == first && s == 0x7FFFFFFFFFFFFFFFLL);
55         ok1(errno == 0);
56         ok1(sintmap_del(&map, 0x7FFFFFFFFFFFFFFFLL) == first);
57         ok1(sintmap_empty(&map));
58         
59         /* This exits depending on whether all tests passed */
60         return exit_status();
61 }