| 449 cx_testing_allocator_destroy(&talloc); |
449 cx_testing_allocator_destroy(&talloc); |
| 450 if (f) fclose(f); |
450 if (f) fclose(f); |
| 451 remove(fname); |
451 remove(fname); |
| 452 } |
452 } |
| 453 |
453 |
| |
454 CX_TEST(test_properties_load_empty_file) { |
| |
455 CxTestingAllocator talloc; |
| |
456 cx_testing_allocator_init(&talloc); |
| |
457 char fname[16] = "ucxtestXXXXXX"; |
| |
458 int tmpfd = mkstemp(fname); |
| |
459 FILE *f = tmpfd < 0 ? NULL : fdopen(tmpfd, "w"); |
| |
460 CX_TEST_DO { |
| |
461 CX_TEST_ASSERTM(f, "test file cannot be opened, test aborted"); |
| |
462 fclose(f); |
| |
463 f = NULL; |
| |
464 |
| |
465 CxMap *map = cxHashMapCreateSimple(CX_STORE_POINTERS); |
| |
466 // store something that we don't want to be deleted |
| |
467 cxMapPut(map, "test", "value"); |
| |
468 CxPropertiesStatus status = cxPropertiesLoadDefault(&talloc.base, fname, map); |
| |
469 CX_TEST_ASSERT(status == CX_PROPERTIES_NO_DATA); |
| |
470 CX_TEST_ASSERT(cxMapSize(map) == 1); |
| |
471 |
| |
472 char *v = cxMapGet(map, "test"); |
| |
473 CX_TEST_ASSERTM(v, "value was removed"); |
| |
474 CX_TEST_ASSERT(!strcmp(v, "value")); |
| |
475 CX_TEST_ASSERT(!cx_testing_allocator_used(&talloc)); |
| |
476 cxMapFree(map); |
| |
477 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
| |
478 } |
| |
479 cx_testing_allocator_destroy(&talloc); |
| |
480 if (f) fclose(f); |
| |
481 remove(fname); |
| |
482 } |
| |
483 |
| |
484 CX_TEST(test_properties_load_only_comments) { |
| |
485 CxTestingAllocator talloc; |
| |
486 cx_testing_allocator_init(&talloc); |
| |
487 char fname[16] = "ucxtestXXXXXX"; |
| |
488 int tmpfd = mkstemp(fname); |
| |
489 FILE *f = tmpfd < 0 ? NULL : fdopen(tmpfd, "w"); |
| |
490 CX_TEST_DO { |
| |
491 CX_TEST_ASSERTM(f, "test file cannot be opened, test aborted"); |
| |
492 fputs("# test file\n\n# contains only comments\n\n# key = value\n", f); |
| |
493 fclose(f); |
| |
494 f = NULL; |
| |
495 |
| |
496 CxMap *map = cxHashMapCreateSimple(CX_STORE_POINTERS); |
| |
497 CxPropertiesStatus status = cxPropertiesLoadDefault(&talloc.base, fname, map); |
| |
498 CX_TEST_ASSERT(status == CX_PROPERTIES_NO_DATA); |
| |
499 CX_TEST_ASSERT(cxMapSize(map) == 0); |
| |
500 |
| |
501 CX_TEST_ASSERT(!cx_testing_allocator_used(&talloc)); |
| |
502 cxMapFree(map); |
| |
503 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
| |
504 } |
| |
505 cx_testing_allocator_destroy(&talloc); |
| |
506 if (f) fclose(f); |
| |
507 remove(fname); |
| |
508 } |
| |
509 |
| 454 CX_TEST(test_properties_multiple_fill) { |
510 CX_TEST(test_properties_multiple_fill) { |
| 455 const char *props1 = "key1 = value1\n"; |
511 const char *props1 = "key1 = value1\n"; |
| 456 const char *props2 = "key2 = value2\n"; |
512 const char *props2 = "key2 = value2\n"; |
| 457 const char *props3 = "key3 = value3\n"; |
513 const char *props3 = "key3 = value3\n"; |
| 458 |
514 |
| 557 cx_test_register(suite, test_properties_next); |
613 cx_test_register(suite, test_properties_next); |
| 558 cx_test_register(suite, test_properties_next_multi); |
614 cx_test_register(suite, test_properties_next_multi); |
| 559 cx_test_register(suite, test_properties_next_part); |
615 cx_test_register(suite, test_properties_next_part); |
| 560 cx_test_register(suite, test_properties_next_long_lines); |
616 cx_test_register(suite, test_properties_next_long_lines); |
| 561 cx_test_register(suite, test_properties_load); |
617 cx_test_register(suite, test_properties_load); |
| 562 // TODO: test_properties_load_empty_file |
618 cx_test_register(suite, test_properties_load_empty_file); |
| |
619 cx_test_register(suite, test_properties_load_only_comments); |
| 563 // TODO: test_properties_load_invalid_key |
620 // TODO: test_properties_load_invalid_key |
| 564 // TODO: test_properties_load_missing_delimiter |
621 // TODO: test_properties_load_missing_delimiter |
| 565 // TODO: test_properties_load_unexpected_end |
622 // TODO: test_properties_load_unexpected_end |
| 566 // TODO: test_properties_load_file_not_exists |
623 // TODO: test_properties_load_file_not_exists |
| 567 // TODO: test_properties_load_exceed_stack |
624 // TODO: test_properties_load_exceed_stack |