test/map_tests.c

changeset 33
9c219a62070d
parent 32
c7af4ec56e19
child 34
0dcd2ca2a223
     1.1 --- a/test/map_tests.c	Thu May 31 09:18:26 2012 +0200
     1.2 +++ b/test/map_tests.c	Thu May 31 12:51:22 2012 +0200
     1.3 @@ -4,20 +4,19 @@
     1.4  
     1.5  #include "map_tests.h"
     1.6  
     1.7 -UCX_TEST_BEGIN(test_ucx_map_new) {
     1.8 +UCX_TEST_IMPLEMENT(test_ucx_map_new) {
     1.9      UcxMap *map = ucx_map_new(16);
    1.10 -    
    1.11 +    UCX_TEST_BEGIN
    1.12      UCX_TEST_ASSERT(map->size == 16, "wrong size")
    1.13      UCX_TEST_ASSERT(map->map != NULL, "failed")
    1.14      
    1.15 +    UCX_TEST_END
    1.16      ucx_map_free(map);
    1.17 -    
    1.18 -    UCX_TEST_END
    1.19  }
    1.20  
    1.21 -UCX_TEST_BEGIN(test_ucx_key) {
    1.22 -    
    1.23 +UCX_TEST_IMPLEMENT(test_ucx_key) {
    1.24      UcxKey key = ucx_key("This is a text.", 15);
    1.25 +    UCX_TEST_BEGIN
    1.26      UCX_TEST_ASSERT(strncmp(key.data, "This is a text.", 15) == 0, "failed")
    1.27      UCX_TEST_ASSERT(key.len == 15, "failed")
    1.28      UCX_TEST_ASSERT(key.hash == 1261186027, "hash failed")
    1.29 @@ -25,13 +24,14 @@
    1.30      UCX_TEST_END
    1.31  }
    1.32  
    1.33 -UCX_TEST_BEGIN(test_ucx_map_put) {
    1.34 +UCX_TEST_IMPLEMENT(test_ucx_map_put) {
    1.35      
    1.36      UcxMap *map = ucx_map_new(4);
    1.37      
    1.38      int td[5];
    1.39      td[0] = 10; td[1] = 42; td[2] = 70; td[3] = 11200; td[4] = 80000;
    1.40  
    1.41 +    UCX_TEST_BEGIN
    1.42      ucx_map_cstr_put(map, "Key2", &td[2]); /* 0 */
    1.43      ucx_map_cstr_put(map, "Key0", &td[0]); /* 0 */
    1.44      ucx_map_cstr_put(map, "Key1", &td[1]); /* 3 */
    1.45 @@ -63,19 +63,18 @@
    1.46              "overwrite failed")
    1.47      UCX_TEST_ASSERT(map->map[0]->next->next->next == NULL, "overwrite failed")
    1.48      
    1.49 +    UCX_TEST_END
    1.50      ucx_map_free(map);
    1.51 -    
    1.52 +}
    1.53 +
    1.54 +UCX_TEST_IMPLEMENT(test_ucx_map_get) {
    1.55 +    UCX_TEST_BEGIN
    1.56 +    UCX_TEST_ASSERT(0, "not implemented");
    1.57      UCX_TEST_END
    1.58  }
    1.59  
    1.60 -UCX_TEST_BEGIN(test_ucx_map_get) {
    1.61 -    // TODO:
    1.62 -    UCX_TEST_END
    1.63 -}
    1.64 -
    1.65 -UCX_TEST_BEGIN(test_ucx_map_iterator) {
    1.66 -    UcxMap *map = ucx_map_new(16);
    1.67 -    
    1.68 +UCX_TEST_SUBROUTINE(test_ucx_map_itersrt, mapptr) {
    1.69 +    UcxMap *map = (UcxMap*) mapptr;
    1.70      int v1 = 10;
    1.71      int v2 = 15;
    1.72      int v3 = 7;
    1.73 @@ -97,29 +96,20 @@
    1.74  
    1.75      UCX_TEST_ASSERT(hit == 4, "test1: wrong number of hits");
    1.76      UCX_TEST_ASSERT(check == v1+v2+v3+v4, "test1: wrong result");
    1.77 +}
    1.78  
    1.79 +UCX_TEST_IMPLEMENT(test_ucx_map_iterator) {
    1.80 +    UcxMap *map = ucx_map_new(16);
    1.81 +    UCX_TEST_BEGIN
    1.82 +    UCX_TEST_CALL_SUBROUTINE(test_ucx_map_itersrt, map)
    1.83 +    UCX_TEST_END
    1.84      ucx_map_free(map);
    1.85 -    
    1.86 -    map = ucx_map_new(1);
    1.87 -    ucx_map_cstr_put(map, "v1", &v1);
    1.88 -    ucx_map_cstr_put(map, "v2", &v2);
    1.89 -    ucx_map_cstr_put(map, "v3", &v3);
    1.90 -    ucx_map_cstr_put(map, "v4", &v4);
    1.91 -    
    1.92 -    i = ucx_map_iterator(map);
    1.93 -    check = 0;
    1.94 -    hit = 0;
    1.95 -    
    1.96 -    UCX_MAP_FOREACH(int*, v, map, i) {
    1.97 -        check += *v;
    1.98 -        hit++;
    1.99 -    }
   1.100 -    
   1.101 -    UCX_TEST_ASSERT(hit == 4, "test2: wrong number of hits");
   1.102 -    UCX_TEST_ASSERT(check == v1+v2+v3+v4, "test2: wrong result");
   1.103 -    
   1.104 -    
   1.105 +}
   1.106 +
   1.107 +UCX_TEST_IMPLEMENT(test_ucx_map_iterator_chain) {
   1.108 +    UcxMap *map = ucx_map_new(1);
   1.109 +    UCX_TEST_BEGIN
   1.110 +    UCX_TEST_CALL_SUBROUTINE(test_ucx_map_itersrt, map)
   1.111 +    UCX_TEST_END
   1.112      ucx_map_free(map);
   1.113 -    
   1.114 -    UCX_TEST_END
   1.115  }

mercurial