Test UC_HTABLE_FOR_EACH

This commit is contained in:
Nils O. Selåsdal
2013-10-17 22:38:00 +02:00
parent b0172a365e
commit 7ff33c113b
2 changed files with 47 additions and 3 deletions
+43
View File
@@ -239,6 +239,48 @@ START_TEST (test_htable_clear)
END_TEST
START_TEST (test_htable_foreach)
struct MyString str1 = {"One", {0,NULL}};
struct MyString str2 = {"One", {0,NULL}};
struct MyString str3 = {"Other",{0,NULL}};
struct UHTable table;
struct UHNode *it;
int rc;
int found1 = 0;
int found2 = 0;
int found3 = 0;
rc = uc_htable_init(&table, 1000);
ck_assert_int_eq(rc, 0);
uc_htable_insert(&table, &str1.node, hash_str(str1.str));
uc_htable_insert(&table, &str2.node, hash_str(str2.str));
uc_htable_insert(&table, &str3.node, hash_str(str3.str));
ck_assert_int_eq(uc_htable_count(&table), 3);
UC_HTABLE_FOREACH(&table, it) {
struct MyString *my_str = UC_CONTAINER_OF(it, struct MyString, node);
if (my_str == &str1) {
found1++;
}
if (my_str == &str2) {
found2++;
}
if (my_str == &str3) {
found3++;
}
}
ck_assert_int_eq(found1, 1);
ck_assert_int_eq(found2, 1);
ck_assert_int_eq(found3, 1);
uc_htable_destroy(&table);
END_TEST
Suite *htable_suite(void)
{
Suite *s = suite_create("htable");
@@ -251,6 +293,7 @@ Suite *htable_suite(void)
tcase_add_test(tc, test_htable_has_node);
tcase_add_test(tc, test_htable_remove);
tcase_add_test(tc, test_htable_clear);
tcase_add_test(tc, test_htable_foreach);
suite_add_tcase(s, tc);