tests/test_buffer.c

changeset 1030
06091e067bee
parent 1028
3e4905241838
--- a/tests/test_buffer.c	Fri Dec 20 13:13:38 2024 +0100
+++ b/tests/test_buffer.c	Fri Dec 20 15:00:05 2024 +0100
@@ -790,6 +790,24 @@
     cxBufferDestroy(&buf);
 }
 
+CX_TEST(test_buffer_append) {
+    CxBuffer buf;
+    cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND);
+    memcpy(buf.space, "prepXXXX\0\0\0\0\0\0\0\0", 16);
+    buf.capacity = 8;
+    buf.size = 6;
+    buf.pos = 4;
+    CX_TEST_DO {
+        size_t written = cxBufferAppend("testing", 1, 7, &buf);
+        CX_TEST_ASSERT(written == 7);
+        CX_TEST_ASSERT(buf.size == 13);
+        CX_TEST_ASSERT(buf.pos == 4);
+        CX_TEST_ASSERT(buf.capacity >= 13);
+        CX_TEST_ASSERT(0 == memcmp(buf.space, "prepXXtesting", 13));
+    }
+    cxBufferDestroy(&buf);
+}
+
 CX_TEST(test_buffer_put_fit) {
     CxBuffer buf;
     cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
@@ -1314,6 +1332,7 @@
     cx_test_register(suite, test_buffer_write_multibyte_discard);
     cx_test_register(suite, test_buffer_write_multibyte_extend);
     cx_test_register(suite, test_buffer_write_copy_on_write);
+    cx_test_register(suite, test_buffer_append);
     cx_test_register(suite, test_buffer_put_fit);
     cx_test_register(suite, test_buffer_put_discard);
     cx_test_register(suite, test_buffer_put_extend);

mercurial