# HG changeset patch # User Mike Becker # Date 1651416506 -7200 # Node ID 900795d59d030d0389f7e74c15a36280345c1f87 # Parent 3700ac4bd9a3a342365e3216c8ffed3b11e4f0e4 #184 #170 flush at threshold test diff -r 3700ac4bd9a3 -r 900795d59d03 test/test_buffer.cpp --- 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); +}