diff --git a/test/test_ht.c b/test/test_ht.c index 93999a4..7dd2fdd 100644 --- a/test/test_ht.c +++ b/test/test_ht.c @@ -70,7 +70,11 @@ bool foreach_steal_test_callback(void *key, void *value, void *user_data) { return !data->flag; } -int main() { +bool find_test_callback(void *key, void *value, void *user_data) { + return strcmp(key, user_data) == 0; +} + +int main(int argc, const char **argv) { int64_t allocation_count = 0; const HTTableFunctions ONE_STR_FNS = { .hash = ht_string_hash_callback, @@ -277,6 +281,18 @@ int main() { assert(ht_foreach_steal(t2, foreach_steal_test_callback, &acaf)); assert(ht_count(t2) == 25); + void *target = NULL; + for (size_t i = 0; i < 100; ++i) { + if (ht_has(t2, STRS_COPY3[i])) { + target = STRS_COPY3[i]; + break; + } + } + assert(target); + assert(ht_find(t2, find_test_callback, target, &found_key, &found_value)); + assert(strcmp(found_key, target) == 0); + assert(strcmp(found_value, target) == 0); + t = ht_copy(t2, counting_strdup, counting_strdup, &allocation_count); assert(ht_clear(t2));