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 417cfb1
Show file tree
Hide file tree
Showing 2 changed files with 10 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

0 comments on commit 417cfb1

Please sign in to comment.