X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fhtable%2Ftest%2Frun-type.c;h=c4201ed0cc5f5a6b151603f015ece212d5484d9a;hb=209a81909942a07cb334d6dcae7626a3ecde141d;hp=e1a78f49616eee40d421994253b30b1c07a5aba7;hpb=fb92682e8b55b813fd4bcfad42b63e57cd9aae21;p=ccan diff --git a/ccan/htable/test/run-type.c b/ccan/htable/test/run-type.c index e1a78f49..c4201ed0 100644 --- a/ccan/htable/test/run-type.c +++ b/ccan/htable/test/run-type.c @@ -65,7 +65,7 @@ static void find_vals(const struct htable_obj *ht, return; } } - pass("Found %u numbers in hash", i); + ok1(htable_obj_count(ht) == i); } static void del_vals(struct htable_obj *ht, @@ -83,7 +83,7 @@ static void del_vals(struct htable_obj *ht, } static void del_vals_bykey(struct htable_obj *ht, - const struct obj val[], unsigned int num) + const struct obj val[] UNNEEDED, unsigned int num) { unsigned int i; @@ -107,7 +107,7 @@ static bool check_mask(struct htable *ht, const struct obj val[], unsigned num) return true; } -int main(int argc, char *argv[]) +int main(void) { unsigned int i; struct htable_obj ht, ht2; @@ -116,22 +116,24 @@ int main(int argc, char *argv[]) void *p; struct htable_obj_iter iter; - plan_tests(29); + plan_tests(35); for (i = 0; i < NUM_VALS; i++) val[i].key = i; dne = i; htable_obj_init(&ht); - ok1(ht.raw.max == 0); + ok1(htable_obj_count(&ht) == 0); + ok1(ht_max(&ht.raw) == 0); ok1(ht.raw.bits == 0); /* We cannot find an entry which doesn't exist. */ ok1(!htable_obj_get(&ht, &dne)); + ok1(!htable_obj_pick(&ht, 0, NULL)); /* Fill it, it should increase in size. */ add_vals(&ht, val, NUM_VALS); ok1(ht.raw.bits == NUM_BITS + 1); - ok1(ht.raw.max < (1 << ht.raw.bits)); + ok1(ht_max(&ht.raw) < (1 << ht.raw.bits)); /* Mask should be set. */ ok1(ht.raw.common_mask != 0); @@ -141,6 +143,8 @@ int main(int argc, char *argv[]) /* Find all. */ find_vals(&ht, val, NUM_VALS); ok1(!htable_obj_get(&ht, &dne)); + ok1(htable_obj_pick(&ht, 0, NULL)); + ok1(htable_obj_pick(&ht, 0, &iter)); /* Walk once, should get them all. */ i = 0; @@ -205,6 +209,8 @@ int main(int argc, char *argv[]) } htable_obj_clear(&ht); + ok1(htable_obj_count(&ht) == 0); htable_obj_clear(&ht2); + ok1(htable_obj_count(&ht2) == 0); return exit_status(); }