Skip to content

Commit

Permalink
stream::capacity() has coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
cmazakas committed Apr 10, 2024
1 parent d502b88 commit abc6d64
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions test/unit/serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> s; // stores complete output

Expand All @@ -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 = [&](
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions toolchain.cmake
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit abc6d64

Please sign in to comment.