1 #include <ccan/tally/tally.c>
2 #include <ccan/tap/tap.h>
7 ssize_t total, overflow;
10 max = (ssize_t)~(1ULL << (sizeof(max)*CHAR_BIT - 1));
11 min = (ssize_t)(1ULL << (sizeof(max)*CHAR_BIT - 1));
17 tally_add(tally, min);
18 ok1(tally_total(tally, NULL) == min);
19 ok1(tally_total(tally, &overflow) == min);
23 tally_add(tally, min);
24 total = tally_total(tally, &overflow);
26 ok1((size_t)total == 0);
27 ok1(tally_total(tally, NULL) == min);
32 tally_add(tally, max);
33 ok1(tally_total(tally, NULL) == max);
34 ok1(tally_total(tally, &overflow) == max);
37 /* Overflow into sign bit... */
38 tally_add(tally, max);
39 total = tally_total(tally, &overflow);
41 ok1((size_t)total == (size_t)-2);
42 ok1(tally_total(tally, NULL) == max);
44 /* Overflow into upper size_t. */
45 tally_add(tally, max);
46 total = tally_total(tally, &overflow);
48 if (sizeof(size_t) == 4)
49 ok1((size_t)total == 0x7FFFFFFD);
50 else if (sizeof(size_t) == 8)
51 ok1((size_t)total == 0x7FFFFFFFFFFFFFFDULL);
52 ok1(tally_total(tally, NULL) == max);