Refactor buffers_range:

* Add tests
* Increase code coverage
* Correct behavior for default constructed iterators
This commit is contained in:
Vinnie Falco
2018-12-14 20:07:24 -08:00
parent 117dda7b31
commit ca728e4022
3 changed files with 61 additions and 8 deletions

View File

@ -4,6 +4,7 @@ Version 200
* Tidy up msvc-14 workaround in multi_buffer
* buffers_cat fixes and coverage
* Refactor buffers_adaptor
* Refactor buffers_range
API Changes:

View File

@ -46,9 +46,13 @@ public:
buffer_sequence_iterator<BufferSequence>::type;
iter_type it_;
buffers_range_adaptor const* b_ = nullptr;
const_iterator(iter_type const& it)
const_iterator(
buffers_range_adaptor const& b,
iter_type const& it)
: it_(it)
, b_(&b)
{
}
@ -60,17 +64,19 @@ public:
using difference_type = std::ptrdiff_t;
using iterator_category =
std::bidirectional_iterator_tag;
const_iterator() = default;
bool
operator==(const_iterator const& other) const
{
return it_ == other.it_;
return b_ == other.b_ && it_ == other.it_;
}
bool
operator!=(const_iterator const& other) const
{
return ! (*this == other);
return !(*this == other);
}
reference
@ -97,7 +103,6 @@ public:
return temp;
}
// deprecated
const_iterator&
operator--()
{
@ -105,7 +110,6 @@ public:
return *this;
}
// deprecated
const_iterator
operator--(int)
{
@ -121,16 +125,21 @@ public:
{
}
buffers_range_adaptor(
buffers_range_adaptor const&) = default;
buffers_range_adaptor& operator=(
buffers_range_adaptor const&) = default;
const_iterator
begin() const noexcept
{
return net::buffer_sequence_begin(b_);
return {*this, net::buffer_sequence_begin(b_)};
}
const_iterator
end() const noexcept
{
return net::buffer_sequence_end(b_);
return {*this, net::buffer_sequence_end(b_)};
}
};

View File

@ -9,3 +9,46 @@
// Test that header file is self-contained.
#include <boost/beast/core/buffers_range.hpp>
#include "buffer_test.hpp"
#include <boost/beast/_experimental/unit_test/suite.hpp>
namespace boost {
namespace beast {
class buffers_range_test : public beast::unit_test::suite
{
public:
BOOST_STATIC_ASSERT(
net::is_mutable_buffer_sequence<
decltype(beast::buffers_range(
std::declval<net::mutable_buffer>()))>::value);
void
testBufferSequence()
{
{
string_view s = "Hello, world!";
test_buffer_sequence(*this, buffers_range(
net::const_buffer{s.data(), s.size()}));
}
{
char buf[13];
test_buffer_sequence(*this,
buffers_range(net::mutable_buffer{
buf, sizeof(buf)}));
}
}
void
run() override
{
testBufferSequence();
}
};
BEAST_DEFINE_TESTSUITE(beast,core,buffers_range);
} // beast
} // boost