1.1 --- a/test/map_tests.c Fri Feb 24 15:53:50 2012 +0100 1.2 +++ b/test/map_tests.c Fri May 25 17:39:27 2012 +0200 1.3 @@ -71,3 +71,54 @@ 1.4 UCX_TEST_BEGIN(test_ucx_map_get) { 1.5 UCX_TEST_END 1.6 } 1.7 + 1.8 +UCX_TEST_BEGIN(test_ucx_map_iterator) { 1.9 + UcxMap *map = ucx_map_new(16); 1.10 + 1.11 + int v1 = 10; 1.12 + int v2 = 15; 1.13 + int v3 = 7; 1.14 + int v4 = 9; 1.15 + 1.16 + ucx_map_cstr_put(map, "v1", &v1); 1.17 + ucx_map_cstr_put(map, "v2", &v2); 1.18 + ucx_map_cstr_put(map, "v3", &v3); 1.19 + ucx_map_cstr_put(map, "v4", &v4); 1.20 + 1.21 + UcxMapIterator i = ucx_map_iterator(map); 1.22 + int check = 0; 1.23 + int hit = 0; 1.24 + 1.25 + UCX_MAP_FOREACH(int*, v, map, i) { 1.26 + check += *v; 1.27 + hit++; 1.28 + } 1.29 + 1.30 + UCX_TEST_ASSERT(hit == 4, "test1: wrong number of hits"); 1.31 + UCX_TEST_ASSERT(check == v1+v2+v3+v4, "test1: wrong result"); 1.32 + 1.33 + ucx_map_free(map); 1.34 + 1.35 + map = ucx_map_new(1); 1.36 + ucx_map_cstr_put(map, "v1", &v1); 1.37 + ucx_map_cstr_put(map, "v2", &v2); 1.38 + ucx_map_cstr_put(map, "v3", &v3); 1.39 + ucx_map_cstr_put(map, "v4", &v4); 1.40 + 1.41 + i = ucx_map_iterator(map); 1.42 + check = 0; 1.43 + hit = 0; 1.44 + 1.45 + UCX_MAP_FOREACH(int*, v, map, i) { 1.46 + check += *v; 1.47 + hit++; 1.48 + } 1.49 + 1.50 + UCX_TEST_ASSERT(hit == 4, "test2: wrong number of hits"); 1.51 + UCX_TEST_ASSERT(check == v1+v2+v3+v4, "test2: wrong result"); 1.52 + 1.53 + 1.54 + ucx_map_free(map); 1.55 + 1.56 + UCX_TEST_END 1.57 +}