| 519 fclose(f); |
519 fclose(f); |
| 520 f = NULL; |
520 f = NULL; |
| 521 // preparation of test file complete |
521 // preparation of test file complete |
| 522 |
522 |
| 523 // we want to load the properties into a map of char* pointers |
523 // we want to load the properties into a map of char* pointers |
| 524 CxMap *map = cxHashMapCreateSimple(CX_STORE_POINTERS); |
524 CxMap *map = cxHashMapCreate(NULL, CX_STORE_POINTERS, 0); |
| 525 cxDefineAdvancedDestructor(map, cxFree, &talloc); |
525 cxSetAdvancedDestructor(map, cxFree, &talloc); |
| 526 CxPropertiesStatus status = cxPropertiesLoadDefault(&talloc.base, fname, map); |
526 CxPropertiesStatus status = cxPropertiesLoadDefault(&talloc.base, fname, map); |
| 527 |
527 |
| 528 CX_TEST_ASSERT(status == CX_PROPERTIES_NO_ERROR); |
528 CX_TEST_ASSERT(status == CX_PROPERTIES_NO_ERROR); |
| 529 CX_TEST_ASSERT(cxMapSize(map) == 5); |
529 CX_TEST_ASSERT(cxMapSize(map) == 5); |
| 530 |
530 |
| 568 CX_TEST_DO { |
568 CX_TEST_DO { |
| 569 CX_TEST_ASSERTM(f, "test file cannot be opened, test aborted"); |
569 CX_TEST_ASSERTM(f, "test file cannot be opened, test aborted"); |
| 570 fclose(f); |
570 fclose(f); |
| 571 f = NULL; |
571 f = NULL; |
| 572 |
572 |
| 573 CxMap *map = cxHashMapCreateSimple(CX_STORE_POINTERS); |
573 CxMap *map = cxHashMapCreate(NULL, CX_STORE_POINTERS, 0); |
| 574 // store something that we don't want to be deleted |
574 // store something that we don't want to be deleted |
| 575 cxMapPut(map, "test", "value"); |
575 cxMapPut(map, "test", "value"); |
| 576 CxPropertiesStatus status = cxPropertiesLoadDefault(&talloc.base, fname, map); |
576 CxPropertiesStatus status = cxPropertiesLoadDefault(&talloc.base, fname, map); |
| 577 CX_TEST_ASSERT(status == CX_PROPERTIES_NO_DATA); |
577 CX_TEST_ASSERT(status == CX_PROPERTIES_NO_DATA); |
| 578 CX_TEST_ASSERT(cxMapSize(map) == 1); |
578 CX_TEST_ASSERT(cxMapSize(map) == 1); |
| 599 CX_TEST_ASSERTM(f, "test file cannot be opened, test aborted"); |
599 CX_TEST_ASSERTM(f, "test file cannot be opened, test aborted"); |
| 600 fputs("# test file\n\n# contains only comments\n\n# key = value\n", f); |
600 fputs("# test file\n\n# contains only comments\n\n# key = value\n", f); |
| 601 fclose(f); |
601 fclose(f); |
| 602 f = NULL; |
602 f = NULL; |
| 603 |
603 |
| 604 CxMap *map = cxHashMapCreateSimple(CX_STORE_POINTERS); |
604 CxMap *map = cxHashMapCreate(NULL, CX_STORE_POINTERS, 0); |
| 605 CxPropertiesStatus status = cxPropertiesLoadDefault(&talloc.base, fname, map); |
605 CxPropertiesStatus status = cxPropertiesLoadDefault(&talloc.base, fname, map); |
| 606 CX_TEST_ASSERT(status == CX_PROPERTIES_NO_DATA); |
606 CX_TEST_ASSERT(status == CX_PROPERTIES_NO_DATA); |
| 607 CX_TEST_ASSERT(cxMapSize(map) == 0); |
607 CX_TEST_ASSERT(cxMapSize(map) == 0); |
| 608 |
608 |
| 609 CX_TEST_ASSERT(!cx_testing_allocator_used(&talloc)); |
609 CX_TEST_ASSERT(!cx_testing_allocator_used(&talloc)); |
| 625 CX_TEST_ASSERTM(f, "test file cannot be opened, test aborted"); |
625 CX_TEST_ASSERTM(f, "test file cannot be opened, test aborted"); |
| 626 fputs("# test file\n\ntest = value\n = value2\n", f); |
626 fputs("# test file\n\ntest = value\n = value2\n", f); |
| 627 fclose(f); |
627 fclose(f); |
| 628 f = NULL; |
628 f = NULL; |
| 629 |
629 |
| 630 CxMap *map = cxHashMapCreateSimple(CX_STORE_POINTERS); |
630 CxMap *map = cxHashMapCreate(NULL, CX_STORE_POINTERS, 0); |
| 631 cxDefineAdvancedDestructor(map, cxFree, &talloc); |
631 cxSetAdvancedDestructor(map, cxFree, &talloc); |
| 632 CxPropertiesStatus status = cxPropertiesLoadDefault(&talloc.base, fname, map); |
632 CxPropertiesStatus status = cxPropertiesLoadDefault(&talloc.base, fname, map); |
| 633 CX_TEST_ASSERT(status == CX_PROPERTIES_INVALID_EMPTY_KEY); |
633 CX_TEST_ASSERT(status == CX_PROPERTIES_INVALID_EMPTY_KEY); |
| 634 // all keys that could be successfully parsed are added |
634 // all keys that could be successfully parsed are added |
| 635 CX_TEST_ASSERT(cxMapSize(map) == 1); |
635 CX_TEST_ASSERT(cxMapSize(map) == 1); |
| 636 char *v = cxMapGet(map, "test"); |
636 char *v = cxMapGet(map, "test"); |
| 645 remove(fname); |
645 remove(fname); |
| 646 } |
646 } |
| 647 |
647 |
| 648 CX_TEST(test_properties_load_file_not_exists) { |
648 CX_TEST(test_properties_load_file_not_exists) { |
| 649 CX_TEST_DO { |
649 CX_TEST_DO { |
| 650 CxMap *map = cxHashMapCreateSimple(CX_STORE_POINTERS); |
650 CxMap *map = cxHashMapCreate(NULL, CX_STORE_POINTERS, 0); |
| 651 CxPropertiesStatus status = cxPropertiesLoadDefault(NULL, "does-definitely-not-exist", map); |
651 CxPropertiesStatus status = cxPropertiesLoadDefault(NULL, "does-definitely-not-exist", map); |
| 652 CX_TEST_ASSERT(status == CX_PROPERTIES_FILE_ERROR); |
652 CX_TEST_ASSERT(status == CX_PROPERTIES_FILE_ERROR); |
| 653 cxMapFree(map); |
653 cxMapFree(map); |
| 654 } |
654 } |
| 655 } |
655 } |
| 664 CX_TEST_ASSERTM(f, "test file cannot be opened, test aborted"); |
664 CX_TEST_ASSERTM(f, "test file cannot be opened, test aborted"); |
| 665 fputs("# test file\n\ntest = value\ntest2 = value2\n", f); |
665 fputs("# test file\n\ntest = value\ntest2 = value2\n", f); |
| 666 fclose(f); |
666 fclose(f); |
| 667 f = NULL; |
667 f = NULL; |
| 668 |
668 |
| 669 CxMap *map = cxHashMapCreateSimple(sizeof(cxmutstr)); |
669 CxMap *map = cxHashMapCreate(NULL, sizeof(cxmutstr), 0); |
| 670 cxDefineAdvancedDestructor(map, cx_strfree_a, &talloc); |
670 cxSetAdvancedDestructor(map, cx_strfree_a, &talloc); |
| 671 CxPropertiesStatus status = cxPropertiesLoadDefault(&talloc.base, fname, map); |
671 CxPropertiesStatus status = cxPropertiesLoadDefault(&talloc.base, fname, map); |
| 672 CX_TEST_ASSERT(status == CX_PROPERTIES_NO_ERROR); |
672 CX_TEST_ASSERT(status == CX_PROPERTIES_NO_ERROR); |
| 673 CX_TEST_ASSERT(cxMapSize(map) == 2); |
673 CX_TEST_ASSERT(cxMapSize(map) == 2); |
| 674 cxstring v1 = cx_str("value"); |
674 cxstring v1 = cx_str("value"); |
| 675 cxstring v2 = cx_str("value2"); |
675 cxstring v2 = cx_str("value2"); |
| 695 CX_TEST_ASSERTM(f, "test file cannot be opened, test aborted"); |
695 CX_TEST_ASSERTM(f, "test file cannot be opened, test aborted"); |
| 696 fputs("# test file\n\ntest = value\ntest2 = value2\n", f); |
696 fputs("# test file\n\ntest = value\ntest2 = value2\n", f); |
| 697 fclose(f); |
697 fclose(f); |
| 698 f = NULL; |
698 f = NULL; |
| 699 |
699 |
| 700 CxMap *map = cxHashMapCreateSimple(sizeof(CxBuffer)); |
700 CxMap *map = cxHashMapCreate(NULL, sizeof(CxBuffer), 0); |
| 701 cxDefineAdvancedDestructor(map, cxFree, &talloc); |
701 cxSetAdvancedDestructor(map, cxFree, &talloc); |
| 702 CxPropertiesStatus status = cxPropertiesLoadDefault(&talloc.base, fname, map); |
702 CxPropertiesStatus status = cxPropertiesLoadDefault(&talloc.base, fname, map); |
| 703 CX_TEST_ASSERT(status == CX_PROPERTIES_MAP_ERROR); |
703 CX_TEST_ASSERT(status == CX_PROPERTIES_MAP_ERROR); |
| 704 CX_TEST_ASSERT(cxMapSize(map) == 0); |
704 CX_TEST_ASSERT(cxMapSize(map) == 0); |
| 705 |
705 |
| 706 cxMapFree(map); |
706 cxMapFree(map); |