diff -r 23bb65cbf7a4 -r 91ac86557290 test/map_tests.c --- a/test/map_tests.c Fri Feb 24 15:53:50 2012 +0100 +++ b/test/map_tests.c Fri May 25 17:39:27 2012 +0200 @@ -71,3 +71,54 @@ UCX_TEST_BEGIN(test_ucx_map_get) { UCX_TEST_END } + +UCX_TEST_BEGIN(test_ucx_map_iterator) { + UcxMap *map = ucx_map_new(16); + + int v1 = 10; + int v2 = 15; + int v3 = 7; + int v4 = 9; + + ucx_map_cstr_put(map, "v1", &v1); + ucx_map_cstr_put(map, "v2", &v2); + ucx_map_cstr_put(map, "v3", &v3); + ucx_map_cstr_put(map, "v4", &v4); + + UcxMapIterator i = ucx_map_iterator(map); + int check = 0; + int hit = 0; + + UCX_MAP_FOREACH(int*, v, map, i) { + check += *v; + hit++; + } + + UCX_TEST_ASSERT(hit == 4, "test1: wrong number of hits"); + UCX_TEST_ASSERT(check == v1+v2+v3+v4, "test1: wrong result"); + + ucx_map_free(map); + + map = ucx_map_new(1); + ucx_map_cstr_put(map, "v1", &v1); + ucx_map_cstr_put(map, "v2", &v2); + ucx_map_cstr_put(map, "v3", &v3); + ucx_map_cstr_put(map, "v4", &v4); + + i = ucx_map_iterator(map); + check = 0; + hit = 0; + + UCX_MAP_FOREACH(int*, v, map, i) { + check += *v; + hit++; + } + + UCX_TEST_ASSERT(hit == 4, "test2: wrong number of hits"); + UCX_TEST_ASSERT(check == v1+v2+v3+v4, "test2: wrong result"); + + + ucx_map_free(map); + + UCX_TEST_END +}