Add uc_htable_remove + test

This commit is contained in:
Nils O. Selåsdal
2013-10-17 22:12:48 +02:00
parent 6c76759355
commit 0f0ae6dd1e
3 changed files with 70 additions and 1 deletions
+44
View File
@@ -163,6 +163,49 @@ START_TEST (test_htable_has_node)
END_TEST
START_TEST (test_htable_remove)
struct MyString str1 = {"One", {0,NULL}};
struct MyString str2 = {"One", {0,NULL}};
struct MyString str3 = {"Other", {0,NULL}};
struct UHTable table;
int rc;
rc = uc_htable_init(&table, 1);
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_remove(&table, &str2.node);
ck_assert_int_eq(uc_htable_count(&table), 2);
//this one should still be here
fail_if(my_find(&table, "One", hash_str("One")) != &str1);
//
//thisone should be gone
rc = uc_htable_has_node(&table, &str2.node);
ck_assert_int_eq(rc, 0);
uc_htable_remove(&table, &str1.node);
ck_assert_int_eq(uc_htable_count(&table), 1);
//now this one should be gone
rc = uc_htable_has_node(&table, &str1.node);
ck_assert_int_eq(rc, 0);
//double removal should be ok
uc_htable_remove(&table, &str1.node);
ck_assert_int_eq(uc_htable_count(&table), 1);
//this one should still be here
fail_if(my_find(&table, "Other", hash_str("Other")) != &str3);
END_TEST
Suite *htable_suite(void)
{
Suite *s = suite_create("htable");
@@ -173,6 +216,7 @@ Suite *htable_suite(void)
tcase_add_test(tc, test_htable_resize);
tcase_add_test(tc, test_htable_fail_init_resize);
tcase_add_test(tc, test_htable_has_node);
tcase_add_test(tc, test_htable_remove);
suite_add_tcase(s, tc);