--- 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); +}