#170 test cxBufferGet

Mon, 25 Jul 2022 15:34:19 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 25 Jul 2022 15:34:19 +0200
changeset 568
8eda32d09e3d
parent 567
f90a7cfe2480
child 569
cb63f3d1236a

#170 test cxBufferGet

test/test_buffer.cpp file | annotate | diff | comparison | revisions
--- 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);
+}

mercurial