aboutsummaryrefslogtreecommitdiff
path: root/src/tests/ktests/hashtbl2/test.c
blob: 2441e79bfeee7bfb4ecb550e4f928ba093b65a31 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <hashtbl.h>

void test_hashtbl_2() {
	BEGIN_TEST("test-hashtbl-2");

	hashtbl_t *ht = create_hashtbl(id_key_eq_fun, id_hash_fun, 0);
	ASSERT(ht != 0);

	ASSERT(hashtbl_add(ht, (void*)12, "TESTSTR12"));
	ASSERT(hashtbl_add(ht, (void*)777, "TESTSTR777"));

	ASSERT(hashtbl_find(ht, (void*)12) != 0 &&
			strcmp(hashtbl_find(ht, (void*)12), "TESTSTR12") == 0);
	ASSERT(hashtbl_find(ht, (void*)777) != 0 &&
			strcmp(hashtbl_find(ht, (void*)777), "TESTSTR777") == 0);
	ASSERT(hashtbl_find(ht, (void*)144) == 0);

	ASSERT(hashtbl_add(ht, (void*)144, "Forever alone"));

	ASSERT(hashtbl_find(ht, (void*)12) != 0 &&
			strcmp(hashtbl_find(ht, (void*)12), "TESTSTR12") == 0);
	ASSERT(hashtbl_find(ht, (void*)144) != 0 &&
			strcmp(hashtbl_find(ht, (void*)144), "Forever alone") == 0);
	ASSERT(hashtbl_find(ht, (void*)777) != 0 &&
			strcmp(hashtbl_find(ht, (void*)777), "TESTSTR777") == 0);

	hashtbl_remove(ht, (void*)12);
	ASSERT(hashtbl_find(ht, (void*)12) == 0);
	ASSERT(hashtbl_find(ht, (void*)144) != 0 &&
			strcmp(hashtbl_find(ht, (void*)144), "Forever alone") == 0);
	ASSERT(hashtbl_find(ht, (void*)777) != 0 &&
			strcmp(hashtbl_find(ht, (void*)777), "TESTSTR777") == 0);

	delete_hashtbl(ht);

	TEST_OK;
}

#undef TEST_PLACEHOLDER_AFTER_TASKING
#define TEST_PLACEHOLDER_AFTER_TASKING { test_hashtbl_2(); }

/* vim: set ts=4 sw=4 tw=0 noet :*/