mirror of
https://github.com/boostorg/beast.git
synced 2025-07-30 21:07:26 +02:00
buffers_cat fixes and coverage:
* Fix operator== for default constructed iterators * More tests and code coverage
This commit is contained in:
@ -2,6 +2,7 @@ Version 200
|
|||||||
|
|
||||||
* Don't include OpenSSL for core snippets
|
* Don't include OpenSSL for core snippets
|
||||||
* Tidy up msvc-14 workaround in multi_buffer
|
* Tidy up msvc-14 workaround in multi_buffer
|
||||||
|
* buffers_cat fixes and coverage
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ namespace boost {
|
|||||||
namespace beast {
|
namespace beast {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
|
|
||||||
// This simple variant gets the job done without
|
// This simple variant gets the job done without
|
||||||
// causing too much trouble with template depth:
|
// causing too much trouble with template depth:
|
||||||
//
|
//
|
||||||
|
@ -170,6 +170,7 @@ private:
|
|||||||
reference
|
reference
|
||||||
operator()(mp11::mp_size_t<0>)
|
operator()(mp11::mp_size_t<0>)
|
||||||
{
|
{
|
||||||
|
// Dereferencing a default-constructed iterator
|
||||||
BOOST_THROW_EXCEPTION(std::logic_error{
|
BOOST_THROW_EXCEPTION(std::logic_error{
|
||||||
"invalid iterator"});
|
"invalid iterator"});
|
||||||
}
|
}
|
||||||
@ -279,11 +280,11 @@ operator==(const_iterator const& other) const
|
|||||||
(bn_ == nullptr) ?
|
(bn_ == nullptr) ?
|
||||||
(
|
(
|
||||||
other.bn_ == nullptr ||
|
other.bn_ == nullptr ||
|
||||||
other.it_.index() == sizeof...(Bn)
|
other.it_.index() == sizeof...(Bn) + 1
|
||||||
):(
|
):(
|
||||||
(other.bn_ == nullptr) ?
|
(other.bn_ == nullptr) ?
|
||||||
(
|
(
|
||||||
it_.index() == sizeof...(Bn)
|
it_.index() == sizeof...(Bn) + 1
|
||||||
): (
|
): (
|
||||||
bn_ == other.bn_ &&
|
bn_ == other.bn_ &&
|
||||||
it_ == other.it_
|
it_ == other.it_
|
||||||
|
@ -215,6 +215,64 @@ public:
|
|||||||
decltype(bs)::const_iterator it;
|
decltype(bs)::const_iterator it;
|
||||||
decltype(bs2)::const_iterator it2;
|
decltype(bs2)::const_iterator it2;
|
||||||
BEAST_EXPECT(it == it2);
|
BEAST_EXPECT(it == it2);
|
||||||
|
|
||||||
|
// decrement begin() should throw
|
||||||
|
try
|
||||||
|
{
|
||||||
|
--bs.begin();
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
catch(std::logic_error const&)
|
||||||
|
{
|
||||||
|
pass();
|
||||||
|
}
|
||||||
|
catch(...)
|
||||||
|
{
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
testDefaultIterators()
|
||||||
|
{
|
||||||
|
// default ctor is one past the end
|
||||||
|
char c[2];
|
||||||
|
auto bs = buffers_cat(
|
||||||
|
net::const_buffer(&c[0], 1),
|
||||||
|
net::const_buffer(&c[1], 1));
|
||||||
|
decltype(bs)::const_iterator it;
|
||||||
|
BEAST_EXPECT(bs.end() == it);
|
||||||
|
BEAST_EXPECT(it == bs.end());
|
||||||
|
decltype(bs)::const_iterator it2;
|
||||||
|
BEAST_EXPECT(it == it2);
|
||||||
|
BEAST_EXPECT(it2 == it);
|
||||||
|
it = bs.end();
|
||||||
|
it2 = bs.end();
|
||||||
|
BEAST_EXPECT(it == it2);
|
||||||
|
BEAST_EXPECT(it2 == it);
|
||||||
|
decltype(bs)::const_iterator it3(it2);
|
||||||
|
BEAST_EXPECT(it3 == it2);
|
||||||
|
it = bs.begin();
|
||||||
|
BEAST_EXPECT(it != it3);
|
||||||
|
it = it3;
|
||||||
|
BEAST_EXPECT(it == it3);
|
||||||
|
|
||||||
|
// dereferencing default iterator should throw
|
||||||
|
try
|
||||||
|
{
|
||||||
|
it = {};
|
||||||
|
*it;
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
catch(std::logic_error const&)
|
||||||
|
{
|
||||||
|
pass();
|
||||||
|
}
|
||||||
|
catch(...)
|
||||||
|
{
|
||||||
|
fail();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -309,6 +367,7 @@ public:
|
|||||||
|
|
||||||
testBufferCat();
|
testBufferCat();
|
||||||
testIterators();
|
testIterators();
|
||||||
|
testDefaultIterators();
|
||||||
testGccWarning1();
|
testGccWarning1();
|
||||||
testGccWarning2();
|
testGccWarning2();
|
||||||
test_empty_buffer_sequences();
|
test_empty_buffer_sequences();
|
||||||
|
@ -125,40 +125,6 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void testIterator()
|
|
||||||
{
|
|
||||||
using net::buffer_size;
|
|
||||||
using net::const_buffer;
|
|
||||||
char b[3];
|
|
||||||
std::array<const_buffer, 3> bs{{
|
|
||||||
const_buffer{&b[0], 1},
|
|
||||||
const_buffer{&b[1], 1},
|
|
||||||
const_buffer{&b[2], 1}}};
|
|
||||||
auto pb = buffers_prefix(2, bs);
|
|
||||||
BEAST_EXPECT(bsize1(pb) == 2);
|
|
||||||
BEAST_EXPECT(bsize2(pb) == 2);
|
|
||||||
BEAST_EXPECT(bsize3(pb) == 2);
|
|
||||||
BEAST_EXPECT(bsize4(pb) == 2);
|
|
||||||
|
|
||||||
// default ctor is one past the end
|
|
||||||
decltype(pb)::const_iterator it;
|
|
||||||
BEAST_EXPECT(pb.end() == it);
|
|
||||||
BEAST_EXPECT(it == pb.end());
|
|
||||||
decltype(pb)::const_iterator it2;
|
|
||||||
BEAST_EXPECT(it == it2);
|
|
||||||
BEAST_EXPECT(it2 == it);
|
|
||||||
it = pb.end();
|
|
||||||
it2 = pb.end();
|
|
||||||
BEAST_EXPECT(it == it2);
|
|
||||||
BEAST_EXPECT(it2 == it);
|
|
||||||
decltype(pb)::const_iterator it3(it2);
|
|
||||||
BEAST_EXPECT(it3 == it2);
|
|
||||||
it = pb.begin();
|
|
||||||
BEAST_EXPECT(it != it3);
|
|
||||||
it = it3;
|
|
||||||
BEAST_EXPECT(it == it3);
|
|
||||||
}
|
|
||||||
|
|
||||||
void testInPlaceInit()
|
void testInPlaceInit()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
@ -208,13 +174,56 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testIterators()
|
||||||
|
{
|
||||||
|
char b[3];
|
||||||
|
std::array<net::const_buffer, 3> bs{{
|
||||||
|
net::const_buffer{&b[0], 1},
|
||||||
|
net::const_buffer{&b[1], 1},
|
||||||
|
net::const_buffer{&b[2], 1}}};
|
||||||
|
auto pb = buffers_prefix(2, bs);
|
||||||
|
BEAST_EXPECT(bsize1(pb) == 2);
|
||||||
|
BEAST_EXPECT(bsize2(pb) == 2);
|
||||||
|
BEAST_EXPECT(bsize3(pb) == 2);
|
||||||
|
BEAST_EXPECT(bsize4(pb) == 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
testDefaultIterators()
|
||||||
|
{
|
||||||
|
// default ctor is one past the end
|
||||||
|
char b[3];
|
||||||
|
std::array<net::const_buffer, 3> bs{{
|
||||||
|
net::const_buffer{&b[0], 1},
|
||||||
|
net::const_buffer{&b[1], 1},
|
||||||
|
net::const_buffer{&b[2], 1}}};
|
||||||
|
auto pb = buffers_prefix(2, bs);
|
||||||
|
decltype(pb)::const_iterator it;
|
||||||
|
BEAST_EXPECT(pb.end() == it);
|
||||||
|
BEAST_EXPECT(it == pb.end());
|
||||||
|
decltype(pb)::const_iterator it2;
|
||||||
|
BEAST_EXPECT(it == it2);
|
||||||
|
BEAST_EXPECT(it2 == it);
|
||||||
|
it = pb.end();
|
||||||
|
it2 = pb.end();
|
||||||
|
BEAST_EXPECT(it == it2);
|
||||||
|
BEAST_EXPECT(it2 == it);
|
||||||
|
decltype(pb)::const_iterator it3(it2);
|
||||||
|
BEAST_EXPECT(it3 == it2);
|
||||||
|
it = pb.begin();
|
||||||
|
BEAST_EXPECT(it != it3);
|
||||||
|
it = it3;
|
||||||
|
BEAST_EXPECT(it == it3);
|
||||||
|
}
|
||||||
|
|
||||||
void run() override
|
void run() override
|
||||||
{
|
{
|
||||||
testMatrix<net::const_buffer>();
|
testMatrix<net::const_buffer>();
|
||||||
testMatrix<net::mutable_buffer>();
|
testMatrix<net::mutable_buffer>();
|
||||||
testEmptyBuffers();
|
testEmptyBuffers();
|
||||||
testIterator();
|
|
||||||
testInPlaceInit();
|
testInPlaceInit();
|
||||||
|
testIterators();
|
||||||
|
testDefaultIterators();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user