From abc6d64f4c8780808943e11df8fa2e72e1c02d89 Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Wed, 10 Apr 2024 11:43:52 -0700 Subject: [PATCH] stream::capacity() has coverage --- src/serializer.cpp | 6 +----- test/unit/serializer.cpp | 9 +++++++++ toolchain.cmake | 5 +++++ 3 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 toolchain.cmake diff --git a/src/serializer.cpp b/src/serializer.cpp index e0727916..5fb6633d 100644 --- a/src/serializer.cpp +++ b/src/serializer.cpp @@ -542,11 +542,7 @@ serializer:: stream:: capacity() const { - auto const n = - chunked_overhead_ + - 2 + // CRLF - 5; // final chunk - return sr_->tmp0_.capacity() - n; // VFALCO ? + return sr_->tmp0_.capacity(); } std::size_t diff --git a/test/unit/serializer.cpp b/test/unit/serializer.cpp index 1302553f..bfbfd304 100644 --- a/test/unit/serializer.cpp +++ b/test/unit/serializer.cpp @@ -274,6 +274,9 @@ struct serializer_test serializer sr(sr_capacity); auto stream = sr.start_stream(res); + BOOST_TEST_EQ(stream.size(), 0); + BOOST_TEST_GT(stream.capacity(), 0); + BOOST_TEST_LE(stream.capacity(), sr_capacity); std::vector s; // stores complete output @@ -292,6 +295,11 @@ struct serializer_test stream.commit(bs); body.remove_prefix(bs); + if(! res.chunked() ) + BOOST_TEST_EQ(stream.size(), bs); + else + // chunk overhead: header + \r\n + BOOST_TEST_EQ(stream.size(), bs + 18 + 2); }; auto consume_body_buffer = [&]( @@ -339,6 +347,7 @@ struct serializer_test for(auto pos = cbs.begin(); pos != end; ++pos) consume_body_buffer(*pos); + BOOST_TEST_EQ(stream.size(), 0); } BOOST_TEST_THROWS(stream.close(), std::logic_error); diff --git a/toolchain.cmake b/toolchain.cmake new file mode 100644 index 00000000..62980ed5 --- /dev/null +++ b/toolchain.cmake @@ -0,0 +1,5 @@ +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_FLAGS_INIT "-Wall -Wextra --coverage") +set(BUILD_TESTING ON) +set(CMAKE_EXE_LINKER_FLAGS_INIT "--coverage") +# add_link_options("--coverage")