test/prop_tests.c

changeset 110
1cf71e56f01e
parent 109
75cb6590358b
child 134
4d320dc3a7af
equal deleted inserted replaced
109:75cb6590358b 110:1cf71e56f01e
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "prop_tests.h" 29 #include "prop_tests.h"
30 30
31 UCX_TEST_IMPLEMENT(test_ucx_prop_new) { 31 UCX_TEST_IMPLEMENT(test_ucx_properties_new) {
32 UcxPropParser *parser = ucx_prop_new(); 32 UcxProperties *parser = ucx_properties_new();
33 33
34 UCX_TEST_BEGIN 34 UCX_TEST_BEGIN
35 35
36 UCX_TEST_ASSERT(parser != NULL, "failed"); 36 UCX_TEST_ASSERT(parser != NULL, "failed");
37 UCX_TEST_ASSERT(parser->buffer == NULL, "parser has buffer"); 37 UCX_TEST_ASSERT(parser->buffer == NULL, "parser has buffer");
38 UCX_TEST_ASSERT(parser->tmp == NULL, "parser has tmp buffer"); 38 UCX_TEST_ASSERT(parser->tmp == NULL, "parser has tmp buffer");
39 39
40 UCX_TEST_END 40 UCX_TEST_END
41 41
42 ucx_prop_free(parser); 42 ucx_properties_free(parser);
43 } 43 }
44 44
45 UCX_TEST_IMPLEMENT(test_ucx_prop_parse) { 45 UCX_TEST_IMPLEMENT(test_ucx_properties_next) {
46 const char *tests[] = { 46 const char *tests[] = {
47 "name = value\n", 47 "name = value\n",
48 "name=value\n", 48 "name=value\n",
49 "n=value\n", 49 "n=value\n",
50 "name=v\n", 50 "name=v\n",
86 86
87 sstr_t name; 87 sstr_t name;
88 sstr_t value; 88 sstr_t value;
89 89
90 for(int i=0;i<10;i++) { 90 for(int i=0;i<10;i++) {
91 UcxPropParser *parser = ucx_prop_new(); 91 UcxProperties *parser = ucx_properties_new();
92 92
93 ucx_prop_fill(parser, (char*)tests[i], strlen(tests[i])); 93 ucx_properties_fill(parser, (char*)tests[i], strlen(tests[i]));
94 UCX_TEST_ASSERT(parser->buffer == tests[i], "fill failed"); 94 UCX_TEST_ASSERT(parser->buffer == tests[i], "fill failed");
95 UCX_TEST_ASSERT(parser->buflen == strlen(tests[i]), "wrong buflen"); 95 UCX_TEST_ASSERT(parser->buflen == strlen(tests[i]), "wrong buflen");
96 96
97 int r = ucx_prop_parse(parser, &name, &value); 97 int r = ucx_properties_next(parser, &name, &value);
98 sstr_t n = sstr((char*)names[i]); 98 sstr_t n = sstr((char*)names[i]);
99 sstr_t v = sstr((char*)values[i]); 99 sstr_t v = sstr((char*)values[i]);
100 UCX_TEST_ASSERT(r == 1, "parse returned 0"); 100 UCX_TEST_ASSERT(r == 1, "next returned 0");
101 UCX_TEST_ASSERT((!sstrcmp(name, n)), "wrong property name"); 101 UCX_TEST_ASSERT((!sstrcmp(name, n)), "wrong property name");
102 UCX_TEST_ASSERT((!sstrcmp(value, v)), "wrong property value"); 102 UCX_TEST_ASSERT((!sstrcmp(value, v)), "wrong property value");
103 103
104 r = ucx_prop_parse(parser, &name, &value); 104 r = ucx_properties_next(parser, &name, &value);
105 UCX_TEST_ASSERT(r == 0, "parse returned 1"); 105 UCX_TEST_ASSERT(r == 0, "next returned 1");
106 UCX_TEST_ASSERT(parser->tmp == NULL, "tmp not NULL"); 106 UCX_TEST_ASSERT(parser->tmp == NULL, "tmp not NULL");
107 UCX_TEST_ASSERT(parser->tmpcap == 0, "tmpcap not NULL"); 107 UCX_TEST_ASSERT(parser->tmpcap == 0, "tmpcap not NULL");
108 UCX_TEST_ASSERT(parser->tmplen == 0, "tmplen not NULL"); 108 UCX_TEST_ASSERT(parser->tmplen == 0, "tmplen not NULL");
109 109
110 ucx_prop_free(parser); 110 ucx_properties_free(parser);
111 } 111 }
112 112
113 UCX_TEST_END 113 UCX_TEST_END
114 } 114 }
115 115
116 UCX_TEST_IMPLEMENT(test_ucx_prop_parse_multi) { 116 UCX_TEST_IMPLEMENT(test_ucx_properties_next_multi) {
117 const char *names[] = { 117 const char *names[] = {
118 "a", 118 "a",
119 "b", 119 "b",
120 "c", 120 "c",
121 "uap", 121 "uap",
151 "#key1 = wrong value\n" 151 "#key1 = wrong value\n"
152 "#key2 = not value 2\n" 152 "#key2 = not value 2\n"
153 "key2 = value2\n" 153 "key2 = value2\n"
154 "\n\n\n \n key3=value3\n"; 154 "\n\n\n \n key3=value3\n";
155 155
156 UcxPropParser *parser = ucx_prop_new(); 156 UcxProperties *parser = ucx_properties_new();
157 157
158 UCX_TEST_BEGIN 158 UCX_TEST_BEGIN
159 159
160 ucx_prop_fill(parser, (char*)str, strlen(str)); 160 ucx_properties_fill(parser, (char*)str, strlen(str));
161 161
162 sstr_t name; 162 sstr_t name;
163 sstr_t value; 163 sstr_t value;
164 for(int i=0;i<8;i++) { 164 for(int i=0;i<8;i++) {
165 int r = ucx_prop_parse(parser, &name, &value); 165 int r = ucx_properties_next(parser, &name, &value);
166 UCX_TEST_ASSERT(r == 1, "parse returned 0"); 166 UCX_TEST_ASSERT(r == 1, "next returned 0");
167 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)names[i]))), "wrong name"); 167 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)names[i]))), "wrong name");
168 UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)values[i]))), 168 UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)values[i]))),
169 "wrong value"); 169 "wrong value");
170 } 170 }
171 int r = ucx_prop_parse(parser, &name, &value); 171 int r = ucx_properties_next(parser, &name, &value);
172 UCX_TEST_ASSERT(r == 0, "parse returned 1"); 172 UCX_TEST_ASSERT(r == 0, "next returned 1");
173 173
174 UCX_TEST_END 174 UCX_TEST_END
175 175
176 ucx_prop_free(parser); 176 ucx_properties_free(parser);
177 } 177 }
178 178
179 UCX_TEST_IMPLEMENT(test_ucx_prop_parse_part) { 179 UCX_TEST_IMPLEMENT(test_ucx_properties_next_part) {
180 UcxPropParser *parser = ucx_prop_new(); 180 UcxProperties *parser = ucx_properties_new();
181 const char *str; 181 const char *str;
182 int r; 182 int r;
183 sstr_t name; 183 sstr_t name;
184 sstr_t value; 184 sstr_t value;
185 185
186 UCX_TEST_BEGIN 186 UCX_TEST_BEGIN
187 187
188 str = ""; 188 str = "";
189 ucx_prop_fill(parser, (char*)str, strlen(str)); 189 ucx_properties_fill(parser, (char*)str, strlen(str));
190 r = ucx_prop_parse(parser, &name, &value); 190 r = ucx_properties_next(parser, &name, &value);
191 UCX_TEST_ASSERT(r == 0, "parse returned 1"); 191 UCX_TEST_ASSERT(r == 0, "next returned 1");
192 192
193 str = " \n"; 193 str = " \n";
194 ucx_prop_fill(parser, (char*)str, strlen(str)); 194 ucx_properties_fill(parser, (char*)str, strlen(str));
195 r = ucx_prop_parse(parser, &name, &value); 195 r = ucx_properties_next(parser, &name, &value);
196 UCX_TEST_ASSERT(r == 0, "parse returned 1"); 196 UCX_TEST_ASSERT(r == 0, "next returned 1");
197 197
198 str = "name"; 198 str = "name";
199 ucx_prop_fill(parser, (char*)str, strlen(str)); 199 ucx_properties_fill(parser, (char*)str, strlen(str));
200 r = ucx_prop_parse(parser, &name, &value); 200 r = ucx_properties_next(parser, &name, &value);
201 UCX_TEST_ASSERT(r == 0, "parse returned 1"); 201 UCX_TEST_ASSERT(r == 0, "next returned 1");
202 202
203 str = " "; 203 str = " ";
204 ucx_prop_fill(parser, (char*)str, strlen(str)); 204 ucx_properties_fill(parser, (char*)str, strlen(str));
205 r = ucx_prop_parse(parser, &name, &value); 205 r = ucx_properties_next(parser, &name, &value);
206 UCX_TEST_ASSERT(r == 0, "parse returned 1"); 206 UCX_TEST_ASSERT(r == 0, "next returned 1");
207 207
208 str = "= "; 208 str = "= ";
209 ucx_prop_fill(parser, (char*)str, strlen(str)); 209 ucx_properties_fill(parser, (char*)str, strlen(str));
210 r = ucx_prop_parse(parser, &name, &value); 210 r = ucx_properties_next(parser, &name, &value);
211 UCX_TEST_ASSERT(r == 0, "parse returned 1"); 211 UCX_TEST_ASSERT(r == 0, "next returned 1");
212 212
213 str = "value"; 213 str = "value";
214 ucx_prop_fill(parser, (char*)str, strlen(str)); 214 ucx_properties_fill(parser, (char*)str, strlen(str));
215 r = ucx_prop_parse(parser, &name, &value); 215 r = ucx_properties_next(parser, &name, &value);
216 UCX_TEST_ASSERT(r == 0, "parse returned 1"); 216 UCX_TEST_ASSERT(r == 0, "next returned 1");
217 217
218 str = "\n"; 218 str = "\n";
219 ucx_prop_fill(parser, (char*)str, strlen(str)); 219 ucx_properties_fill(parser, (char*)str, strlen(str));
220 r = ucx_prop_parse(parser, &name, &value); 220 r = ucx_properties_next(parser, &name, &value);
221 UCX_TEST_ASSERT(r == 1, "parse returned 0"); 221 UCX_TEST_ASSERT(r == 1, "next returned 0");
222 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"name"))), "wrong name"); 222 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"name"))), "wrong name");
223 UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"value"))), "wrong value"); 223 UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"value"))), "wrong value");
224 224
225 // second round 225 // second round
226 str = "#comment\n"; 226 str = "#comment\n";
227 ucx_prop_fill(parser, (char*)str, strlen(str)); 227 ucx_properties_fill(parser, (char*)str, strlen(str));
228 r = ucx_prop_parse(parser, &name, &value); 228 r = ucx_properties_next(parser, &name, &value);
229 UCX_TEST_ASSERT(r == 0, "parse returned 1"); 229 UCX_TEST_ASSERT(r == 0, "next returned 1");
230 230
231 str = "#comment\nname = "; 231 str = "#comment\nname = ";
232 ucx_prop_fill(parser, (char*)str, strlen(str)); 232 ucx_properties_fill(parser, (char*)str, strlen(str));
233 r = ucx_prop_parse(parser, &name, &value); 233 r = ucx_properties_next(parser, &name, &value);
234 UCX_TEST_ASSERT(r == 0, "parse returned 1"); 234 UCX_TEST_ASSERT(r == 0, "next returned 1");
235 235
236 str = "value\na = b\n"; 236 str = "value\na = b\n";
237 ucx_prop_fill(parser, (char*)str, strlen(str)); 237 ucx_properties_fill(parser, (char*)str, strlen(str));
238 r = ucx_prop_parse(parser, &name, &value); 238 r = ucx_properties_next(parser, &name, &value);
239 UCX_TEST_ASSERT(r == 1, "parse returned 0"); 239 UCX_TEST_ASSERT(r == 1, "next returned 0");
240 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"name"))), "wrong name"); 240 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"name"))), "wrong name");
241 UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"value"))), "wrong value"); 241 UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"value"))), "wrong value");
242 242
243 r = ucx_prop_parse(parser, &name, &value); 243 r = ucx_properties_next(parser, &name, &value);
244 UCX_TEST_ASSERT(r == 1, "parse returned 0"); 244 UCX_TEST_ASSERT(r == 1, "next returned 0");
245 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"a"))), "wrong name"); 245 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"a"))), "wrong name");
246 UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"b"))), "wrong value"); 246 UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"b"))), "wrong value");
247 247
248 str = "# comment\n#\n#\ntests = "; 248 str = "# comment\n#\n#\ntests = ";
249 ucx_prop_fill(parser, (char*)str, strlen(str)); 249 ucx_properties_fill(parser, (char*)str, strlen(str));
250 r = ucx_prop_parse(parser, &name, &value); 250 r = ucx_properties_next(parser, &name, &value);
251 UCX_TEST_ASSERT(r == 0, "parse returned 1"); 251 UCX_TEST_ASSERT(r == 0, "next returned 1");
252 252
253 str = "test1 "; 253 str = "test1 ";
254 ucx_prop_fill(parser, (char*)str, strlen(str)); 254 ucx_properties_fill(parser, (char*)str, strlen(str));
255 r = ucx_prop_parse(parser, &name, &value); 255 r = ucx_properties_next(parser, &name, &value);
256 UCX_TEST_ASSERT(r == 0, "parse returned 1"); 256 UCX_TEST_ASSERT(r == 0, "next returned 1");
257 257
258 str = "test2 test3 test4\n"; 258 str = "test2 test3 test4\n";
259 sstr_t testv = sstr((char*)"test1 test2 test3 test4"); 259 sstr_t testv = sstr((char*)"test1 test2 test3 test4");
260 ucx_prop_fill(parser, (char*)str, strlen(str)); 260 ucx_properties_fill(parser, (char*)str, strlen(str));
261 r = ucx_prop_parse(parser, &name, &value); 261 r = ucx_properties_next(parser, &name, &value);
262 UCX_TEST_ASSERT(r == 1, "parse returned 0"); 262 UCX_TEST_ASSERT(r == 1, "next returned 0");
263 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"tests"))), "wrong name"); 263 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"tests"))), "wrong name");
264 UCX_TEST_ASSERT((!sstrcmp(value, testv)), "wrong value"); 264 UCX_TEST_ASSERT((!sstrcmp(value, testv)), "wrong value");
265 265
266 // test if parse finds a name/value after a tmp comment 266 // test if ucx_properties_next finds a name/value after a tmp comment
267 str = "# just a comment"; 267 str = "# just a comment";
268 ucx_prop_fill(parser, (char*)str, strlen(str)); 268 ucx_properties_fill(parser, (char*)str, strlen(str));
269 r = ucx_prop_parse(parser, &name, &value); 269 r = ucx_properties_next(parser, &name, &value);
270 UCX_TEST_ASSERT(r == 0, "parse returned 1"); 270 UCX_TEST_ASSERT(r == 0, "next returned 1");
271 271
272 str = " in 3"; 272 str = " in 3";
273 ucx_prop_fill(parser, (char*)str, strlen(str)); 273 ucx_properties_fill(parser, (char*)str, strlen(str));
274 r = ucx_prop_parse(parser, &name, &value); 274 r = ucx_properties_next(parser, &name, &value);
275 UCX_TEST_ASSERT(r == 0, "parse returned 1"); 275 UCX_TEST_ASSERT(r == 0, "next returned 1");
276 276
277 str = " parts\na = 1\n"; 277 str = " parts\na = 1\n";
278 ucx_prop_fill(parser, (char*)str, strlen(str)); 278 ucx_properties_fill(parser, (char*)str, strlen(str));
279 r = ucx_prop_parse(parser, &name, &value); 279 r = ucx_properties_next(parser, &name, &value);
280 UCX_TEST_ASSERT(r == 1, "parse returned 0"); 280 UCX_TEST_ASSERT(r == 1, "next returned 0");
281 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"a"))), "wrong name"); 281 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"a"))), "wrong name");
282 UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"1"))), "wrong value"); 282 UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"1"))), "wrong value");
283 283
284 UCX_TEST_END 284 UCX_TEST_END
285 285
286 ucx_prop_free(parser); 286 ucx_properties_free(parser);
287 } 287 }
288 288
289 UCX_TEST_IMPLEMENT(test_ucx_prop_parse_long) { 289 UCX_TEST_IMPLEMENT(test_ucx_properties_next_long) {
290 UcxPropParser *parser = ucx_prop_new(); 290 UcxProperties *parser = ucx_properties_new();
291 int r; 291 int r;
292 size_t name_len = 512; 292 size_t name_len = 512;
293 char *long_name = (char*)malloc(name_len); 293 char *long_name = (char*)malloc(name_len);
294 memset(long_name, 'a', 70); 294 memset(long_name, 'a', 70);
295 memset(long_name+70, 'b', 242); 295 memset(long_name+70, 'b', 242);
303 UCX_TEST_BEGIN 303 UCX_TEST_BEGIN
304 304
305 sstr_t name; 305 sstr_t name;
306 sstr_t value; 306 sstr_t value;
307 307
308 ucx_prop_fill(parser, long_name, 10); 308 ucx_properties_fill(parser, long_name, 10);
309 r = ucx_prop_parse(parser, &name, &value); 309 r = ucx_properties_next(parser, &name, &value);
310 UCX_TEST_ASSERT(r == 0, "parse returned 1"); 310 UCX_TEST_ASSERT(r == 0, "next returned 1");
311 311
312 ucx_prop_fill(parser, long_name+10, 202); 312 ucx_properties_fill(parser, long_name+10, 202);
313 r = ucx_prop_parse(parser, &name, &value); 313 r = ucx_properties_next(parser, &name, &value);
314 UCX_TEST_ASSERT(r == 0, "parse returned 1"); 314 UCX_TEST_ASSERT(r == 0, "next returned 1");
315 315
316 ucx_prop_fill(parser, long_name+212, 200); 316 ucx_properties_fill(parser, long_name+212, 200);
317 r = ucx_prop_parse(parser, &name, &value); 317 r = ucx_properties_next(parser, &name, &value);
318 UCX_TEST_ASSERT(r == 0, "parse returned 1"); 318 UCX_TEST_ASSERT(r == 0, "next returned 1");
319 319
320 ucx_prop_fill(parser, long_name+412, 100); 320 ucx_properties_fill(parser, long_name+412, 100);
321 r = ucx_prop_parse(parser, &name, &value); 321 r = ucx_properties_next(parser, &name, &value);
322 UCX_TEST_ASSERT(r == 0, "parse returned 1"); 322 UCX_TEST_ASSERT(r == 0, "next returned 1");
323 323
324 const char *str = " = "; 324 const char *str = " = ";
325 ucx_prop_fill(parser, (char*)str, strlen(str)); 325 ucx_properties_fill(parser, (char*)str, strlen(str));
326 r = ucx_prop_parse(parser, &name, &value); 326 r = ucx_properties_next(parser, &name, &value);
327 UCX_TEST_ASSERT(r == 0, "parse returned 1"); 327 UCX_TEST_ASSERT(r == 0, "next returned 1");
328 328
329 ucx_prop_fill(parser, long_value, 512); 329 ucx_properties_fill(parser, long_value, 512);
330 r = ucx_prop_parse(parser, &name, &value); 330 r = ucx_properties_next(parser, &name, &value);
331 UCX_TEST_ASSERT(r == 0, "parse returned 1"); 331 UCX_TEST_ASSERT(r == 0, "next returned 1");
332 332
333 ucx_prop_fill(parser, long_value+512, 1024); 333 ucx_properties_fill(parser, long_value+512, 1024);
334 r = ucx_prop_parse(parser, &name, &value); 334 r = ucx_properties_next(parser, &name, &value);
335 UCX_TEST_ASSERT(r == 0, "parse returned 1"); 335 UCX_TEST_ASSERT(r == 0, "next returned 1");
336 336
337 ucx_prop_fill(parser, long_value+1536, 512); 337 ucx_properties_fill(parser, long_value+1536, 512);
338 r = ucx_prop_parse(parser, &name, &value); 338 r = ucx_properties_next(parser, &name, &value);
339 UCX_TEST_ASSERT(r == 0, "parse returned 1"); 339 UCX_TEST_ASSERT(r == 0, "next returned 1");
340 340
341 str = "\n#comment\nkey = value\n"; 341 str = "\n#comment\nkey = value\n";
342 ucx_prop_fill(parser, (char*)str, strlen(str)); 342 ucx_properties_fill(parser, (char*)str, strlen(str));
343 r = ucx_prop_parse(parser, &name, &value); 343 r = ucx_properties_next(parser, &name, &value);
344 sstr_t n = sstrn(long_name, name_len); 344 sstr_t n = sstrn(long_name, name_len);
345 sstr_t v = sstrn(long_value, value_len); 345 sstr_t v = sstrn(long_value, value_len);
346 UCX_TEST_ASSERT(r == 1, "parse returned 0"); 346 UCX_TEST_ASSERT(r == 1, "next returned 0");
347 UCX_TEST_ASSERT((!sstrcmp(name, n)), "wrong name"); 347 UCX_TEST_ASSERT((!sstrcmp(name, n)), "wrong name");
348 UCX_TEST_ASSERT((!sstrcmp(value, v)), "wrong value"); 348 UCX_TEST_ASSERT((!sstrcmp(value, v)), "wrong value");
349 349
350 r = ucx_prop_parse(parser, &name, &value); 350 r = ucx_properties_next(parser, &name, &value);
351 UCX_TEST_ASSERT(r == 1, "parse returned 0"); 351 UCX_TEST_ASSERT(r == 1, "next returned 0");
352 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"key"))), "wrong name"); 352 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"key"))), "wrong name");
353 UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"value"))), "wrong value"); 353 UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"value"))), "wrong value");
354 354
355 r = ucx_prop_parse(parser, &name, &value); 355 r = ucx_properties_next(parser, &name, &value);
356 UCX_TEST_ASSERT(r == 0, "parse returned 1"); 356 UCX_TEST_ASSERT(r == 0, "next returned 1");
357 357
358 UCX_TEST_END 358 UCX_TEST_END
359 359
360 free(long_name); 360 free(long_name);
361 free(long_value); 361 free(long_value);
362 ucx_prop_free(parser); 362 ucx_properties_free(parser);
363 } 363 }
364 364
365 UCX_TEST_IMPLEMENT(test_ucx_prop_parse2map) { 365 UCX_TEST_IMPLEMENT(test_ucx_properties2map) {
366 UcxMap *map = ucx_map_new(16); 366 UcxMap *map = ucx_map_new(16);
367 UcxPropParser *parser = ucx_prop_new(); 367 UcxProperties *parser = ucx_properties_new();
368 368
369 UCX_TEST_BEGIN 369 UCX_TEST_BEGIN
370 370
371 const char *str = "key1 = value1\nkey2 = value2\n\n#comment\n\nkey3 = value3\n"; 371 const char *str = "key1 = value1\nkey2 = value2\n\n#comment\n\nkey3 = value3\n";
372 ucx_prop_fill(parser, (char*)str, strlen(str)); 372 ucx_properties_fill(parser, (char*)str, strlen(str));
373 373
374 int r = ucx_prop_parse2map(parser, map); 374 int r = ucx_properties2map(parser, map);
375 375
376 UCX_TEST_ASSERT(r == 0, "parse2map failed"); 376 UCX_TEST_ASSERT(r == 0, "properties2map failed");
377 UCX_TEST_ASSERT(map->count == 3, "wrong number of properties"); 377 UCX_TEST_ASSERT(map->count == 3, "wrong number of properties");
378 378
379 char *v1 = (char*)ucx_map_cstr_get(map, "key1"); 379 char *v1 = (char*)ucx_map_cstr_get(map, "key1");
380 char *v2 = (char*)ucx_map_cstr_get(map, "key2"); 380 char *v2 = (char*)ucx_map_cstr_get(map, "key2");
381 char *v3 = (char*)ucx_map_cstr_get(map, "key3"); 381 char *v3 = (char*)ucx_map_cstr_get(map, "key3");
394 free(v2); 394 free(v2);
395 free(v3); 395 free(v3);
396 map = ucx_map_new(16); 396 map = ucx_map_new(16);
397 397
398 str = "\n#comment\n"; 398 str = "\n#comment\n";
399 ucx_prop_fill(parser, (char*)str, strlen(str)); 399 ucx_properties_fill(parser, (char*)str, strlen(str));
400 400
401 r = ucx_prop_parse2map(parser, map); 401 r = ucx_properties2map(parser, map);
402 UCX_TEST_ASSERT(r == 0, "parse2map failed"); 402 UCX_TEST_ASSERT(r == 0, "properties2map failed");
403 UCX_TEST_ASSERT(map->count == 0, "wrong number of properties"); 403 UCX_TEST_ASSERT(map->count == 0, "wrong number of properties");
404 404
405 str = "key1 = value1\nsyntax error line\n"; 405 str = "key1 = value1\nsyntax error line\n";
406 ucx_prop_fill(parser, (char*)str, strlen(str)); 406 ucx_properties_fill(parser, (char*)str, strlen(str));
407 407
408 r = ucx_prop_parse2map(parser, map); 408 r = ucx_properties2map(parser, map);
409 UCX_TEST_ASSERT(r == 1, "parse2map should return 1"); 409 UCX_TEST_ASSERT(r == 1, "properties2map should return 1");
410 UCX_TEST_ASSERT(map->count == 1, "wrong number of properties"); 410 UCX_TEST_ASSERT(map->count == 1, "wrong number of properties");
411 411
412 char *v = (char*)ucx_map_cstr_get(map, "key1"); 412 char *v = (char*)ucx_map_cstr_get(map, "key1");
413 UCX_TEST_ASSERT((!strcmp(v, "value1")), "wrong value"); 413 UCX_TEST_ASSERT((!strcmp(v, "value1")), "wrong value");
414 414
415 UCX_TEST_END 415 UCX_TEST_END
416 416
417 ucx_prop_free(parser); 417 ucx_properties_free(parser);
418 } 418 }
419 419
420 UCX_TEST_IMPLEMENT(test_ucx_properties_load) { 420 UCX_TEST_IMPLEMENT(test_ucx_properties_load) {
421 UCX_TEST_BEGIN 421 UCX_TEST_BEGIN
422 FILE *f = tmpfile(); 422 FILE *f = tmpfile();

mercurial