| 106 | } |
| 107 | |
| 108 | int main(void) |
| 109 | { |
| 110 | unsigned int i; |
| 111 | uintptr_t perfect_bit; |
| 112 | struct htable ht; |
| 113 | uint64_t val[NUM_VALS]; |
| 114 | uint64_t dne; |
| 115 | void *p; |
| 116 | struct htable_iter iter; |
| 117 | |
| 118 | plan_tests(36); |
| 119 | for (i = 0; i < NUM_VALS; i++) |
| 120 | val[i] = i; |
| 121 | dne = i; |
| 122 | |
| 123 | htable_init(&ht, hash, NULL); |
| 124 | ok1(ht_max(&ht) == 0); |
| 125 | ok1(ht.bits == 0); |
| 126 | |
| 127 | /* We cannot find an entry which doesn't exist. */ |
| 128 | ok1(!htable_get(&ht, hash(&dne, NULL), objcmp, &dne)); |
| 129 | |
| 130 | /* This should increase it once. */ |
| 131 | add_vals(&ht, val, 0, 1); |
| 132 | ok1(ht.bits == 1); |
| 133 | ok1(ht_max(&ht) == 1); |
| 134 | ok1(ht.common_mask == -1); |
| 135 | |
| 136 | /* Mask should be set. */ |
| 137 | ok1(check_mask(&ht, val, 1)); |
| 138 | |
| 139 | /* This should increase it again. */ |
| 140 | add_vals(&ht, val, 1, 1); |
| 141 | ok1(ht.bits == 2); |
| 142 | ok1(ht_max(&ht) == 3); |
| 143 | |
| 144 | /* Mask should be set. */ |
| 145 | ok1(ht.common_mask != 0); |
| 146 | ok1(ht.common_mask != -1); |
| 147 | ok1(check_mask(&ht, val, 2)); |
| 148 | |
| 149 | /* Now do the rest. */ |
| 150 | add_vals(&ht, val, 2, NUM_VALS - 2); |
| 151 | |
| 152 | /* Find all. */ |
| 153 | find_vals(&ht, val, NUM_VALS); |
| 154 | ok1(!htable_get(&ht, hash(&dne, NULL), objcmp, &dne)); |
| 155 | |
| 156 | /* Walk once, should get them all. */ |
| 157 | i = 0; |
| 158 | for (p = htable_first(&ht,&iter); p; p = htable_next(&ht, &iter)) |
| 159 | i++; |
| 160 | ok1(i == NUM_VALS); |
| 161 | |
| 162 | i = 0; |
| 163 | for (p = htable_prev(&ht, &iter); p; p = htable_prev(&ht, &iter)) |
| 164 | i++; |
| 165 | ok1(i == NUM_VALS); |
nothing calls this directly
no test coverage detected