| 382 free(long_key); |
382 free(long_key); |
| 383 free(long_value); |
383 free(long_value); |
| 384 } |
384 } |
| 385 |
385 |
| 386 CX_TEST(test_properties_load) { |
386 CX_TEST(test_properties_load) { |
| |
387 CxTestingAllocator talloc; |
| |
388 cx_testing_allocator_init(&talloc); |
| 387 char fname[16] = "ucxtestXXXXXX"; |
389 char fname[16] = "ucxtestXXXXXX"; |
| 388 int tmpfd = mkstemp(fname); |
390 int tmpfd = mkstemp(fname); |
| 389 FILE *f = tmpfd < 0 ? NULL : fdopen(tmpfd, "w"); |
391 FILE *f = tmpfd < 0 ? NULL : fdopen(tmpfd, "w"); |
| 390 CX_TEST_DO { |
392 CX_TEST_DO { |
| 391 CX_TEST_ASSERTM(f, "test file cannot be opened, test aborted"); |
393 CX_TEST_ASSERTM(f, "test file cannot be opened, test aborted"); |
| 410 f = NULL; |
412 f = NULL; |
| 411 // preparation of test file complete |
413 // preparation of test file complete |
| 412 |
414 |
| 413 // we want to load the properties into a map of char* pointers |
415 // we want to load the properties into a map of char* pointers |
| 414 CxMap *map = cxHashMapCreateSimple(CX_STORE_POINTERS); |
416 CxMap *map = cxHashMapCreateSimple(CX_STORE_POINTERS); |
| 415 cxDefineDestructor(map, cxFreeDefault); |
417 cxDefineAdvancedDestructor(map, cxFree, &talloc); |
| 416 CxPropertiesStatus status = cxPropertiesLoadDefault(fname, map); |
418 CxPropertiesStatus status = cxPropertiesLoadDefault(&talloc.base, fname, map); |
| 417 |
419 |
| 418 CX_TEST_ASSERT(status == CX_PROPERTIES_NO_ERROR); |
420 CX_TEST_ASSERT(status == CX_PROPERTIES_NO_ERROR); |
| 419 CX_TEST_ASSERT(cxMapSize(map) == 5); |
421 CX_TEST_ASSERT(cxMapSize(map) == 5); |
| 420 |
422 |
| 421 char *v1 = cxMapGet(map, "key1"); |
423 char *v1 = cxMapGet(map, "key1"); |
| 438 CX_TEST_ASSERT(!cx_strcmp(expected, actual)); |
440 CX_TEST_ASSERT(!cx_strcmp(expected, actual)); |
| 439 CX_TEST_ASSERT(!strcmp(lk, "property value")); |
441 CX_TEST_ASSERT(!strcmp(lk, "property value")); |
| 440 |
442 |
| 441 free(long_key); |
443 free(long_key); |
| 442 free(long_value); |
444 free(long_value); |
| |
445 CX_TEST_ASSERT(cx_testing_allocator_used(&talloc)); |
| 443 cxMapFree(map); |
446 cxMapFree(map); |
| 444 } |
447 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
| |
448 } |
| |
449 cx_testing_allocator_destroy(&talloc); |
| 445 if (f) fclose(f); |
450 if (f) fclose(f); |
| 446 remove(fname); |
451 remove(fname); |
| 447 } |
452 } |
| 448 |
453 |
| 449 CX_TEST(test_properties_multiple_fill) { |
454 CX_TEST(test_properties_multiple_fill) { |