]> git.ozlabs.org Git - ccan/blob - ccan/intmap/test/run-signed-int.c
crypto/shachain/tools: update to new rbuf API.
[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(38);
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(sintmap_last(&map, &s) == NULL);
20         ok1(errno == ENOENT);
21         s = 0x7FFFFFFFFFFFFFFFLL;
22         ok1(sintmap_after(&map, &s) == NULL);
23         ok1(errno == ENOENT);
24         s = -0x8000000000000000LL;
25         ok1(sintmap_after(&map, &s) == NULL);
26         ok1(errno == ENOENT);
27         s = 0x7FFFFFFFFFFFFFFELL;
28         ok1(sintmap_after(&map, &s) == NULL);
29         ok1(errno == ENOENT);
30         ok1(sintmap_add(&map, 0x7FFFFFFFFFFFFFFFLL, first));
31         ok1(sintmap_get(&map, 0x7FFFFFFFFFFFFFFFLL) == first);
32         ok1(sintmap_first(&map, &s) == first && s == 0x7FFFFFFFFFFFFFFFLL);
33         ok1(sintmap_last(&map, &s) == first && s == 0x7FFFFFFFFFFFFFFFLL);
34         ok1(errno == 0);
35         ok1(sintmap_add(&map, -0x8000000000000000LL, second));
36         ok1(sintmap_get(&map, 0x7FFFFFFFFFFFFFFFLL) == first);
37         ok1(sintmap_get(&map, -0x8000000000000000LL) == second);
38         ok1(sintmap_first(&map, &s) == second && s == -0x8000000000000000LL);
39         ok1(sintmap_after(&map, &s) == first && s == 0x7FFFFFFFFFFFFFFFLL);
40         ok1(sintmap_last(&map, &s) == first && s == 0x7FFFFFFFFFFFFFFFLL);
41         ok1(errno == 0);
42         s = 0x7FFFFFFFFFFFFFFELL;
43         ok1(sintmap_after(&map, &s) == first && s == 0x7FFFFFFFFFFFFFFFLL);
44         ok1(errno == 0);
45         s = -0x7FFFFFFFFFFFFFFFLL;
46         ok1(sintmap_after(&map, &s) == first && s == 0x7FFFFFFFFFFFFFFFLL);
47         ok1(errno == 0);
48         ok1(sintmap_after(&map, &s) == NULL);
49         ok1(errno == ENOENT);
50         ok1(sintmap_del(&map, 0x7FFFFFFFFFFFFFFFLL) == first);
51         s = -0x8000000000000000LL;
52         ok1(sintmap_after(&map, &s) == NULL);
53         ok1(errno == ENOENT);
54         ok1(sintmap_add(&map, 0x7FFFFFFFFFFFFFFFLL, first));
55         ok1(sintmap_del(&map, 0x8000000000000000LL) == second);
56         s = -0x8000000000000000LL;
57         ok1(sintmap_after(&map, &s) == first && s == 0x7FFFFFFFFFFFFFFFLL);
58         ok1(errno == 0);
59         ok1(sintmap_del(&map, 0x7FFFFFFFFFFFFFFFLL) == first);
60         ok1(sintmap_empty(&map));
61         
62         /* This exits depending on whether all tests passed */
63         return exit_status();
64 }