test/map_tests.c

changeset 42
ff3dd1ee7dee
parent 41
7f90a03e186e
child 43
02f38adea013
equal deleted inserted replaced
41:7f90a03e186e 42:ff3dd1ee7dee
134 UCX_TEST_BEGIN 134 UCX_TEST_BEGIN
135 UCX_TEST_CALL_SUBROUTINE(test_ucx_map_itersrt, map) 135 UCX_TEST_CALL_SUBROUTINE(test_ucx_map_itersrt, map)
136 UCX_TEST_END 136 UCX_TEST_END
137 ucx_map_free(map); 137 ucx_map_free(map);
138 } 138 }
139
140 UCX_TEST_IMPLEMENT(test_ucx_map_store_load) {
141 UcxMap *map = ucx_map_new(4);
142
143 ucx_map_cstr_put(map, "test", "test");
144 ucx_map_cstr_put(map, "key", "value");
145 ucx_map_cstr_put(map, "other.very.long.key", "value");
146 ucx_map_cstr_put(map, "testkey", "testvalue");
147 ucx_map_cstr_put(map, "simple", "not a key but an extremely long value "
148 "to test if the buffer extension works as designed");
149
150 FILE *f = fopen("test_ucx_map_store", "w");
151 int r;
152
153 fwrite(" # comment test", 1, 15, f);
154 r = ucx_map_store(map, f);
155 fwrite("#discard this", 1, 13, f);
156
157 fclose(f);
158 ucx_map_free(map);
159 map = ucx_map_new(1);
160 f = fopen("test_ucx_map_store", "r");
161 r += ucx_map_load(map, f);
162
163 UCX_TEST_BEGIN
164 char *value;
165 UCX_TEST_ASSERT(r == 0, "IO errors, test cannot be performed");
166
167 value = ucx_map_cstr_get(map, "test");
168 UCX_TEST_ASSERT(strcmp(value, "test") == 0, "value error for key: test");
169
170 value = ucx_map_cstr_get(map, "key");
171 UCX_TEST_ASSERT(strcmp(value, "value") == 0, "value error for key: key");
172
173 value = ucx_map_cstr_get(map, "other.very.long.key");
174 UCX_TEST_ASSERT(strcmp(value, "value") == 0,
175 "value error for key: other.very.long.key");
176
177 value = ucx_map_cstr_get(map, "testkey");
178 UCX_TEST_ASSERT(strcmp(value, "testvalue") == 0,
179 "value error for key: testkey");
180
181 value = ucx_map_cstr_get(map, "simple");
182 UCX_TEST_ASSERT(strcmp(value, "not a key but an extremely long value "
183 "to test if the buffer extension works as designed") == 0,
184 "value error for key: simple");
185
186 UCX_TEST_END
187 fclose(f);
188
189 unlink("test_ucx_map_store");
190 }

mercurial