diff -r ff194559eb41 -r 1c78cd19fb6b test/map_tests.c --- a/test/map_tests.c Fri Oct 05 13:23:25 2012 +0200 +++ b/test/map_tests.c Fri Oct 05 14:06:40 2012 +0200 @@ -285,3 +285,38 @@ ucx_map_free(map); ucx_map_free(clone); } + +UCX_TEST_IMPLEMENT(test_ucx_map_rehash) { + UcxMap *map = ucx_map_new(4); + + char keys[10][5]; + char values[10][7]; + for (int i = 0 ; i < 10 ; i++) { + strcpy(keys[i], "key"); + keys[i][3] = 48+i; keys[i][4] = 0; + strcpy(values[i], "value"); + values[i][5] = 48+i; values[i][6] = 0; + + ucx_map_cstr_put(map, keys[i], values[i]); + } + + map = ucx_map_rehash(map); + + UCX_TEST_BEGIN + UCX_TEST_ASSERT(map->size == 25, "new capacity shall be 2.5 * count"); + UCX_TEST_ASSERT(map->count == 10, "new map element count incorrect"); + for (int i = 0 ; i < 10 ; i++) { + char *value = ucx_map_cstr_get(map, keys[i]); + UCX_TEST_ASSERT(value != NULL, "new map is missing old keys"); + UCX_TEST_ASSERT(strncmp(value, values[i], 6) == 0, + "new map contains incorrect values"); + } + UcxMap *samemap = ucx_map_rehash(map); + UCX_TEST_ASSERT(samemap == map, + "subsequent rehashing call shall do nothing"); + UCX_TEST_ASSERT(samemap->size == 25, + "subsequent rehashing call shall not change size"); + UCX_TEST_END + + ucx_map_free(map); +}