#170 add cxBufferClear test

Sat, 30 Apr 2022 08:30:51 +0200

author
Mike Becker <universe@uap-core.de>
date
Sat, 30 Apr 2022 08:30:51 +0200
changeset 536
cb9b9739055e
parent 535
2ff6e9184468
child 537
16219eba3a0a

#170 add cxBufferClear test

src/buffer.c file | annotate | diff | comparison | revisions
test/test_buffer.cpp file | annotate | diff | comparison | revisions
--- a/src/buffer.c	Sun Apr 24 17:45:09 2022 +0200
+++ b/src/buffer.c	Sat Apr 30 08:30:51 2022 +0200
@@ -119,7 +119,8 @@
         return 0;
     }
 
-    if (cxReallocate(buffer->allocator, &buffer->bytes, newcap) == 0) {
+    if (cxReallocate(buffer->allocator,
+                     (void **) &buffer->bytes, newcap) == 0) {
         buffer->capacity = newcap;
         return 0;
     } else {
--- a/test/test_buffer.cpp	Sun Apr 24 17:45:09 2022 +0200
+++ b/test/test_buffer.cpp	Sat Apr 30 08:30:51 2022 +0200
@@ -242,3 +242,20 @@
     cxBufferDestroy(&buf);
     EXPECT_TRUE(alloc.verify());
 }
+
+TEST(BufferClear, Test) {
+    char space[16];
+    strcpy(space, "clear test");
+    CxBuffer buf;
+    cxBufferInit(&buf, space, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
+    ASSERT_EQ(buf.size, 0);
+    // only clear the used part of the buffer
+    cxBufferClear(&buf);
+    EXPECT_EQ(memcmp(space, "clear test", 10), 0);
+    buf.size = 5;
+    buf.pos = 3;
+    cxBufferClear(&buf);
+    EXPECT_EQ(memcmp(space, "\0\0\0\0\0 test", 10), 0);
+    EXPECT_EQ(buf.size, 0);
+    EXPECT_EQ(buf.pos, 0);
+}

mercurial