diff options
Diffstat (limited to 'src/tests/ktests/hashtbl1')
l--------- | src/tests/ktests/hashtbl1/Makefile | 1 | ||||
-rw-r--r-- | src/tests/ktests/hashtbl1/test.c | 41 |
2 files changed, 42 insertions, 0 deletions
diff --git a/src/tests/ktests/hashtbl1/Makefile b/src/tests/ktests/hashtbl1/Makefile new file mode 120000 index 0000000..4630a7c --- /dev/null +++ b/src/tests/ktests/hashtbl1/Makefile @@ -0,0 +1 @@ +../rules.make
\ No newline at end of file diff --git a/src/tests/ktests/hashtbl1/test.c b/src/tests/ktests/hashtbl1/test.c new file mode 100644 index 0000000..993718c --- /dev/null +++ b/src/tests/ktests/hashtbl1/test.c @@ -0,0 +1,41 @@ +#include <hashtbl.h> + +void test_hashtbl_1() { + BEGIN_TEST("test-hashtbl-1"); + + // hashtable test + hashtbl_t *ht = create_hashtbl(str_key_eq_fun, str_hash_fun, 0); + ASSERT(ht != 0); + + ASSERT(hashtbl_add(ht, "test1", "STRTEST1")); + ASSERT(hashtbl_add(ht, "test2", "STRTEST2")); + ASSERT(hashtbl_find(ht, "test1") != 0 && + strcmp(hashtbl_find(ht, "test1"), "STRTEST1") == 0); + ASSERT(hashtbl_find(ht, "test2") != 0 && + strcmp(hashtbl_find(ht, "test2"), "STRTEST2") == 0); + ASSERT(hashtbl_find(ht, "test") == 0); + + ASSERT(hashtbl_add(ht, "test", "Forever alone")); + ASSERT(hashtbl_find(ht, "test1") != 0 && + strcmp(hashtbl_find(ht, "test1"), "STRTEST1") == 0); + ASSERT(hashtbl_find(ht, "test2") != 0 && + strcmp(hashtbl_find(ht, "test2"), "STRTEST2") == 0); + ASSERT(hashtbl_find(ht, "test") != 0 && + strcmp(hashtbl_find(ht, "test"), "Forever alone") == 0); + + hashtbl_remove(ht, "test1"); + ASSERT(hashtbl_find(ht, "test1") == 0); + ASSERT(hashtbl_find(ht, "test2") != 0 && + strcmp(hashtbl_find(ht, "test2"), "STRTEST2") == 0); + ASSERT(hashtbl_find(ht, "test") != 0 && + strcmp(hashtbl_find(ht, "test"), "Forever alone") == 0); + + delete_hashtbl(ht); + + TEST_OK; +} + +#undef TEST_PLACEHOLDER_AFTER_TASKING +#define TEST_PLACEHOLDER_AFTER_TASKING { test_hashtbl_1(); } + +/* vim: set ts=4 sw=4 tw=0 noet :*/ |