fixed map tests + used tmpfiles in tests

Tue, 09 Oct 2012 10:21:18 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 09 Oct 2012 10:21:18 +0200
changeset 55
180bc6b18fec
parent 54
f634f790661a
child 56
76caac0da4a0

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
     1.1 --- a/test/logging_tests.c	Mon Oct 08 14:04:52 2012 +0200
     1.2 +++ b/test/logging_tests.c	Tue Oct 09 10:21:18 2012 +0200
     1.3 @@ -3,27 +3,19 @@
     1.4   */
     1.5  
     1.6  #include "logging_tests.h"
     1.7 -#ifndef _WIN32
     1.8 -#include <unistd.h>
     1.9 -#endif /* not _WIN32 */
    1.10  
    1.11  UCX_TEST_IMPLEMENT(test_ucx_logger_log) {
    1.12      char buffer[100];
    1.13 -#if defined _USE_GNU || defined _USE_XOPEN2K8
    1.14 -    FILE *stream = fmemopen(buffer, 100, "w");
    1.15 -#else
    1.16 -    FILE *stream = fopen("test_ucx_logger", "w+");
    1.17 -#endif /* _WIN32 */
    1.18 +    FILE *stream = tmpfile();
    1.19 +
    1.20      UcxLogger *logger = ucx_logger_new(stream, UCX_LOGGER_INFO);
    1.21      
    1.22      UCX_TEST_BEGIN
    1.23      ucx_logger_info(logger, ST("[INFO:] allright\n"));
    1.24      ucx_logger_trace(logger, ST("[TRACE:] dont log this!\n"));
    1.25      ucx_logger_error(logger, ST("[ERROR:] error!\n"));
    1.26 -#if !(defined _USE_GNU || defined _USE_XOPEN2K8)
    1.27      fseek(stream, 0, SEEK_SET);
    1.28      fread(buffer, 1, 100, stream);
    1.29 -#endif /* _WIN32 */
    1.30  
    1.31      UCX_TEST_ASSERT(strncmp(buffer,
    1.32              "[INFO:] allright\n[ERROR:] error!\n", 33) == 0, "incorrect logs");
    1.33 @@ -32,7 +24,4 @@
    1.34  
    1.35      free(logger);
    1.36      fclose(stream);
    1.37 -#if !(defined _USE_GNU || defined _USE_XOPEN2K8)
    1.38 -    unlink("test_ucx_logger");
    1.39 -#endif
    1.40  }
     2.1 --- a/test/main.c	Mon Oct 08 14:04:52 2012 +0200
     2.2 +++ b/test/main.c	Tue Oct 09 10:21:18 2012 +0200
     2.3 @@ -163,6 +163,7 @@
     2.4          ucx_test_register(suite, test_sstrsplit);
     2.5  
     2.6          ucx_test_run(suite, stdout);
     2.7 +        fflush(stdout);
     2.8          ucx_test_suite_free(suite);
     2.9          
    2.10          return EXIT_SUCCESS;
     3.1 --- a/test/map_tests.c	Mon Oct 08 14:04:52 2012 +0200
     3.2 +++ b/test/map_tests.c	Tue Oct 09 10:21:18 2012 +0200
     3.3 @@ -4,10 +4,6 @@
     3.4  
     3.5  #include "map_tests.h"
     3.6  
     3.7 -#ifndef _WIN32
     3.8 -#include <unistd.h>
     3.9 -#endif /* not _WIN32 */
    3.10 -
    3.11  UCX_TEST_IMPLEMENT(test_ucx_map_new) {
    3.12      UcxMap *map = ucx_map_new(16);
    3.13      UCX_TEST_BEGIN
    3.14 @@ -204,24 +200,24 @@
    3.15      ucx_map_cstr_put(map, "simple", "not a key but an extremely long value "
    3.16              "to test if the buffer extension works as designed");
    3.17  
    3.18 -    FILE *f = fopen("test_ucx_map_store", "w");
    3.19 +    UCX_TEST_BEGIN
    3.20 +    FILE *f = tmpfile();
    3.21 +    UCX_TEST_ASSERT(f, "test file cannot be opened, test aborted")
    3.22      int r;
    3.23  
    3.24      fwrite(" # comment test\n", 1, 16, f);
    3.25      r = ucx_map_store_enc(map, f, test_ucx_map_store_load_encdec, NULL);
    3.26      fwrite("!discard this", 1, 13, f);
    3.27 +    fflush(f);
    3.28  
    3.29 -    fclose(f);
    3.30      ucx_map_free(map);
    3.31      map = ucx_map_new(1);
    3.32 -    f = fopen("test_ucx_map_store", "r");
    3.33 +    fseek(f, 0, SEEK_SET);
    3.34      UcxAllocator allocator = UCX_ALLOCATOR_DEFAULT;
    3.35      r += ucx_map_load_enc(map, f, allocator,
    3.36              test_ucx_map_store_load_encdec, NULL);
    3.37      fclose(f);
    3.38 -    unlink("test_ucx_map_store");
    3.39  
    3.40 -    UCX_TEST_BEGIN
    3.41      char *value;
    3.42      UCX_TEST_ASSERT(r == 0, "IO errors, test cannot be performed");
    3.43  
    3.44 @@ -250,6 +246,12 @@
    3.45              "to test if the buffer extension works as designed") == 0,
    3.46              "value error for key: simple");
    3.47  
    3.48 +    void *d;
    3.49 +    UcxMapIterator iter = ucx_map_iterator(map);
    3.50 +    UCX_MAP_FOREACH(d, iter) {
    3.51 +        free(d);
    3.52 +    }
    3.53 +    ucx_map_free(map);
    3.54      UCX_TEST_END
    3.55  }
    3.56  
    3.57 @@ -261,22 +263,22 @@
    3.58      ucx_map_cstr_put(map, "testkey", "testvalue");
    3.59      ucx_map_cstr_put(map, "simple", "a simple value");
    3.60  
    3.61 -    FILE *f = fopen("test_ucx_map_store", "w");
    3.62 +    UCX_TEST_BEGIN
    3.63 +    FILE *f = tmpfile();
    3.64 +    UCX_TEST_ASSERT(f, "test file cannot be opened, test aborted")
    3.65      int r;
    3.66      r = ucx_map_store_enc(map, f, NULL, NULL);
    3.67 -    fclose(f);
    3.68      ucx_map_free(map);
    3.69 +    fflush(f);
    3.70  
    3.71      UcxMempool *pool = ucx_mempool_new(4);
    3.72      map = ucx_map_new(4);
    3.73 -    f = fopen("test_ucx_map_store", "r");
    3.74 +    fseek(f, 0, SEEK_SET);
    3.75      UcxAllocator allocator = UCX_ALLOCATOR_MEMPOOL(pool);
    3.76      r += ucx_map_load_enc(map, f, allocator,
    3.77              test_ucx_map_store_load_encdec, NULL);
    3.78      fclose(f);
    3.79 -    unlink("test_ucx_map_store");
    3.80  
    3.81 -    UCX_TEST_BEGIN
    3.82      UCX_TEST_ASSERT(r == 0, "IO errors, test cannot be performed");
    3.83      UcxMapIterator iter = ucx_map_iterator(map);
    3.84      char *value; size_t n;
    3.85 @@ -285,9 +287,10 @@
    3.86          UCX_TEST_ASSERT(strncmp(pool->data[iter.index], value, n),
    3.87                  "values of map does not match pooled values");
    3.88      }
    3.89 -    UCX_TEST_END
    3.90  
    3.91      ucx_mempool_free(pool);
    3.92 +    ucx_map_free(map);
    3.93 +    UCX_TEST_END
    3.94  }
    3.95  
    3.96  UCX_TEST_IMPLEMENT(test_ucx_map_clone) {

mercurial