buffers_cat fixes and coverage:

* Fix operator== for default constructed iterators
* More tests and code coverage
This commit is contained in:
Vinnie Falco
2018-12-14 07:21:17 -08:00
parent ad2cdf0281
commit c1d7a83af2
5 changed files with 107 additions and 38 deletions

View File

@ -2,6 +2,7 @@ Version 200
* Don't include OpenSSL for core snippets
* Tidy up msvc-14 workaround in multi_buffer
* buffers_cat fixes and coverage
--------------------------------------------------------------------------------

View File

@ -18,7 +18,6 @@ namespace boost {
namespace beast {
namespace detail {
// This simple variant gets the job done without
// causing too much trouble with template depth:
//

View File

@ -170,6 +170,7 @@ private:
reference
operator()(mp11::mp_size_t<0>)
{
// Dereferencing a default-constructed iterator
BOOST_THROW_EXCEPTION(std::logic_error{
"invalid iterator"});
}
@ -279,11 +280,11 @@ operator==(const_iterator const& other) const
(bn_ == nullptr) ?
(
other.bn_ == nullptr ||
other.it_.index() == sizeof...(Bn)
other.it_.index() == sizeof...(Bn) + 1
):(
(other.bn_ == nullptr) ?
(
it_.index() == sizeof...(Bn)
it_.index() == sizeof...(Bn) + 1
): (
bn_ == other.bn_ &&
it_ == other.it_

View File

@ -215,6 +215,64 @@ public:
decltype(bs)::const_iterator it;
decltype(bs2)::const_iterator 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
@ -309,6 +367,7 @@ public:
testBufferCat();
testIterators();
testDefaultIterators();
testGccWarning1();
testGccWarning2();
test_empty_buffer_sequences();

View File

@ -125,40 +125,6 @@ public:
#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()
{
{
@ -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
{
testMatrix<net::const_buffer>();
testMatrix<net::mutable_buffer>();
testEmptyBuffers();
testIterator();
testInPlaceInit();
testIterators();
testDefaultIterators();
}
};