]> git.ozlabs.org Git - ccan/blob - ccan/objset/test/run.c
base64: fix for unsigned chars (e.g. ARM).
[ccan] / ccan / objset / test / run.c
1 #include <ccan/objset/objset.h>
2 #include <ccan/tap/tap.h>
3
4 struct objset_charp {
5         OBJSET_MEMBERS(char *);
6 };
7
8 struct objset_int {
9         OBJSET_MEMBERS(int *);
10 };
11
12 int main(void)
13 {
14         struct objset_charp osetc;
15         struct objset_int oseti;
16         struct objset_iter i;
17         int i1 = 1, i2 = 2;
18         char c1 = 1, c2 = 2;
19
20         /* This is how many tests you plan to run */
21         plan_tests(46);
22
23         objset_init(&osetc);
24         objset_init(&oseti);
25         ok1(objset_empty(&osetc));
26         ok1(objset_empty(&oseti));
27         ok1(objset_get(&oseti, &i1) == NULL);
28         ok1(objset_get(&oseti, &i2) == NULL);
29         ok1(objset_get(&osetc, &c1) == NULL);
30         ok1(objset_get(&osetc, &c2) == NULL);
31
32         ok1(!objset_del(&oseti, &i1));
33         ok1(!objset_del(&oseti, &i2));
34         ok1(!objset_del(&osetc, &c1));
35         ok1(!objset_del(&osetc, &c2));
36
37         objset_add(&oseti, &i1);
38         ok1(!objset_empty(&oseti));
39         ok1(objset_get(&oseti, &i1) == &i1);
40         ok1(objset_get(&oseti, &i2) == NULL);
41
42         objset_add(&osetc, &c1);
43         ok1(!objset_empty(&osetc));
44         ok1(objset_get(&osetc, &c1) == &c1);
45         ok1(objset_get(&osetc, &c2) == NULL);
46
47         objset_add(&oseti, &i2);
48         ok1(!objset_empty(&oseti));
49         ok1(objset_get(&oseti, &i1) == &i1);
50         ok1(objset_get(&oseti, &i2) == &i2);
51
52         objset_add(&osetc, &c2);
53         ok1(!objset_empty(&osetc));
54         ok1(objset_get(&osetc, &c1) == &c1);
55         ok1(objset_get(&osetc, &c2) == &c2);
56
57         ok1((objset_first(&oseti, &i) == &i1
58              && objset_next(&oseti, &i) == &i2)
59             || (objset_first(&oseti, &i) == &i2
60                 && objset_next(&oseti, &i) == &i1));
61         ok1(objset_next(&oseti, &i) == NULL);
62
63         ok1((objset_first(&osetc, &i) == &c1
64              && objset_next(&osetc, &i) == &c2)
65             || (objset_first(&osetc, &i) == &c2
66                 && objset_next(&osetc, &i) == &c1));
67         ok1(objset_next(&osetc, &i) == NULL);
68
69         ok1(objset_del(&oseti, &i1));
70         ok1(!objset_del(&oseti, &i1));
71         ok1(objset_del(&osetc, &c1));
72         ok1(!objset_del(&osetc, &c1));
73
74         ok1(objset_first(&oseti, &i) == &i2);
75         ok1(objset_next(&oseti, &i) == NULL);
76         ok1(objset_first(&osetc, &i) == &c2);
77         ok1(objset_next(&osetc, &i) == NULL);
78
79         objset_clear(&oseti);
80         ok1(objset_first(&oseti, &i) == NULL);
81         ok1(objset_empty(&oseti));
82         ok1(objset_get(&oseti, &i1) == NULL);
83         ok1(objset_get(&oseti, &i2) == NULL);
84         ok1(!objset_del(&oseti, &i1));
85         ok1(!objset_del(&oseti, &i2));
86
87         objset_clear(&osetc);
88         ok1(objset_first(&osetc, &i) == NULL);
89         ok1(objset_empty(&osetc));
90         ok1(objset_get(&osetc, &c1) == NULL);
91         ok1(objset_get(&osetc, &c2) == NULL);
92         ok1(!objset_del(&osetc, &c1));
93         ok1(!objset_del(&osetc, &c2));
94
95         /* This exits depending on whether all tests passed */
96         return exit_status();
97 }