1 #include <ccan/objset/objset.h>
2 #include <ccan/tap/tap.h>
5 OBJSET_MEMBERS(char *);
14 struct objset_charp osetc;
15 struct objset_int oseti;
20 /* This is how many tests you plan to run */
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);
32 ok1(!objset_del(&oseti, &i1));
33 ok1(!objset_del(&oseti, &i2));
34 ok1(!objset_del(&osetc, &c1));
35 ok1(!objset_del(&osetc, &c2));
37 objset_add(&oseti, &i1);
38 ok1(!objset_empty(&oseti));
39 ok1(objset_get(&oseti, &i1) == &i1);
40 ok1(objset_get(&oseti, &i2) == NULL);
42 objset_add(&osetc, &c1);
43 ok1(!objset_empty(&osetc));
44 ok1(objset_get(&osetc, &c1) == &c1);
45 ok1(objset_get(&osetc, &c2) == NULL);
47 objset_add(&oseti, &i2);
48 ok1(!objset_empty(&oseti));
49 ok1(objset_get(&oseti, &i1) == &i1);
50 ok1(objset_get(&oseti, &i2) == &i2);
52 objset_add(&osetc, &c2);
53 ok1(!objset_empty(&osetc));
54 ok1(objset_get(&osetc, &c1) == &c1);
55 ok1(objset_get(&osetc, &c2) == &c2);
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);
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);
69 ok1(objset_del(&oseti, &i1));
70 ok1(!objset_del(&oseti, &i1));
71 ok1(objset_del(&osetc, &c1));
72 ok1(!objset_del(&osetc, &c1));
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);
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));
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));
95 /* This exits depending on whether all tests passed */