]> git.ozlabs.org Git - ccan/blobdiff - ccan/htable/test/run.c
base64: fix for unsigned chars (e.g. ARM).
[ccan] / ccan / htable / test / run.c
index 3608941d97a9de42fde9a96d60d761e00662fc8e..27007a41ac5f94d452ac4a91121b5a122d7f87fe 100644 (file)
@@ -97,7 +97,7 @@ static bool check_mask(struct htable *ht, uint64_t val[], unsigned num)
 
 int main(void)
 {
-       unsigned int i, weight;
+       unsigned int i;
        uintptr_t perfect_bit;
        struct htable ht;
        uint64_t val[NUM_VALS];
@@ -105,7 +105,7 @@ int main(void)
        void *p;
        struct htable_iter iter;
 
-       plan_tests(38);
+       plan_tests(43);
        for (i = 0; i < NUM_VALS; i++)
                val[i] = i;
        dne = i;
@@ -122,18 +122,17 @@ int main(void)
        add_vals(&ht, val, 0, 1);
        ok1(ht.bits == 1);
        ok1(ht_max(&ht) == 1);
-       weight = 0;
-       for (i = 0; i < sizeof(ht.common_mask) * CHAR_BIT; i++) {
-               if (ht.common_mask & ((uintptr_t)1 << i)) {
-                       weight++;
-               }
-       }
-       /* Only one bit should be clear. */
-       ok1(weight == i-1);
+       ok1(ht.common_mask == -1);
 
        /* Mask should be set. */
        ok1(check_mask(&ht, val, 1));
 
+       /* htable_pick should always return that value */
+       ok1(htable_pick(&ht, 0, NULL) == val);
+       ok1(htable_pick(&ht, 1, NULL) == val);
+       ok1(htable_pick(&ht, 0, &iter) == val);
+       ok1(get_raw_ptr(&ht, ht.table[iter.off]) == val);
+       
        /* This should increase it again. */
        add_vals(&ht, val, 1, 1);
        ok1(ht.bits == 2);
@@ -210,6 +209,7 @@ int main(void)
        htable_clear(&ht);
 
        ok1(htable_count(&ht) == 0);
+       ok1(htable_pick(&ht, 0, NULL) == NULL);
 
        return exit_status();
 }