1 #include <ccan/tap/tap.h>
2 #include <ccan/jset/jset.c>
7 JSET_MEMBERS(struct foo *);
10 static int cmp_ptr(const void *a, const void *b)
12 return *(char **)a - *(char **)b;
17 int main(int argc, char *argv[])
24 for (i = 0; i < NUM; i++)
27 set = jset_new(struct jset_foo);
28 ok1(jset_error(set) == NULL);
30 ok1(jset_set(set, foo[0]) == true);
31 ok1(jset_set(set, foo[0]) == false);
32 ok1(jset_clear(set, foo[0]) == true);
33 ok1(jset_clear(set, foo[0]) == false);
34 ok1(jset_count(set) == 0);
35 ok1(jset_nth(set, 0, NULL) == (struct foo *)NULL);
36 ok1(jset_first(set) == (struct foo *)NULL);
37 ok1(jset_last(set) == (struct foo *)NULL);
39 for (i = 0; i < NUM; i++)
40 jset_set(set, foo[i]);
42 qsort(foo, NUM, sizeof(foo[0]), cmp_ptr);
44 ok1(jset_count(set) == NUM);
45 ok1(jset_nth(set, 0, NULL) == foo[0]);
46 ok1(jset_nth(set, NUM-1, NULL) == foo[NUM-1]);
47 ok1(jset_nth(set, NUM, NULL) == (struct foo *)NULL);
48 ok1(jset_first(set) == foo[0]);
49 ok1(jset_last(set) == foo[NUM-1]);
50 ok1(jset_next(set, foo[0]) == foo[1]);
51 ok1(jset_next(set, foo[NUM-1]) == (struct foo *)NULL);
52 ok1(jset_prev(set, foo[1]) == foo[0]);
53 ok1(jset_prev(set, foo[0]) == (struct foo *)NULL);
54 ok1(jset_error(set) == NULL);
57 for (i = 0; i < NUM; i++)