test/map_tests.c

changeset 44
46356d74e873
parent 43
02f38adea013
child 46
48ca036d7d9c
equal deleted inserted replaced
43:02f38adea013 44:46356d74e873
1 /* 1 /*
2 * 2 *
3 */ 3 */
4 4
5 #include "map_tests.h" 5 #include "map_tests.h"
6
7 #ifndef _WIN32
8 #include <unistd.h>
9 #endif /* not _WIN32 */
6 10
7 UCX_TEST_IMPLEMENT(test_ucx_map_new) { 11 UCX_TEST_IMPLEMENT(test_ucx_map_new) {
8 UcxMap *map = ucx_map_new(16); 12 UcxMap *map = ucx_map_new(16);
9 UCX_TEST_BEGIN 13 UCX_TEST_BEGIN
10 UCX_TEST_ASSERT(map->size == 16, "wrong size"); 14 UCX_TEST_ASSERT(map->size == 16, "wrong size");
192 UCX_TEST_END 196 UCX_TEST_END
193 fclose(f); 197 fclose(f);
194 198
195 unlink("test_ucx_map_store"); 199 unlink("test_ucx_map_store");
196 } 200 }
201
202 UCX_TEST_IMPLEMENT(test_ucx_map_clone) {
203 UcxMap *map = ucx_map_new(4);
204
205 ucx_map_cstr_put(map, "key1", "value1");
206 ucx_map_cstr_put(map, "key2", "value2");
207 ucx_map_cstr_put(map, "key3", "value3");
208
209 UcxMap *clone = ucx_map_clone(map, NULL, NULL);
210
211 char *v1 = ucx_map_cstr_get(map, "key1");
212 char *v2 = ucx_map_cstr_get(map, "key2");
213 char *v3 = ucx_map_cstr_get(map, "key3");
214
215 UCX_TEST_BEGIN
216
217 UCX_TEST_ASSERT(v1 != NULL, "failed key 1");
218 UCX_TEST_ASSERT(v2 != NULL, "failed key 2");
219 UCX_TEST_ASSERT(v3 != NULL, "failed key 3");
220
221 char *c1 = ucx_map_cstr_get(clone, "key1");
222 char *c2 = ucx_map_cstr_get(clone, "key2");
223 char *c3 = ucx_map_cstr_get(clone, "key3");
224
225 UCX_TEST_ASSERT(c1 != NULL, "failed key 1 (clone)");
226 UCX_TEST_ASSERT(c2 != NULL, "failed key 2 (clone)");
227 UCX_TEST_ASSERT(c3 != NULL, "failed key 3 (clone)");
228
229 UCX_TEST_ASSERT(strcmp(c1, v1) == 0, "value error for key1");
230 UCX_TEST_ASSERT(strcmp(c2, v2) == 0, "value error for key2");
231 UCX_TEST_ASSERT(strcmp(c3, v3) == 0, "value error for key3");
232
233 UCX_TEST_END
234
235 ucx_map_free(map);
236 ucx_map_free(clone);
237 }

mercurial