test/map_tests.c

changeset 71
303dabadff1c
parent 69
fb59270b1de3
child 76
655020a30e77
equal deleted inserted replaced
69:fb59270b1de3 71:303dabadff1c
13 UCX_TEST_END 13 UCX_TEST_END
14 ucx_map_free(map); 14 ucx_map_free(map);
15 } 15 }
16 16
17 UCX_TEST_IMPLEMENT(test_ucx_key) { 17 UCX_TEST_IMPLEMENT(test_ucx_key) {
18 UcxKey key = ucx_key("This is a text.", 15); 18 UcxKey key = ucx_key((void*)"This is a text.", 15);
19 UCX_TEST_BEGIN 19 UCX_TEST_BEGIN
20 UCX_TEST_ASSERT(strncmp((const char*)key.data, "This is a text.", 15) == 0, 20 UCX_TEST_ASSERT(strncmp((const char*)key.data, "This is a text.", 15) == 0,
21 "failed"); 21 "failed");
22 UCX_TEST_ASSERT(key.len == 15, "failed"); 22 UCX_TEST_ASSERT(key.len == 15, "failed");
23 UCX_TEST_ASSERT(key.hash == 1261186027, "hash failed"); 23 UCX_TEST_ASSERT(key.hash == 1261186027, "hash failed");
192 } 192 }
193 193
194 UCX_TEST_IMPLEMENT(test_ucx_map_store_load) { 194 UCX_TEST_IMPLEMENT(test_ucx_map_store_load) {
195 UcxMap *map = ucx_map_new(4); 195 UcxMap *map = ucx_map_new(4);
196 196
197 ucx_map_cstr_put(map, "test", "test"); 197 ucx_map_cstr_put(map, "test", (void*)"test");
198 ucx_map_cstr_put(map, "key", "value"); 198 ucx_map_cstr_put(map, "key", (void*)"value");
199 ucx_map_cstr_put(map, "other.very.long.key", "value"); 199 ucx_map_cstr_put(map, "other.very.long.key", (void*)"value");
200 ucx_map_cstr_put(map, "testkey", "testvalue"); 200 ucx_map_cstr_put(map, "testkey", (void*)"testvalue");
201 ucx_map_cstr_put(map, "simple", "not a key but an extremely long value " 201 ucx_map_cstr_put(map, "simple", (void*)"not a key but an extremely long "
202 "to test if the buffer extension works as designed"); 202 "value to test if the buffer extension works as designed");
203 203
204 UCX_TEST_BEGIN 204 UCX_TEST_BEGIN
205 FILE *f = tmpfile(); 205 FILE *f = tmpfile();
206 UCX_TEST_ASSERT(f, "test file cannot be opened, test aborted") 206 UCX_TEST_ASSERT(f, "test file cannot be opened, test aborted")
207 int r; 207 int r;
257 } 257 }
258 258
259 UCX_TEST_IMPLEMENT(test_ucx_map_store_load_with_mempool) { 259 UCX_TEST_IMPLEMENT(test_ucx_map_store_load_with_mempool) {
260 UcxMap *map = ucx_map_new(4); 260 UcxMap *map = ucx_map_new(4);
261 261
262 ucx_map_cstr_put(map, "test", "test"); 262 ucx_map_cstr_put(map, "test", (void*)"test");
263 ucx_map_cstr_put(map, "key", "value"); 263 ucx_map_cstr_put(map, "key", (void*)"value");
264 ucx_map_cstr_put(map, "testkey", "testvalue"); 264 ucx_map_cstr_put(map, "testkey", (void*)"testvalue");
265 ucx_map_cstr_put(map, "simple", "a simple value"); 265 ucx_map_cstr_put(map, "simple", (void*)"a simple value");
266 266
267 UCX_TEST_BEGIN 267 UCX_TEST_BEGIN
268 FILE *f = tmpfile(); 268 FILE *f = tmpfile();
269 UCX_TEST_ASSERT(f, "test file cannot be opened, test aborted") 269 UCX_TEST_ASSERT(f, "test file cannot be opened, test aborted")
270 int r; 270 int r;
295 } 295 }
296 296
297 UCX_TEST_IMPLEMENT(test_ucx_map_clone) { 297 UCX_TEST_IMPLEMENT(test_ucx_map_clone) {
298 UcxMap *map = ucx_map_new(4); 298 UcxMap *map = ucx_map_new(4);
299 299
300 ucx_map_cstr_put(map, "key1", "value1"); 300 ucx_map_cstr_put(map, "key1", (void*)"value1");
301 ucx_map_cstr_put(map, "key2", "value2"); 301 ucx_map_cstr_put(map, "key2", (void*)"value2");
302 ucx_map_cstr_put(map, "key3", "value3"); 302 ucx_map_cstr_put(map, "key3", (void*)"value3");
303 303
304 UcxMap *clone = ucx_map_clone(map, NULL, NULL); 304 UcxMap *clone = ucx_map_clone(map, NULL, NULL);
305 305
306 const char *v1 = (const char *) ucx_map_cstr_get(map, "key1"); 306 const char *v1 = (const char *) ucx_map_cstr_get(map, "key1");
307 const char *v2 = (const char *) ucx_map_cstr_get(map, "key2"); 307 const char *v2 = (const char *) ucx_map_cstr_get(map, "key2");

mercurial