test/map_tests.c

changeset 42
ff3dd1ee7dee
parent 41
7f90a03e186e
child 43
02f38adea013
     1.1 --- a/test/map_tests.c	Thu Oct 04 14:08:31 2012 +0200
     1.2 +++ b/test/map_tests.c	Thu Oct 04 16:03:18 2012 +0200
     1.3 @@ -136,3 +136,55 @@
     1.4      UCX_TEST_END
     1.5      ucx_map_free(map);
     1.6  }
     1.7 +
     1.8 +UCX_TEST_IMPLEMENT(test_ucx_map_store_load) {
     1.9 +    UcxMap *map = ucx_map_new(4);
    1.10 +
    1.11 +    ucx_map_cstr_put(map, "test", "test");
    1.12 +    ucx_map_cstr_put(map, "key", "value");
    1.13 +    ucx_map_cstr_put(map, "other.very.long.key", "value");
    1.14 +    ucx_map_cstr_put(map, "testkey", "testvalue");
    1.15 +    ucx_map_cstr_put(map, "simple", "not a key but an extremely long value "
    1.16 +            "to test if the buffer extension works as designed");
    1.17 +
    1.18 +    FILE *f = fopen("test_ucx_map_store", "w");
    1.19 +    int r;
    1.20 +
    1.21 +    fwrite(" # comment test", 1, 15, f);
    1.22 +    r = ucx_map_store(map, f);
    1.23 +    fwrite("#discard this", 1, 13, f);
    1.24 +
    1.25 +    fclose(f);
    1.26 +    ucx_map_free(map);
    1.27 +    map = ucx_map_new(1);
    1.28 +    f = fopen("test_ucx_map_store", "r");
    1.29 +    r += ucx_map_load(map, f);
    1.30 +
    1.31 +    UCX_TEST_BEGIN
    1.32 +    char *value;
    1.33 +    UCX_TEST_ASSERT(r == 0, "IO errors, test cannot be performed");
    1.34 +
    1.35 +    value = ucx_map_cstr_get(map, "test");
    1.36 +    UCX_TEST_ASSERT(strcmp(value, "test") == 0, "value error for key: test");
    1.37 +
    1.38 +    value = ucx_map_cstr_get(map, "key");
    1.39 +    UCX_TEST_ASSERT(strcmp(value, "value") == 0, "value error for key: key");
    1.40 +
    1.41 +    value = ucx_map_cstr_get(map, "other.very.long.key");
    1.42 +    UCX_TEST_ASSERT(strcmp(value, "value") == 0,
    1.43 +            "value error for key: other.very.long.key");
    1.44 +
    1.45 +    value = ucx_map_cstr_get(map, "testkey");
    1.46 +    UCX_TEST_ASSERT(strcmp(value, "testvalue") == 0,
    1.47 +            "value error for key: testkey");
    1.48 +
    1.49 +    value = ucx_map_cstr_get(map, "simple");
    1.50 +    UCX_TEST_ASSERT(strcmp(value, "not a key but an extremely long value "
    1.51 +            "to test if the buffer extension works as designed") == 0,
    1.52 +            "value error for key: simple");
    1.53 +
    1.54 +    UCX_TEST_END
    1.55 +    fclose(f);
    1.56 +
    1.57 +    unlink("test_ucx_map_store");
    1.58 +}

mercurial