]> git.ozlabs.org Git - ccan/blob - ccan/htable/test/run-clash.c
base64: fix for unsigned chars (e.g. ARM).
[ccan] / ccan / htable / test / run-clash.c
1 #include <ccan/htable/htable.h>
2 #include <ccan/htable/htable.c>
3 #include <ccan/tap/tap.h>
4 #include <stdbool.h>
5 #include <string.h>
6
7 /* Clashy hash */
8 static size_t hash(const void *elem, void *unused UNNEEDED)
9 {
10         return 0;
11 }
12
13 int main(void)
14 {
15         struct htable ht;
16
17         plan_tests(254 * 253);
18         /* We try to get two elements which clash */
19         for (size_t i = 2; i < 256; i++) {
20                 for (size_t j = 2; j < 256; j++) {
21                         if (i == j)
22                                 continue;
23                         htable_init(&ht, hash, NULL);
24                         htable_add(&ht, hash((void *)i, NULL), (void *)i);
25                         htable_add(&ht, hash((void *)j, NULL), (void *)j);
26                         ok1(htable_check(&ht, "test"));
27                         htable_clear(&ht);
28                 }
29         }
30         return exit_status();
31 }