--- a/test/test_buffer.cpp Mon Jul 25 15:29:56 2022 +0200 +++ b/test/test_buffer.cpp Mon Jul 25 15:34:19 2022 +0200 @@ -746,3 +746,34 @@ cxBufferWrite("test", 1, 5, &buf); EXPECT_FALSE(cxBufferEof(&buf)); } + +class BufferRead : public ::testing::Test { +protected: + CxBuffer buf{}; + + void SetUp() override { + cxBufferInit(&buf, nullptr, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + buf.capacity = 8; // artificially reduce capacity to check OOB writes + memset(buf.space, 0, 16); + memcpy(buf.space, "some data", 9); + buf.size = 9; + } + + void TearDown() override { + cxBufferDestroy(&buf); + } +}; + +TEST_F(BufferRead, GetByte) { + buf.pos = 2; + EXPECT_EQ(cxBufferGet(&buf), 'm'); + EXPECT_EQ(cxBufferGet(&buf), 'e'); + EXPECT_EQ(cxBufferGet(&buf), ' '); + EXPECT_EQ(cxBufferGet(&buf), 'd'); + EXPECT_EQ(buf.pos, 6); +} + +TEST_F(BufferRead, GetEof) { + buf.pos = buf.size; + EXPECT_EQ(cxBufferGet(&buf), EOF); +}