test/map_tests.c

changeset 44
46356d74e873
parent 43
02f38adea013
child 46
48ca036d7d9c
     1.1 --- a/test/map_tests.c	Thu Oct 04 18:23:32 2012 +0200
     1.2 +++ b/test/map_tests.c	Thu Oct 04 18:46:57 2012 +0200
     1.3 @@ -4,6 +4,10 @@
     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 @@ -194,3 +198,40 @@
    1.15  
    1.16      unlink("test_ucx_map_store");
    1.17  }
    1.18 +
    1.19 +UCX_TEST_IMPLEMENT(test_ucx_map_clone) {
    1.20 +    UcxMap *map = ucx_map_new(4);
    1.21 +    
    1.22 +    ucx_map_cstr_put(map, "key1", "value1");
    1.23 +    ucx_map_cstr_put(map, "key2", "value2");
    1.24 +    ucx_map_cstr_put(map, "key3", "value3");
    1.25 +    
    1.26 +    UcxMap *clone = ucx_map_clone(map, NULL, NULL);
    1.27 +    
    1.28 +    char *v1 = ucx_map_cstr_get(map, "key1");
    1.29 +    char *v2 = ucx_map_cstr_get(map, "key2");
    1.30 +    char *v3 = ucx_map_cstr_get(map, "key3");
    1.31 +    
    1.32 +    UCX_TEST_BEGIN
    1.33 +    
    1.34 +    UCX_TEST_ASSERT(v1 != NULL, "failed key 1");
    1.35 +    UCX_TEST_ASSERT(v2 != NULL, "failed key 2");
    1.36 +    UCX_TEST_ASSERT(v3 != NULL, "failed key 3");
    1.37 +    
    1.38 +    char *c1 = ucx_map_cstr_get(clone, "key1");
    1.39 +    char *c2 = ucx_map_cstr_get(clone, "key2");
    1.40 +    char *c3 = ucx_map_cstr_get(clone, "key3");
    1.41 +    
    1.42 +    UCX_TEST_ASSERT(c1 != NULL, "failed key 1 (clone)");
    1.43 +    UCX_TEST_ASSERT(c2 != NULL, "failed key 2 (clone)");
    1.44 +    UCX_TEST_ASSERT(c3 != NULL, "failed key 3 (clone)");
    1.45 +    
    1.46 +    UCX_TEST_ASSERT(strcmp(c1, v1) == 0, "value error for key1");
    1.47 +    UCX_TEST_ASSERT(strcmp(c2, v2) == 0, "value error for key2");
    1.48 +    UCX_TEST_ASSERT(strcmp(c3, v3) == 0, "value error for key3");
    1.49 +    
    1.50 +    UCX_TEST_END
    1.51 +    
    1.52 +    ucx_map_free(map);
    1.53 +    ucx_map_free(clone);
    1.54 +}

mercurial