Sun, 01 May 2022 16:48:26 +0200
#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); +}