12 /*********************************************************************/
16 void cbi2p(void*closure, uint16_t id, void *ptr)
20 ck_assert((ni >> id) & 1);
21 ck_assert((uintptr_t)ptr == (uintptr_t)(ni + id));
25 void test_i2ptr(struct u16id2ptr **pi2p)
27 int i, ni, n, x, y[2];
35 for (j = 0 ; j < S ; j++) {
37 ck_assert_int_eq(1, u16id2ptr_has(*pi2p, j));
38 ck_assert_int_eq(0, u16id2ptr_get(*pi2p, j, &p));
39 ck_assert((uintptr_t)p == (uintptr_t)(i + j));
40 ck_assert_int_eq(-1, u16id2ptr_add(pi2p, j, p));
41 ck_assert_int_eq(0, u16id2ptr_put(*pi2p, j, p));
43 ck_assert_int_eq(0, u16id2ptr_has(*pi2p, j));
44 ck_assert_int_eq(-1, u16id2ptr_get(*pi2p, j, &p));
45 ck_assert_int_eq(-1, u16id2ptr_put(*pi2p, j, p));
48 p = (void*)(uintptr_t)(ni + j);
49 ck_assert_int_eq(0, u16id2ptr_set(pi2p, j, p));
51 } else if ((i >> j) & 1) {
52 ck_assert_int_eq(0, u16id2ptr_drop(pi2p, j, &p));
53 ck_assert((uintptr_t)p == (uintptr_t)(i + j));
55 ck_assert_int_eq(-1, u16id2ptr_drop(pi2p, j, NULL));
58 ck_assert_int_eq(n, u16id2ptr_count(*pi2p));
59 for (x = 0 ; x < n ; x++) {
60 ck_assert_int_eq(0, u16id2ptr_at(*pi2p, x, &j, &p));
61 ck_assert((ni >> j) & 1);
62 ck_assert((uintptr_t)p == (uintptr_t)(ni + j));
66 u16id2ptr_forall(*pi2p, cbi2p, y);
67 ck_assert_int_eq(n, y[1]);
72 START_TEST (check_u16id2ptr)
74 struct u16id2ptr *i2p;
79 u16id2ptr_destroy(&i2p);
81 ck_assert_int_eq(0, u16id2ptr_create(&i2p));
84 u16id2ptr_destroy(&i2p);
89 /*********************************************************************/
91 void test_i2bool(struct u16id2bool **pi2b)
99 for (j = 0 ; j < S ; j++) {
100 x = (uint16_t)(j * 5);
102 ck_assert_int_eq(v, u16id2bool_get(*pi2b, x));
103 ck_assert_int_eq(v, u16id2bool_set(pi2b, x, (ni >> j) & 1));
107 for (j = 0 ; j < S ; j++) {
108 x = (uint16_t)(j * 5);
110 ck_assert_int_eq(v, u16id2bool_get(*pi2b, x));
111 ck_assert_int_eq(v, u16id2bool_set(pi2b, x, 0));
115 START_TEST (check_u16id2bool)
117 struct u16id2bool *i2b;
122 u16id2bool_destroy(&i2b);
124 ck_assert_int_eq(0, u16id2bool_create(&i2b));
127 u16id2bool_destroy(&i2b);
132 /*********************************************************************/
137 void mksuite(const char *name) { suite = suite_create(name); }
138 void addtcase(const char *name) { tcase = tcase_create(name); suite_add_tcase(suite, tcase); tcase_set_timeout(tcase, 120); }
139 void addtest(TFun fun) { tcase_add_test(tcase, fun); }
143 SRunner *srunner = srunner_create(suite);
144 srunner_run_all(srunner, CK_NORMAL);
145 nerr = srunner_ntests_failed(srunner);
146 srunner_free(srunner);
150 int main(int ac, char **av)
154 addtest(check_u16id2ptr);
155 addtest(check_u16id2bool);