test/test_buffer.cpp

changeset 548
459bca1cdf8d
parent 547
9e933920dcf9
child 565
d756746ea94f
--- a/test/test_buffer.cpp	Mon May 16 19:15:44 2022 +0200
+++ b/test/test_buffer.cpp	Mon May 16 19:25:19 2022 +0200
@@ -31,6 +31,21 @@
 #include <gtest/gtest.h>
 #include "util_allocator.h"
 
+class BufferFixture : public ::testing::Test {
+protected:
+    void SetUp() override {
+        cxBufferInit(&buf, nullptr, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
+        buf.size = 6;
+        buf.pos = 3;
+    }
+
+    void TearDown() override {
+        cxBufferDestroy(&buf);
+    }
+
+    CxBuffer buf{};
+};
+
 static void expect_default_flush_config(CxBuffer *buf) {
     EXPECT_EQ(buf->flush_blkmax, 0);
     EXPECT_EQ(buf->flush_blksize, 4096);
@@ -580,19 +595,7 @@
     EXPECT_EQ(memcmp(target.space, "prepfoobarhello", 15), 0);
 }
 
-class BufferSeek : public ::testing::Test {
-protected:
-    void SetUp() override {
-        cxBufferInit(&buf, nullptr, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
-        buf.size = 6;
-        buf.pos = 3;
-    }
-
-    void TearDown() override {
-        cxBufferDestroy(&buf);
-    }
-
-    CxBuffer buf{};
+class BufferSeek : public BufferFixture {
 };
 
 TEST_F(BufferSeek, SetZero) {
@@ -678,4 +681,24 @@
     EXPECT_NE(result, 0);
     EXPECT_EQ(buf.size, 6);
     EXPECT_EQ(buf.pos, 3);
-}
\ No newline at end of file
+}
+
+class BufferEof : public BufferFixture {
+};
+
+TEST_F(BufferEof, Reached) {
+    buf.pos = buf.size;
+    EXPECT_TRUE(cxBufferEof(&buf));
+    buf.pos = buf.size - 1;
+    ASSERT_FALSE(cxBufferEof(&buf));
+    cxBufferPut(&buf, 'a');
+    EXPECT_TRUE(cxBufferEof(&buf));
+}
+
+TEST_F(BufferEof, NotReached) {
+    buf.pos = buf.size - 1;
+    EXPECT_FALSE(cxBufferEof(&buf));
+    buf.pos = 0;
+    cxBufferWrite("test", 1, 5, &buf);
+    EXPECT_FALSE(cxBufferEof(&buf));
+}

mercurial