test/buffer_tests.c

changeset 290
d5d6ab809ad3
parent 269
591473851c95
equal deleted inserted replaced
289:a5eabd407774 290:d5d6ab809ad3
623 623
624 UCX_TEST_END 624 UCX_TEST_END
625 625
626 ucx_buffer_free(b); 626 ucx_buffer_free(b);
627 } 627 }
628
629 UCX_TEST(test_ucx_buffer_shl) {
630
631 const char* hw = "Shift the World!";
632
633 UcxBuffer *b = ucx_buffer_new(NULL, 20, UCX_BUFFER_DEFAULT);
634 ucx_buffer_puts(b, hw);
635 b->pos = 5;
636
637 UCX_TEST_BEGIN
638 char* expected;
639
640 ucx_buffer_shift_left(b, 2);
641 expected = "ift the World!";
642
643 UCX_TEST_ASSERT(b->pos == 3, "position after normal shl wrong");
644 UCX_TEST_ASSERT(b->size == strlen(expected), "size after normal shl wrong");
645 UCX_TEST_ASSERT(!memcmp(b->space, expected, b->size),
646 "contents after normal shl wrong");
647
648
649 ucx_buffer_shift_left(b, 5);
650 expected = "he World!";
651
652 UCX_TEST_ASSERT(b->pos == 0, "position after overshift left wrong");
653 UCX_TEST_ASSERT(b->size == strlen(expected),
654 "size after overshift left wrong");
655 UCX_TEST_ASSERT(!memcmp(b->space, expected, b->size),
656 "contents after overshift left wrong");
657
658 ucx_buffer_shift_left(b, 10);
659 UCX_TEST_ASSERT(b->pos == 0, "position after 'shl everything away' wrong");
660 UCX_TEST_ASSERT(b->size == 0, "size after 'shl everything away' wrong");
661
662 UCX_TEST_END
663
664 ucx_buffer_free(b);
665 }
666
667 UCX_TEST(test_ucx_buffer_shr) {
668
669 const char* hw = "Shift the World!";
670
671 UcxBuffer *b = ucx_buffer_new(NULL, 20, UCX_BUFFER_DEFAULT);
672 ucx_buffer_puts(b, hw);
673 b->pos = 12;
674
675 UCX_TEST_BEGIN
676 char* expected;
677
678 ucx_buffer_shift_right(b, 2);
679 expected = "ShShift the World!";
680
681 UCX_TEST_ASSERT(b->pos == 14, "position after normal shr wrong");
682 UCX_TEST_ASSERT(b->size == strlen(expected), "size after normal shr wrong");
683 UCX_TEST_ASSERT(!memcmp(b->space, expected, b->size),
684 "contents after normal shr wrong");
685
686
687 ucx_buffer_shift_right(b, 5);
688 expected = "ShShiShShift the Wor";
689 UCX_TEST_ASSERT(strlen(expected) == b->capacity,
690 "Test data is wrong, please fix the test.");
691
692 UCX_TEST_ASSERT(b->pos == 19,
693 "position after overshift right w/o auto-extend wrong");
694 UCX_TEST_ASSERT(b->size == 20,
695 "size after overshift right w/o auto-extend wrong");
696 UCX_TEST_ASSERT(b->capacity == 20,
697 "capacity after overshift right w/o auto-extend wrong");
698 UCX_TEST_ASSERT(!memcmp(b->space, expected, b->size),
699 "contents after overshift right w/o auto-extend wrong");
700
701 ucx_buffer_shift_right(b, 15);
702 UCX_TEST_ASSERT(b->pos == b->capacity, "position after 'shr to eof' wrong");
703 UCX_TEST_ASSERT(b->size == b->capacity, "size after 'shr to eof' wrong");
704 UCX_TEST_ASSERT(ucx_buffer_eof(b), "buffer not eof after 'shr to eof'");
705
706 UCX_TEST_END
707
708 ucx_buffer_free(b);
709 }
710
711 UCX_TEST(test_ucx_buffer_shr_ax) {
712
713 const char* hw = "Shift the World!";
714
715 UcxBuffer *b = ucx_buffer_new(NULL, 20, UCX_BUFFER_AUTOEXTEND);
716 ucx_buffer_puts(b, hw);
717 b->pos = 12;
718
719 UCX_TEST_BEGIN
720
721 const char* expected = "Shift the Shift the World!";
722
723 ucx_buffer_shift_right(b, 10);
724 UCX_TEST_ASSERT(b->pos == 22, "position after shr w/ auto-extend wrong");
725 UCX_TEST_ASSERT(b->size == strlen(expected),
726 "size after shr w/ auto-extend wrong");
727 UCX_TEST_ASSERT(b->capacity >= b->size,
728 "auto-extension of capacity after shr w/ auto-extend failed");
729 UCX_TEST_ASSERT(!ucx_buffer_eof(b),
730 "buffer should not be eof after shr w/ auto-extend");
731 UCX_TEST_ASSERT(!memcmp(b->space, expected, b->size),
732 "contents wrong after shr w/ auto-extend");
733
734 UCX_TEST_END
735
736 ucx_buffer_free(b);
737 }
738

mercurial