diff -r f634f790661a -r 180bc6b18fec test/map_tests.c --- a/test/map_tests.c Mon Oct 08 14:04:52 2012 +0200 +++ b/test/map_tests.c Tue Oct 09 10:21:18 2012 +0200 @@ -4,10 +4,6 @@ #include "map_tests.h" -#ifndef _WIN32 -#include -#endif /* not _WIN32 */ - UCX_TEST_IMPLEMENT(test_ucx_map_new) { UcxMap *map = ucx_map_new(16); UCX_TEST_BEGIN @@ -204,24 +200,24 @@ ucx_map_cstr_put(map, "simple", "not a key but an extremely long value " "to test if the buffer extension works as designed"); - FILE *f = fopen("test_ucx_map_store", "w"); + 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); - fclose(f); ucx_map_free(map); map = ucx_map_new(1); - f = fopen("test_ucx_map_store", "r"); + 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); - unlink("test_ucx_map_store"); - UCX_TEST_BEGIN char *value; UCX_TEST_ASSERT(r == 0, "IO errors, test cannot be performed"); @@ -250,6 +246,12 @@ "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(d, iter) { + free(d); + } + ucx_map_free(map); UCX_TEST_END } @@ -261,22 +263,22 @@ ucx_map_cstr_put(map, "testkey", "testvalue"); ucx_map_cstr_put(map, "simple", "a simple value"); - FILE *f = fopen("test_ucx_map_store", "w"); + 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); - fclose(f); ucx_map_free(map); + fflush(f); UcxMempool *pool = ucx_mempool_new(4); map = ucx_map_new(4); - f = fopen("test_ucx_map_store", "r"); + 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); - 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; @@ -285,9 +287,10 @@ 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_map_free(map); + UCX_TEST_END } UCX_TEST_IMPLEMENT(test_ucx_map_clone) {