]> 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 85502c4ab1f8d3dbeb6e69cde0ecaa2cb4560b7e..27007a41ac5f94d452ac4a91121b5a122d7f87fe 100644 (file)
@@ -67,7 +67,7 @@ static void find_vals(struct htable *ht,
                        return;
                }
        }
-       pass("Found %llu numbers in hash", (long long)i);
+       ok1(htable_count(ht) == i);
 }
 
 static void del_vals(struct htable *ht,
@@ -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,12 +105,13 @@ int main(void)
        void *p;
        struct htable_iter iter;
 
-       plan_tests(36);
+       plan_tests(43);
        for (i = 0; i < NUM_VALS; i++)
                val[i] = i;
        dne = i;
 
        htable_init(&ht, hash, NULL);
+       ok1(htable_count(&ht) == 0);
        ok1(ht_max(&ht) == 0);
        ok1(ht.bits == 0);
 
@@ -121,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);
@@ -207,6 +207,9 @@ int main(void)
        ok1(htable_init_sized(&ht, hash, NULL, 1025));
        ok1(ht_max(&ht) >= 1025);
        htable_clear(&ht);
-       
+
+       ok1(htable_count(&ht) == 0);
+       ok1(htable_pick(&ht, 0, NULL) == NULL);
+
        return exit_status();
 }