diff -r c7af4ec56e19 -r 9c219a62070d test/map_tests.c --- a/test/map_tests.c Thu May 31 09:18:26 2012 +0200 +++ b/test/map_tests.c Thu May 31 12:51:22 2012 +0200 @@ -4,20 +4,19 @@ #include "map_tests.h" -UCX_TEST_BEGIN(test_ucx_map_new) { +UCX_TEST_IMPLEMENT(test_ucx_map_new) { UcxMap *map = ucx_map_new(16); - + UCX_TEST_BEGIN UCX_TEST_ASSERT(map->size == 16, "wrong size") UCX_TEST_ASSERT(map->map != NULL, "failed") + UCX_TEST_END ucx_map_free(map); - - UCX_TEST_END } -UCX_TEST_BEGIN(test_ucx_key) { - +UCX_TEST_IMPLEMENT(test_ucx_key) { UcxKey key = ucx_key("This is a text.", 15); + UCX_TEST_BEGIN UCX_TEST_ASSERT(strncmp(key.data, "This is a text.", 15) == 0, "failed") UCX_TEST_ASSERT(key.len == 15, "failed") UCX_TEST_ASSERT(key.hash == 1261186027, "hash failed") @@ -25,13 +24,14 @@ UCX_TEST_END } -UCX_TEST_BEGIN(test_ucx_map_put) { +UCX_TEST_IMPLEMENT(test_ucx_map_put) { UcxMap *map = ucx_map_new(4); int td[5]; td[0] = 10; td[1] = 42; td[2] = 70; td[3] = 11200; td[4] = 80000; + UCX_TEST_BEGIN ucx_map_cstr_put(map, "Key2", &td[2]); /* 0 */ ucx_map_cstr_put(map, "Key0", &td[0]); /* 0 */ ucx_map_cstr_put(map, "Key1", &td[1]); /* 3 */ @@ -63,19 +63,18 @@ "overwrite failed") UCX_TEST_ASSERT(map->map[0]->next->next->next == NULL, "overwrite failed") + UCX_TEST_END ucx_map_free(map); - +} + +UCX_TEST_IMPLEMENT(test_ucx_map_get) { + UCX_TEST_BEGIN + UCX_TEST_ASSERT(0, "not implemented"); UCX_TEST_END } -UCX_TEST_BEGIN(test_ucx_map_get) { - // TODO: - UCX_TEST_END -} - -UCX_TEST_BEGIN(test_ucx_map_iterator) { - UcxMap *map = ucx_map_new(16); - +UCX_TEST_SUBROUTINE(test_ucx_map_itersrt, mapptr) { + UcxMap *map = (UcxMap*) mapptr; int v1 = 10; int v2 = 15; int v3 = 7; @@ -97,29 +96,20 @@ UCX_TEST_ASSERT(hit == 4, "test1: wrong number of hits"); UCX_TEST_ASSERT(check == v1+v2+v3+v4, "test1: wrong result"); +} +UCX_TEST_IMPLEMENT(test_ucx_map_iterator) { + UcxMap *map = ucx_map_new(16); + UCX_TEST_BEGIN + UCX_TEST_CALL_SUBROUTINE(test_ucx_map_itersrt, map) + UCX_TEST_END 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_TEST_IMPLEMENT(test_ucx_map_iterator_chain) { + UcxMap *map = ucx_map_new(1); + UCX_TEST_BEGIN + UCX_TEST_CALL_SUBROUTINE(test_ucx_map_itersrt, map) + UCX_TEST_END ucx_map_free(map); - - UCX_TEST_END }