#170 test cxBufferRead

Mon, 25 Jul 2022 15:40:27 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 25 Jul 2022 15:40:27 +0200
changeset 569
cb63f3d1236a
parent 568
8eda32d09e3d
child 570
7edce1b5a798

#170 test cxBufferRead

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

mercurial