diff -r c8c59d7f4536 -r 6384016df2a3 test/map_tests.c --- a/test/map_tests.c Mon Jul 15 14:25:50 2013 +0200 +++ b/test/map_tests.c Mon Jul 15 15:43:18 2013 +0200 @@ -204,121 +204,6 @@ ucx_map_free(map); } -void* test_ucx_map_store_load_encdec(void *value, void *data, size_t *size) { - const char *string = (const char*) value; - size_t n = strlen(string); - char *encoded = (char*) malloc(n+1); - for (size_t i = 0 ; i < n ; i++) { - encoded[i] = string[n-1-i]; - } - encoded[n] = 0; - *size = n+1; - return encoded; -} - -UCX_TEST_IMPLEMENT(test_ucx_map_store_load) { - UcxMap *map = ucx_map_new(4); - - ucx_map_cstr_put(map, "test", (void*)"test"); - ucx_map_cstr_put(map, "key", (void*)"value"); - ucx_map_cstr_put(map, "other.very.long.key", (void*)"value"); - ucx_map_cstr_put(map, "testkey", (void*)"testvalue"); - ucx_map_cstr_put(map, "simple", (void*)"not a key but an extremely long " - "value to test if the buffer extension works as designed"); - - UCX_TEST_BEGIN - FILE *f = tmpfile(); - UCX_TEST_ASSERT(f, "test file cannot be opened, test aborted") - int r; - - fwrite(" # comment test\n", 1, 16, f); - r = ucx_map_store_enc(map, f, test_ucx_map_store_load_encdec, NULL); - fwrite("!discard this", 1, 13, f); - fflush(f); - - ucx_map_free(map); - map = ucx_map_new(1); - fseek(f, 0, SEEK_SET); - UcxAllocator allocator = UCX_ALLOCATOR_DEFAULT; - r += ucx_map_load_enc(map, f, allocator, - test_ucx_map_store_load_encdec, NULL); - fclose(f); - - const char *value; - UCX_TEST_ASSERT(r == 0, "IO errors, test cannot be performed"); - - value = (const char *) ucx_map_cstr_get(map, "test"); - UCX_TEST_ASSERT(value != NULL, "value not found for key: test"); - UCX_TEST_ASSERT(strcmp(value, "test") == 0, "value error for key: test"); - - value = (const char *) ucx_map_cstr_get(map, "key"); - UCX_TEST_ASSERT(value != NULL, "value not found for key: key"); - UCX_TEST_ASSERT(strcmp(value, "value") == 0, "value error for key: key"); - - value = (const char *) ucx_map_cstr_get(map, "other.very.long.key"); - UCX_TEST_ASSERT(value != NULL, - "value not found for key: other.very.long.key"); - UCX_TEST_ASSERT(strcmp(value, "value") == 0, - "value error for key: other.very.long.key"); - - value = (const char *) ucx_map_cstr_get(map, "testkey"); - UCX_TEST_ASSERT(value != NULL, "value not found for key: testkey"); - UCX_TEST_ASSERT(strcmp(value, "testvalue") == 0, - "value error for key: testkey"); - - value = (const char *) ucx_map_cstr_get(map, "simple"); - UCX_TEST_ASSERT(value != NULL, "value not found for key: simple"); - UCX_TEST_ASSERT(strcmp(value, "not a key but an extremely long value " - "to test if the buffer extension works as designed") == 0, - "value error for key: simple"); - - void *d; - UcxMapIterator iter = ucx_map_iterator(map); - UCX_MAP_FOREACH(key, d, iter) { - free(d); - } - ucx_map_free(map); - UCX_TEST_END -} - -UCX_TEST_IMPLEMENT(test_ucx_map_store_load_with_mempool) { - UcxMap *map = ucx_map_new(4); - - ucx_map_cstr_put(map, "test", (void*)"test"); - ucx_map_cstr_put(map, "key", (void*)"value"); - ucx_map_cstr_put(map, "testkey", (void*)"testvalue"); - ucx_map_cstr_put(map, "simple", (void*)"a simple value"); - - UCX_TEST_BEGIN - FILE *f = tmpfile(); - UCX_TEST_ASSERT(f, "test file cannot be opened, test aborted"); - int r; - r = ucx_map_store_enc(map, f, NULL, NULL); - ucx_map_free(map); - fflush(f); - - UcxMempool *pool = ucx_mempool_new(4); - map = ucx_map_new(4); - fseek(f, 0, SEEK_SET); - UcxAllocator allocator = UCX_ALLOCATOR_MEMPOOL(pool); - r += ucx_map_load_enc(map, f, allocator, - test_ucx_map_store_load_encdec, NULL); - fclose(f); - - UCX_TEST_ASSERT(r == 0, "IO errors, test cannot be performed"); - UcxMapIterator iter = ucx_map_iterator(map); - const char *value; size_t n; - UCX_MAP_FOREACH(key, value, iter) { - n = strlen(value); - UCX_TEST_ASSERT(strncmp((const char*) pool->data[iter.index], value, n), - "values of map does not match pooled values"); - } - - ucx_mempool_free(pool); - ucx_map_free(map); - UCX_TEST_END -} - UCX_TEST_IMPLEMENT(test_ucx_map_clone) { UcxMap *map = ucx_map_new(4);