Tue, 09 Oct 2012 10:21:18 +0200
fixed map tests + used tmpfiles in tests
test/logging_tests.c | file | annotate | diff | comparison | revisions | |
test/main.c | file | annotate | diff | comparison | revisions | |
test/map_tests.c | file | annotate | diff | comparison | revisions |
--- a/test/logging_tests.c Mon Oct 08 14:04:52 2012 +0200 +++ b/test/logging_tests.c Tue Oct 09 10:21:18 2012 +0200 @@ -3,27 +3,19 @@ */ #include "logging_tests.h" -#ifndef _WIN32 -#include <unistd.h> -#endif /* not _WIN32 */ UCX_TEST_IMPLEMENT(test_ucx_logger_log) { char buffer[100]; -#if defined _USE_GNU || defined _USE_XOPEN2K8 - FILE *stream = fmemopen(buffer, 100, "w"); -#else - FILE *stream = fopen("test_ucx_logger", "w+"); -#endif /* _WIN32 */ + FILE *stream = tmpfile(); + UcxLogger *logger = ucx_logger_new(stream, UCX_LOGGER_INFO); UCX_TEST_BEGIN ucx_logger_info(logger, ST("[INFO:] allright\n")); ucx_logger_trace(logger, ST("[TRACE:] dont log this!\n")); ucx_logger_error(logger, ST("[ERROR:] error!\n")); -#if !(defined _USE_GNU || defined _USE_XOPEN2K8) fseek(stream, 0, SEEK_SET); fread(buffer, 1, 100, stream); -#endif /* _WIN32 */ UCX_TEST_ASSERT(strncmp(buffer, "[INFO:] allright\n[ERROR:] error!\n", 33) == 0, "incorrect logs"); @@ -32,7 +24,4 @@ free(logger); fclose(stream); -#if !(defined _USE_GNU || defined _USE_XOPEN2K8) - unlink("test_ucx_logger"); -#endif }
--- a/test/main.c Mon Oct 08 14:04:52 2012 +0200 +++ b/test/main.c Tue Oct 09 10:21:18 2012 +0200 @@ -163,6 +163,7 @@ ucx_test_register(suite, test_sstrsplit); ucx_test_run(suite, stdout); + fflush(stdout); ucx_test_suite_free(suite); return EXIT_SUCCESS;
--- 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 <unistd.h> -#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) {