test/map_tests.c

changeset 46
48ca036d7d9c
parent 44
46356d74e873
child 48
621a4430c404
equal deleted inserted replaced
45:dd03226c1a6b 46:48ca036d7d9c
139 UCX_TEST_CALL_SUBROUTINE(test_ucx_map_itersrt, map) 139 UCX_TEST_CALL_SUBROUTINE(test_ucx_map_itersrt, map)
140 UCX_TEST_END 140 UCX_TEST_END
141 ucx_map_free(map); 141 ucx_map_free(map);
142 } 142 }
143 143
144 void* test_ucx_map_store_load_encdec(void *value, void *data) {
145 char *string = (char*) value;
146 size_t n = strlen(string);
147 char *encoded = malloc(n+1);
148 for (int i = 0 ; i < n ; i++) {
149 encoded[i] = string[n-1-i];
150 }
151 encoded[n] = 0;
152 return encoded;
153 }
154
144 UCX_TEST_IMPLEMENT(test_ucx_map_store_load) { 155 UCX_TEST_IMPLEMENT(test_ucx_map_store_load) {
145 UcxMap *map = ucx_map_new(4); 156 UcxMap *map = ucx_map_new(4);
146 157
147 ucx_map_cstr_put(map, "test", "test"); 158 ucx_map_cstr_put(map, "test", "test");
148 ucx_map_cstr_put(map, "key", "value"); 159 ucx_map_cstr_put(map, "key", "value");
153 164
154 FILE *f = fopen("test_ucx_map_store", "w"); 165 FILE *f = fopen("test_ucx_map_store", "w");
155 int r; 166 int r;
156 167
157 fwrite(" # comment test\n", 1, 16, f); 168 fwrite(" # comment test\n", 1, 16, f);
158 r = ucx_map_store(map, f); 169 r = ucx_map_store_enc(map, f, test_ucx_map_store_load_encdec, NULL);
159 fwrite("!discard this", 1, 13, f); 170 fwrite("!discard this", 1, 13, f);
160 171
161 fclose(f); 172 fclose(f);
162 ucx_map_free(map); 173 ucx_map_free(map);
163 map = ucx_map_new(1); 174 map = ucx_map_new(1);
164 f = fopen("test_ucx_map_store", "r"); 175 f = fopen("test_ucx_map_store", "r");
165 r += ucx_map_load(map, f); 176 r += ucx_map_load_enc(map, f, test_ucx_map_store_load_encdec, NULL);
166 177
167 UCX_TEST_BEGIN 178 UCX_TEST_BEGIN
168 char *value; 179 char *value;
169 UCX_TEST_ASSERT(r == 0, "IO errors, test cannot be performed"); 180 UCX_TEST_ASSERT(r == 0, "IO errors, test cannot be performed");
170 181

mercurial