#184 #170 flush at threshold test

Sun, 01 May 2022 16:48:26 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 01 May 2022 16:48:26 +0200
changeset 546
900795d59d03
parent 545
3700ac4bd9a3
child 547
9e933920dcf9

#184 #170 flush at threshold test

test/test_buffer.cpp file | annotate | diff | comparison | revisions
--- a/test/test_buffer.cpp	Sun May 01 16:12:13 2022 +0200
+++ b/test/test_buffer.cpp	Sun May 01 16:48:26 2022 +0200
@@ -535,3 +535,27 @@
     ASSERT_EQ(target.size, 12);
     EXPECT_EQ(memcmp(target.space, "prepfoohello", 12), 0);
 }
+
+TEST_F(BufferWrite, FlushAtThreshold) {
+    enableFlushing();
+    buf.flush_threshold = 12;
+    buf.flags |= CX_BUFFER_AUTO_EXTEND;
+    ASSERT_EQ(buf.capacity, 8);
+    ASSERT_EQ(buf.pos, 4);
+    size_t written = cxBufferWrite("foobar", 1, 6, &buf);
+    EXPECT_EQ(written, 6);
+    ASSERT_EQ(buf.pos, 10);
+    ASSERT_EQ(buf.size, 10);
+    ASSERT_GE(buf.capacity, 10);
+    ASSERT_LE(buf.capacity, 12);
+    ASSERT_EQ(target.pos, 0);
+    ASSERT_EQ(target.size, 0);
+    written = cxBufferWrite("hello", 1, 5, &buf);
+    EXPECT_EQ(written, 5);
+    EXPECT_EQ(buf.pos, 0);
+    EXPECT_EQ(buf.size, 0);
+    EXPECT_LE(buf.capacity, 12);
+    EXPECT_EQ(target.pos, 15);
+    ASSERT_EQ(target.size, 15);
+    EXPECT_EQ(memcmp(target.space, "prepfoobarhello", 15), 0);
+}

mercurial