diff -r 7f90a03e186e -r ff3dd1ee7dee test/map_tests.c --- a/test/map_tests.c Thu Oct 04 14:08:31 2012 +0200 +++ b/test/map_tests.c Thu Oct 04 16:03:18 2012 +0200 @@ -136,3 +136,55 @@ UCX_TEST_END ucx_map_free(map); } + +UCX_TEST_IMPLEMENT(test_ucx_map_store_load) { + UcxMap *map = ucx_map_new(4); + + ucx_map_cstr_put(map, "test", "test"); + ucx_map_cstr_put(map, "key", "value"); + ucx_map_cstr_put(map, "other.very.long.key", "value"); + ucx_map_cstr_put(map, "testkey", "testvalue"); + ucx_map_cstr_put(map, "simple", "not a key but an extremely long value " + "to test if the buffer extension works as designed"); + + FILE *f = fopen("test_ucx_map_store", "w"); + int r; + + fwrite(" # comment test", 1, 15, f); + r = ucx_map_store(map, f); + fwrite("#discard this", 1, 13, f); + + fclose(f); + ucx_map_free(map); + map = ucx_map_new(1); + f = fopen("test_ucx_map_store", "r"); + r += ucx_map_load(map, f); + + UCX_TEST_BEGIN + char *value; + UCX_TEST_ASSERT(r == 0, "IO errors, test cannot be performed"); + + value = ucx_map_cstr_get(map, "test"); + UCX_TEST_ASSERT(strcmp(value, "test") == 0, "value error for key: test"); + + value = ucx_map_cstr_get(map, "key"); + UCX_TEST_ASSERT(strcmp(value, "value") == 0, "value error for key: key"); + + value = ucx_map_cstr_get(map, "other.very.long.key"); + UCX_TEST_ASSERT(strcmp(value, "value") == 0, + "value error for key: other.very.long.key"); + + value = ucx_map_cstr_get(map, "testkey"); + UCX_TEST_ASSERT(strcmp(value, "testvalue") == 0, + "value error for key: testkey"); + + value = ucx_map_cstr_get(map, "simple"); + UCX_TEST_ASSERT(strcmp(value, "not a key but an extremely long value " + "to test if the buffer extension works as designed") == 0, + "value error for key: simple"); + + UCX_TEST_END + fclose(f); + + unlink("test_ucx_map_store"); +}