1.1 --- a/test/map_tests.c Mon Oct 08 14:04:52 2012 +0200 1.2 +++ b/test/map_tests.c Tue Oct 09 10:21:18 2012 +0200 1.3 @@ -4,10 +4,6 @@ 1.4 1.5 #include "map_tests.h" 1.6 1.7 -#ifndef _WIN32 1.8 -#include <unistd.h> 1.9 -#endif /* not _WIN32 */ 1.10 - 1.11 UCX_TEST_IMPLEMENT(test_ucx_map_new) { 1.12 UcxMap *map = ucx_map_new(16); 1.13 UCX_TEST_BEGIN 1.14 @@ -204,24 +200,24 @@ 1.15 ucx_map_cstr_put(map, "simple", "not a key but an extremely long value " 1.16 "to test if the buffer extension works as designed"); 1.17 1.18 - FILE *f = fopen("test_ucx_map_store", "w"); 1.19 + UCX_TEST_BEGIN 1.20 + FILE *f = tmpfile(); 1.21 + UCX_TEST_ASSERT(f, "test file cannot be opened, test aborted") 1.22 int r; 1.23 1.24 fwrite(" # comment test\n", 1, 16, f); 1.25 r = ucx_map_store_enc(map, f, test_ucx_map_store_load_encdec, NULL); 1.26 fwrite("!discard this", 1, 13, f); 1.27 + fflush(f); 1.28 1.29 - fclose(f); 1.30 ucx_map_free(map); 1.31 map = ucx_map_new(1); 1.32 - f = fopen("test_ucx_map_store", "r"); 1.33 + fseek(f, 0, SEEK_SET); 1.34 UcxAllocator allocator = UCX_ALLOCATOR_DEFAULT; 1.35 r += ucx_map_load_enc(map, f, allocator, 1.36 test_ucx_map_store_load_encdec, NULL); 1.37 fclose(f); 1.38 - unlink("test_ucx_map_store"); 1.39 1.40 - UCX_TEST_BEGIN 1.41 char *value; 1.42 UCX_TEST_ASSERT(r == 0, "IO errors, test cannot be performed"); 1.43 1.44 @@ -250,6 +246,12 @@ 1.45 "to test if the buffer extension works as designed") == 0, 1.46 "value error for key: simple"); 1.47 1.48 + void *d; 1.49 + UcxMapIterator iter = ucx_map_iterator(map); 1.50 + UCX_MAP_FOREACH(d, iter) { 1.51 + free(d); 1.52 + } 1.53 + ucx_map_free(map); 1.54 UCX_TEST_END 1.55 } 1.56 1.57 @@ -261,22 +263,22 @@ 1.58 ucx_map_cstr_put(map, "testkey", "testvalue"); 1.59 ucx_map_cstr_put(map, "simple", "a simple value"); 1.60 1.61 - FILE *f = fopen("test_ucx_map_store", "w"); 1.62 + UCX_TEST_BEGIN 1.63 + FILE *f = tmpfile(); 1.64 + UCX_TEST_ASSERT(f, "test file cannot be opened, test aborted") 1.65 int r; 1.66 r = ucx_map_store_enc(map, f, NULL, NULL); 1.67 - fclose(f); 1.68 ucx_map_free(map); 1.69 + fflush(f); 1.70 1.71 UcxMempool *pool = ucx_mempool_new(4); 1.72 map = ucx_map_new(4); 1.73 - f = fopen("test_ucx_map_store", "r"); 1.74 + fseek(f, 0, SEEK_SET); 1.75 UcxAllocator allocator = UCX_ALLOCATOR_MEMPOOL(pool); 1.76 r += ucx_map_load_enc(map, f, allocator, 1.77 test_ucx_map_store_load_encdec, NULL); 1.78 fclose(f); 1.79 - unlink("test_ucx_map_store"); 1.80 1.81 - UCX_TEST_BEGIN 1.82 UCX_TEST_ASSERT(r == 0, "IO errors, test cannot be performed"); 1.83 UcxMapIterator iter = ucx_map_iterator(map); 1.84 char *value; size_t n; 1.85 @@ -285,9 +287,10 @@ 1.86 UCX_TEST_ASSERT(strncmp(pool->data[iter.index], value, n), 1.87 "values of map does not match pooled values"); 1.88 } 1.89 - UCX_TEST_END 1.90 1.91 ucx_mempool_free(pool); 1.92 + ucx_map_free(map); 1.93 + UCX_TEST_END 1.94 } 1.95 1.96 UCX_TEST_IMPLEMENT(test_ucx_map_clone) {