--- a/test/test_buffer.cpp Mon Jul 25 15:34:19 2022 +0200 +++ b/test/test_buffer.cpp Mon Jul 25 15:40:27 2022 +0200 @@ -777,3 +777,39 @@ buf.pos = buf.size; EXPECT_EQ(cxBufferGet(&buf), EOF); } + +TEST_F(BufferRead, ReadWithinBounds) { + buf.pos = 2; + char target[4]; + auto read = cxBufferRead(&target, 1, 4, &buf); + ASSERT_EQ(read, 4); + EXPECT_EQ(memcmp(&target, "me d", 4), 0); + EXPECT_EQ(buf.pos, 6); +} + +TEST_F(BufferRead, ReadOutOfBounds) { + buf.pos = 6; + char target[4]; + auto read = cxBufferRead(&target, 1, 4, &buf); + ASSERT_EQ(read, 3); + EXPECT_EQ(memcmp(&target, "ata", 3), 0); + EXPECT_EQ(buf.pos, 9); +} + +TEST_F(BufferRead, ReadOutOfBoundsMultibyte) { + buf.pos = 6; + char target[4]; + target[2] = '\0'; + auto read = cxBufferRead(&target, 2, 2, &buf); + ASSERT_EQ(read, 1); + EXPECT_EQ(memcmp(&target, "at\0", 3), 0); + EXPECT_EQ(buf.pos, 8); +} + +TEST_F(BufferRead, ReadEof) { + buf.pos = 9; + char target[4]; + auto read = cxBufferRead(&target, 1, 1, &buf); + ASSERT_EQ(read, 0); + EXPECT_EQ(buf.pos, 9); +}