1.1 --- a/test/map_tests.c Fri Oct 05 16:59:14 2012 +0200 1.2 +++ b/test/map_tests.c Mon Oct 08 12:29:27 2012 +0200 1.3 @@ -95,6 +95,47 @@ 1.4 UCX_TEST_ASSERT(td[3] == 11200, "failed key 3"); 1.5 UCX_TEST_ASSERT(td[4] == 80000, "failed key 4"); 1.6 1.7 + UCX_TEST_ASSERT(map->count == 5, "expected 5 remaining values"); 1.8 + UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key0") != NULL, "element removed"); 1.9 + 1.10 + UCX_TEST_END 1.11 + ucx_map_free(map); 1.12 +} 1.13 + 1.14 +UCX_TEST_IMPLEMENT(test_ucx_map_remove) { 1.15 + UcxMap *map = ucx_map_new(4); 1.16 + 1.17 + int td[5]; 1.18 + td[0] = 10; td[1] = 42; td[2] = 70; td[3] = 11200; td[4] = 80000; 1.19 + 1.20 + ucx_map_cstr_put(map, "Key2", &td[2]); /* 0 */ 1.21 + ucx_map_cstr_put(map, "Key0", &td[0]); /* 0 */ 1.22 + ucx_map_cstr_put(map, "Key1", &td[1]); /* 3 */ 1.23 + ucx_map_cstr_put(map, "KeY3", &td[3]); /* 2 */ 1.24 + ucx_map_cstr_put(map, "KEY4", &td[4]); /* 0 */ 1.25 + UCX_TEST_BEGIN 1.26 + 1.27 + td[0] = *((int*)ucx_map_cstr_remove(map, "Key0")); 1.28 + td[1] = *((int*)ucx_map_cstr_get(map, "Key1")); 1.29 + td[2] = *((int*)ucx_map_cstr_remove(map, "Key2")); 1.30 + td[3] = *((int*)ucx_map_cstr_get(map, "KeY3")); 1.31 + td[4] = *((int*)ucx_map_cstr_get(map, "KEY4")); 1.32 + UCX_TEST_ASSERT(td[0] == 10, "failed key 0"); 1.33 + UCX_TEST_ASSERT(td[1] == 42, "failed key 1"); 1.34 + UCX_TEST_ASSERT(td[2] == 70, "failed key 2"); 1.35 + UCX_TEST_ASSERT(td[3] == 11200, "failed key 3"); 1.36 + UCX_TEST_ASSERT(td[4] == 80000, "failed key 4"); 1.37 + 1.38 + UCX_TEST_ASSERT(map->count == 3, "expected 3 remaining values"); 1.39 + UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key0")==NULL, "element not removed"); 1.40 + UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key1")!=NULL, "element removed"); 1.41 + UCX_TEST_ASSERT(ucx_map_cstr_get(map, "Key2")==NULL, "element not removed"); 1.42 + UCX_TEST_ASSERT(ucx_map_cstr_get(map, "KeY3")!=NULL, "element removed"); 1.43 + UCX_TEST_ASSERT(ucx_map_cstr_get(map, "KEY4")!=NULL, "element removed"); 1.44 + 1.45 + UCX_TEST_ASSERT(ucx_map_cstr_remove(map, "Key2") == NULL, 1.46 + "subsequent remove call shall return NULL"); 1.47 + 1.48 UCX_TEST_END 1.49 ucx_map_free(map); 1.50 }