| 517 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
517 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
| 518 } |
518 } |
| 519 cx_testing_allocator_destroy(&talloc); |
519 cx_testing_allocator_destroy(&talloc); |
| 520 } |
520 } |
| 521 |
521 |
| |
522 CX_TEST(test_properties_load_incomplete) { |
| |
523 CxTestingAllocator talloc; |
| |
524 cx_testing_allocator_init(&talloc); |
| |
525 CxAllocator *alloc = &talloc.base; |
| |
526 CX_TEST_DO { |
| |
527 char buffer[512]; |
| |
528 CxProperties prop; |
| |
529 cxPropertiesInitDefault(&prop); |
| |
530 cxPropertiesUseStack(&prop, buffer, 512); |
| |
531 |
| |
532 CxMap *map = cxHashMapCreateSimple(CX_STORE_POINTERS); |
| |
533 cxDefineAdvancedDestructor(map, cxFree, alloc); |
| |
534 CxPropertiesSink sink = cxPropertiesMapSink(map); |
| |
535 sink.data = alloc; // use the testing allocator |
| |
536 CxPropertiesSource src = cxPropertiesCstrSource("key1 = value1\nkey2 = value2\n\n#comment\n\nkey3"); |
| |
537 CxPropertiesStatus status = cxPropertiesLoad(&prop, sink, src); |
| |
538 |
| |
539 CX_TEST_ASSERT(status == CX_PROPERTIES_INCOMPLETE_DATA); |
| |
540 CX_TEST_ASSERT(cxMapSize(map) == 2); |
| |
541 |
| |
542 char *v1 = cxMapGet(map, "key1"); |
| |
543 char *v2 = cxMapGet(map, "key2"); |
| |
544 char *v3 = cxMapGet(map, "key3"); |
| |
545 |
| |
546 CX_TEST_ASSERTM(v1, "value for key1 not found"); |
| |
547 CX_TEST_ASSERTM(v2, "value for key2 not found"); |
| |
548 CX_TEST_ASSERT(v3 == NULL); |
| |
549 |
| |
550 CX_TEST_ASSERT(!strcmp(v1, "value1")); |
| |
551 CX_TEST_ASSERT(!strcmp(v2, "value2")); |
| |
552 |
| |
553 // provide a source with the remaining data |
| |
554 src = cxPropertiesCstrSource(" = value3\n"); |
| |
555 status = cxPropertiesLoad(&prop, sink, src); |
| |
556 |
| |
557 CX_TEST_ASSERT(status == CX_PROPERTIES_NO_ERROR); |
| |
558 CX_TEST_ASSERT(cxMapSize(map) == 3); |
| |
559 |
| |
560 v1 = cxMapGet(map, "key1"); |
| |
561 v2 = cxMapGet(map, "key2"); |
| |
562 v3 = cxMapGet(map, "key3"); |
| |
563 |
| |
564 CX_TEST_ASSERTM(v1, "value for key1 not found"); |
| |
565 CX_TEST_ASSERTM(v2, "value for key2 not found"); |
| |
566 CX_TEST_ASSERTM(v3, "value for key3 not found"); |
| |
567 |
| |
568 CX_TEST_ASSERT(!strcmp(v1, "value1")); |
| |
569 CX_TEST_ASSERT(!strcmp(v2, "value2")); |
| |
570 CX_TEST_ASSERT(!strcmp(v3, "value3")); |
| |
571 |
| |
572 cxMapFree(map); |
| |
573 cxPropertiesDestroy(&prop); |
| |
574 |
| |
575 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
| |
576 } |
| |
577 cx_testing_allocator_destroy(&talloc); |
| |
578 } |
| |
579 |
| 522 CX_TEST(test_properties_multiple_fill) { |
580 CX_TEST(test_properties_multiple_fill) { |
| 523 const char *props1 = "key1 = value1\n"; |
581 const char *props1 = "key1 = value1\n"; |
| 524 const char *props2 = "key2 = value2\n"; |
582 const char *props2 = "key2 = value2\n"; |
| 525 const char *props3 = "key3 = value3\n"; |
583 const char *props3 = "key3 = value3\n"; |
| 526 |
584 |
| 626 cx_test_register(suite, test_properties_next_multi); |
684 cx_test_register(suite, test_properties_next_multi); |
| 627 cx_test_register(suite, test_properties_next_part); |
685 cx_test_register(suite, test_properties_next_part); |
| 628 cx_test_register(suite, test_properties_next_long_lines); |
686 cx_test_register(suite, test_properties_next_long_lines); |
| 629 cx_test_register(suite, test_properties_load_string_to_map); |
687 cx_test_register(suite, test_properties_load_string_to_map); |
| 630 cx_test_register(suite, test_properties_load_file_to_map); |
688 cx_test_register(suite, test_properties_load_file_to_map); |
| |
689 cx_test_register(suite, test_properties_load_incomplete); |
| 631 cx_test_register(suite, test_properties_multiple_fill); |
690 cx_test_register(suite, test_properties_multiple_fill); |
| 632 cx_test_register(suite, test_properties_use_stack); |
691 cx_test_register(suite, test_properties_use_stack); |
| 633 cx_test_register(suite, test_properties_empty_key); |
692 cx_test_register(suite, test_properties_empty_key); |
| 634 |
693 |
| 635 return suite; |
694 return suite; |