--- a/test/map_tests.c Fri Oct 05 10:25:33 2012 +0200 +++ b/test/map_tests.c Fri Oct 05 11:52:53 2012 +0200 @@ -141,7 +141,7 @@ ucx_map_free(map); } -void* test_ucx_map_store_load_encdec(void *value, void *data) { +void* test_ucx_map_store_load_encdec(void *value, void *data, size_t *size) { char *string = (char*) value; size_t n = strlen(string); char *encoded = malloc(n+1); @@ -149,6 +149,7 @@ encoded[i] = string[n-1-i]; } encoded[n] = 0; + *size = n+1; return encoded; } @@ -173,7 +174,11 @@ ucx_map_free(map); map = ucx_map_new(1); f = fopen("test_ucx_map_store", "r"); - r += ucx_map_load_enc(map, f, test_ucx_map_store_load_encdec, NULL); + UcxAllocator allocator = UCX_ALLOCATOR_DEFAULT; + r += ucx_map_load_enc(map, f, allocator, + test_ucx_map_store_load_encdec, NULL); + fclose(f); + unlink("test_ucx_map_store"); UCX_TEST_BEGIN char *value; @@ -205,9 +210,43 @@ "value error for key: simple"); 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", "test"); + ucx_map_cstr_put(map, "key", "value"); + ucx_map_cstr_put(map, "testkey", "testvalue"); + ucx_map_cstr_put(map, "simple", "a simple value"); + + FILE *f = fopen("test_ucx_map_store", "w"); + int r; + r = ucx_map_store_enc(map, f, NULL, NULL); fclose(f); + ucx_map_free(map); + UcxMempool *pool = ucx_mempool_new(4); + map = ucx_map_new(4); + f = fopen("test_ucx_map_store", "r"); + UcxAllocator allocator = UCX_ALLOCATOR_MEMPOOL(pool); + r += ucx_map_load_enc(map, f, allocator, + test_ucx_map_store_load_encdec, NULL); + fclose(f); unlink("test_ucx_map_store"); + + UCX_TEST_BEGIN + UCX_TEST_ASSERT(r == 0, "IO errors, test cannot be performed"); + UcxMapIterator iter = ucx_map_iterator(map); + char *value; size_t n; + UCX_MAP_FOREACH(value, iter) { + n = strlen(value); + UCX_TEST_ASSERT(strncmp(pool->data[iter.index], value, n), + "values of map does not match pooled values"); + } + UCX_TEST_END + + ucx_mempool_free(pool); } UCX_TEST_IMPLEMENT(test_ucx_map_clone) {