test/map_tests.c

changeset 112
6384016df2a3
parent 111
c8c59d7f4536
child 134
4d320dc3a7af
     1.1 --- a/test/map_tests.c	Mon Jul 15 14:25:50 2013 +0200
     1.2 +++ b/test/map_tests.c	Mon Jul 15 15:43:18 2013 +0200
     1.3 @@ -204,121 +204,6 @@
     1.4      ucx_map_free(map);
     1.5  }
     1.6  
     1.7 -void* test_ucx_map_store_load_encdec(void *value, void *data, size_t *size) {
     1.8 -    const char *string = (const char*) value;
     1.9 -    size_t n = strlen(string);
    1.10 -    char *encoded = (char*) malloc(n+1);
    1.11 -    for (size_t i = 0 ; i < n ; i++) {
    1.12 -        encoded[i] = string[n-1-i];
    1.13 -    }
    1.14 -    encoded[n] = 0;
    1.15 -    *size = n+1;
    1.16 -    return encoded;
    1.17 -}
    1.18 -
    1.19 -UCX_TEST_IMPLEMENT(test_ucx_map_store_load) {
    1.20 -    UcxMap *map = ucx_map_new(4);
    1.21 -
    1.22 -    ucx_map_cstr_put(map, "test", (void*)"test");
    1.23 -    ucx_map_cstr_put(map, "key", (void*)"value");
    1.24 -    ucx_map_cstr_put(map, "other.very.long.key", (void*)"value");
    1.25 -    ucx_map_cstr_put(map, "testkey", (void*)"testvalue");
    1.26 -    ucx_map_cstr_put(map, "simple", (void*)"not a key but an extremely long "
    1.27 -            "value to test if the buffer extension works as designed");
    1.28 -
    1.29 -    UCX_TEST_BEGIN
    1.30 -    FILE *f = tmpfile();
    1.31 -    UCX_TEST_ASSERT(f, "test file cannot be opened, test aborted")
    1.32 -    int r;
    1.33 -
    1.34 -    fwrite(" # comment test\n", 1, 16, f);
    1.35 -    r = ucx_map_store_enc(map, f, test_ucx_map_store_load_encdec, NULL);
    1.36 -    fwrite("!discard this", 1, 13, f);
    1.37 -    fflush(f);
    1.38 -
    1.39 -    ucx_map_free(map);
    1.40 -    map = ucx_map_new(1);
    1.41 -    fseek(f, 0, SEEK_SET);
    1.42 -    UcxAllocator allocator = UCX_ALLOCATOR_DEFAULT;
    1.43 -    r += ucx_map_load_enc(map, f, allocator,
    1.44 -            test_ucx_map_store_load_encdec, NULL);
    1.45 -    fclose(f);
    1.46 -
    1.47 -    const char *value;
    1.48 -    UCX_TEST_ASSERT(r == 0, "IO errors, test cannot be performed");
    1.49 -
    1.50 -    value = (const char *) ucx_map_cstr_get(map, "test");
    1.51 -    UCX_TEST_ASSERT(value != NULL, "value not found for key: test");
    1.52 -    UCX_TEST_ASSERT(strcmp(value, "test") == 0, "value error for key: test");
    1.53 -
    1.54 -    value = (const char *) ucx_map_cstr_get(map, "key");
    1.55 -    UCX_TEST_ASSERT(value != NULL, "value not found for key: key");
    1.56 -    UCX_TEST_ASSERT(strcmp(value, "value") == 0, "value error for key: key");
    1.57 -
    1.58 -    value = (const char *) ucx_map_cstr_get(map, "other.very.long.key");
    1.59 -    UCX_TEST_ASSERT(value != NULL,
    1.60 -            "value not found for key: other.very.long.key");
    1.61 -    UCX_TEST_ASSERT(strcmp(value, "value") == 0,
    1.62 -            "value error for key: other.very.long.key");
    1.63 -
    1.64 -    value = (const char *) ucx_map_cstr_get(map, "testkey");
    1.65 -    UCX_TEST_ASSERT(value != NULL, "value not found for key: testkey");
    1.66 -    UCX_TEST_ASSERT(strcmp(value, "testvalue") == 0,
    1.67 -            "value error for key: testkey");
    1.68 -
    1.69 -    value = (const char *) ucx_map_cstr_get(map, "simple");
    1.70 -    UCX_TEST_ASSERT(value != NULL, "value not found for key: simple");
    1.71 -    UCX_TEST_ASSERT(strcmp(value, "not a key but an extremely long value "
    1.72 -            "to test if the buffer extension works as designed") == 0,
    1.73 -            "value error for key: simple");
    1.74 -
    1.75 -    void *d;
    1.76 -    UcxMapIterator iter = ucx_map_iterator(map);
    1.77 -    UCX_MAP_FOREACH(key, d, iter) {
    1.78 -        free(d);
    1.79 -    }
    1.80 -    ucx_map_free(map);
    1.81 -    UCX_TEST_END
    1.82 -}
    1.83 -
    1.84 -UCX_TEST_IMPLEMENT(test_ucx_map_store_load_with_mempool) {
    1.85 -    UcxMap *map = ucx_map_new(4);
    1.86 -
    1.87 -    ucx_map_cstr_put(map, "test", (void*)"test");
    1.88 -    ucx_map_cstr_put(map, "key", (void*)"value");
    1.89 -    ucx_map_cstr_put(map, "testkey", (void*)"testvalue");
    1.90 -    ucx_map_cstr_put(map, "simple", (void*)"a simple value");
    1.91 -
    1.92 -    UCX_TEST_BEGIN
    1.93 -    FILE *f = tmpfile();
    1.94 -    UCX_TEST_ASSERT(f, "test file cannot be opened, test aborted");
    1.95 -    int r;
    1.96 -    r = ucx_map_store_enc(map, f, NULL, NULL);
    1.97 -    ucx_map_free(map);
    1.98 -    fflush(f);
    1.99 -
   1.100 -    UcxMempool *pool = ucx_mempool_new(4);
   1.101 -    map = ucx_map_new(4);
   1.102 -    fseek(f, 0, SEEK_SET);
   1.103 -    UcxAllocator allocator = UCX_ALLOCATOR_MEMPOOL(pool);
   1.104 -    r += ucx_map_load_enc(map, f, allocator,
   1.105 -            test_ucx_map_store_load_encdec, NULL);
   1.106 -    fclose(f);
   1.107 -
   1.108 -    UCX_TEST_ASSERT(r == 0, "IO errors, test cannot be performed");
   1.109 -    UcxMapIterator iter = ucx_map_iterator(map);
   1.110 -    const char *value; size_t n;
   1.111 -    UCX_MAP_FOREACH(key, value, iter) {
   1.112 -        n = strlen(value);
   1.113 -        UCX_TEST_ASSERT(strncmp((const char*) pool->data[iter.index], value, n),
   1.114 -                "values of map does not match pooled values");
   1.115 -    }
   1.116 -
   1.117 -    ucx_mempool_free(pool);
   1.118 -    ucx_map_free(map);
   1.119 -    UCX_TEST_END
   1.120 -}
   1.121 -
   1.122  UCX_TEST_IMPLEMENT(test_ucx_map_clone) {
   1.123      UcxMap *map = ucx_map_new(4);
   1.124      

mercurial