]> git.ozlabs.org Git - ccan/blob - ccan/jbitset/test/run-type.c
compiler: shorten names of attributes, add UNUSED
[ccan] / ccan / jbitset / test / run-type.c
1 #include <ccan/tap/tap.h>
2 #include <ccan/jbitset/jbitset_type.h>
3 #include <ccan/jbitset/jbitset.c>
4
5 struct foo;
6
7 JBIT_DEFINE_TYPE(struct foo, foo);
8
9 static int cmp_ptr(const void *a, const void *b)
10 {
11         return *(char **)a - *(char **)b;
12 }
13
14 #define NUM 100
15
16 int main(int argc, char *argv[])
17 {
18         struct jbitset_foo *set;
19         struct foo *foo[NUM];
20         unsigned int i;
21
22         plan_tests(20);
23         for (i = 0; i < NUM; i++)
24                 foo[i] = malloc(20);
25
26         set = jbit_foo_new();
27         ok1(jbit_foo_error(set) == NULL);
28
29         ok1(jbit_foo_set(set, foo[0]) == true);
30         ok1(jbit_foo_set(set, foo[0]) == false);
31         ok1(jbit_foo_clear(set, foo[0]) == true);
32         ok1(jbit_foo_clear(set, foo[0]) == false);
33         ok1(jbit_foo_count(set) == 0);
34         ok1(jbit_foo_nth(set, 0) == (struct foo *)NULL);
35         ok1(jbit_foo_first(set) == (struct foo *)NULL);
36         ok1(jbit_foo_last(set) == (struct foo *)NULL);
37
38         for (i = 0; i < NUM; i++)
39                 jbit_foo_set(set, foo[i]);
40
41         qsort(foo, NUM, sizeof(foo[0]), cmp_ptr);
42
43         ok1(jbit_foo_count(set) == NUM);
44         ok1(jbit_foo_nth(set, 0) == foo[0]);
45         ok1(jbit_foo_nth(set, NUM-1) == foo[NUM-1]);
46         ok1(jbit_foo_nth(set, NUM) == (struct foo *)NULL);
47         ok1(jbit_foo_first(set) == foo[0]);
48         ok1(jbit_foo_last(set) == foo[NUM-1]);
49         ok1(jbit_foo_next(set, foo[0]) == foo[1]);
50         ok1(jbit_foo_next(set, foo[NUM-1]) == (struct foo *)NULL);
51         ok1(jbit_foo_prev(set, foo[1]) == foo[0]);
52         ok1(jbit_foo_prev(set, foo[0]) == (struct foo *)NULL);
53         ok1(jbit_foo_error(set) == NULL);
54         jbit_foo_free(set);
55
56         return exit_status();
57 }