tests/test_buffer.c

changeset 1131
644f77f903b1
parent 1129
cc60b7d07912
equal deleted inserted replaced
1130:5bcb725119b6 1131:644f77f903b1
788 CX_TEST_ASSERT(buf.pos == 4); 788 CX_TEST_ASSERT(buf.pos == 4);
789 CX_TEST_ASSERT(buf.capacity >= 13); 789 CX_TEST_ASSERT(buf.capacity >= 13);
790 CX_TEST_ASSERT(0 == memcmp(buf.space, "prepXXtesting", 13)); 790 CX_TEST_ASSERT(0 == memcmp(buf.space, "prepXXtesting", 13));
791 } 791 }
792 cxBufferDestroy(&buf); 792 cxBufferDestroy(&buf);
793 }
794
795 CX_TEST(test_buffer_append_flush) {
796 CxBuffer buf, target;
797 cxBufferInit(&buf, NULL, 8, cxDefaultAllocator, CX_BUFFER_DEFAULT);
798 cxBufferInit(&target, NULL, 8, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
799 memcpy(buf.space, "prepXXXX", 8);
800 buf.capacity = 8;
801 buf.size = 6;
802 buf.pos = 4;
803 CxBufferFlushConfig flush;
804 flush.threshold = 0;
805 flush.blksize = 4;
806 flush.blkmax = 1;
807 flush.target = ⌖
808 flush.wfunc = cxBufferWriteFunc;
809 cxBufferEnableFlushing(&buf, flush);
810 CX_TEST_DO{
811 size_t written = cxBufferAppend("testing", 1, 7, &buf);
812 CX_TEST_ASSERT(written == 7);
813 CX_TEST_ASSERT(buf.size == 7);
814 CX_TEST_ASSERTM(buf.pos == 0, "position not correctly reset");
815 CX_TEST_ASSERT(buf.capacity == 8);
816 CX_TEST_ASSERT(target.size == 6);
817 CX_TEST_ASSERT(target.pos == 6);
818 CX_TEST_ASSERT(0 == memcmp(buf.space, "testing", 7));
819 CX_TEST_ASSERT(0 == memcmp(target.space, "prepXX", 6));
820 // second test - position only shifted by one block
821 buf.pos = 6;
822 written = cxBufferAppend("foo", 1, 3, &buf);
823 CX_TEST_ASSERT(written == 3);
824 CX_TEST_ASSERT(buf.size == 6);
825 CX_TEST_ASSERTM(buf.pos == 2, "position not correctly adjusted");
826 CX_TEST_ASSERT(buf.capacity == 8);
827 CX_TEST_ASSERT(target.size == 10);
828 CX_TEST_ASSERT(target.pos == 10);
829 CX_TEST_ASSERT(0 == memcmp(buf.space, "ingfoo", 6));
830 CX_TEST_ASSERT(0 == memcmp(target.space, "prepXXtest", 10));
831 }
832 cxBufferDestroy(&buf);
833 cxBufferDestroy(&target);
793 } 834 }
794 835
795 CX_TEST(test_buffer_put_fit) { 836 CX_TEST(test_buffer_put_fit) {
796 CxBuffer buf; 837 CxBuffer buf;
797 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); 838 cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
1446 cx_test_register(suite, test_buffer_write_multibyte_fit); 1487 cx_test_register(suite, test_buffer_write_multibyte_fit);
1447 cx_test_register(suite, test_buffer_write_multibyte_discard); 1488 cx_test_register(suite, test_buffer_write_multibyte_discard);
1448 cx_test_register(suite, test_buffer_write_multibyte_extend); 1489 cx_test_register(suite, test_buffer_write_multibyte_extend);
1449 cx_test_register(suite, test_buffer_write_copy_on_write); 1490 cx_test_register(suite, test_buffer_write_copy_on_write);
1450 cx_test_register(suite, test_buffer_append); 1491 cx_test_register(suite, test_buffer_append);
1492 cx_test_register(suite, test_buffer_append_flush);
1451 cx_test_register(suite, test_buffer_put_fit); 1493 cx_test_register(suite, test_buffer_put_fit);
1452 cx_test_register(suite, test_buffer_put_discard); 1494 cx_test_register(suite, test_buffer_put_discard);
1453 cx_test_register(suite, test_buffer_put_extend); 1495 cx_test_register(suite, test_buffer_put_extend);
1454 cx_test_register(suite, test_buffer_put_copy_on_write); 1496 cx_test_register(suite, test_buffer_put_copy_on_write);
1455 cx_test_register(suite, test_buffer_put_string_fit); 1497 cx_test_register(suite, test_buffer_put_string_fit);

mercurial