mirror of
https://github.com/boostorg/beast.git
synced 2025-07-29 20:37:31 +02:00
@ -1,3 +1,9 @@
|
||||
Version 169:
|
||||
|
||||
* Use buffers_to_string in tests
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
Version 168:
|
||||
|
||||
* Use executor_work_guard in composed operations
|
||||
|
@ -41,6 +41,7 @@ namespace beast {
|
||||
@endcode
|
||||
*/
|
||||
template<class ConstBufferSequence>
|
||||
inline
|
||||
std::string
|
||||
buffers_to_string(ConstBufferSequence const& buffers)
|
||||
{
|
||||
|
@ -10,6 +10,7 @@
|
||||
#ifndef BOOST_BEAST_TEST_BUFFER_TEST_HPP
|
||||
#define BOOST_BEAST_TEST_BUFFER_TEST_HPP
|
||||
|
||||
#include <boost/beast/core/buffers_to_string.hpp>
|
||||
#include <boost/beast/core/string.hpp>
|
||||
#include <boost/beast/core/read_size.hpp>
|
||||
#include <boost/beast/core/type_traits.hpp>
|
||||
@ -23,20 +24,6 @@ namespace boost {
|
||||
namespace beast {
|
||||
namespace test {
|
||||
|
||||
template<class ConstBufferSequence>
|
||||
typename std::enable_if<
|
||||
boost::asio::is_const_buffer_sequence<ConstBufferSequence>::value,
|
||||
std::string>::type
|
||||
to_string(ConstBufferSequence const& bs)
|
||||
{
|
||||
std::string s;
|
||||
s.reserve(buffer_size(bs));
|
||||
for(auto b : beast::detail::buffers_range(bs))
|
||||
s.append(reinterpret_cast<char const*>(b.data()),
|
||||
b.size());
|
||||
return s;
|
||||
}
|
||||
|
||||
template<class DynamicBuffer>
|
||||
void
|
||||
write_buffer(DynamicBuffer& b, string_view s)
|
||||
|
@ -24,19 +24,6 @@ namespace beast {
|
||||
class buffers_adapter_test : public unit_test::suite
|
||||
{
|
||||
public:
|
||||
template<class ConstBufferSequence>
|
||||
static
|
||||
std::string
|
||||
to_string(ConstBufferSequence const& bs)
|
||||
{
|
||||
std::string s;
|
||||
s.reserve(boost::asio::buffer_size(bs));
|
||||
for(auto b : beast::detail::buffers_range(bs))
|
||||
s.append(reinterpret_cast<
|
||||
char const*>(b.data()), b.size());
|
||||
return s;
|
||||
}
|
||||
|
||||
void testBuffersAdapter()
|
||||
{
|
||||
using boost::asio::buffer;
|
||||
@ -124,17 +111,17 @@ public:
|
||||
BEAST_EXPECT(ba.size() == x + y + z);
|
||||
BEAST_EXPECT(ba.max_size() == 0);
|
||||
BEAST_EXPECT(buffer_size(ba.data()) == ba.size());
|
||||
BEAST_EXPECT(to_string(ba.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(ba.data()) == s);
|
||||
ba.consume(t);
|
||||
{
|
||||
auto d = ba.prepare(0);
|
||||
BEAST_EXPECT(buffer_size(d) == 0);
|
||||
}
|
||||
BEAST_EXPECT(to_string(ba.data()) == s.substr(t, std::string::npos));
|
||||
BEAST_EXPECT(buffers_to_string(ba.data()) == s.substr(t, std::string::npos));
|
||||
ba.consume(u);
|
||||
BEAST_EXPECT(to_string(ba.data()) == s.substr(t + u, std::string::npos));
|
||||
BEAST_EXPECT(buffers_to_string(ba.data()) == s.substr(t + u, std::string::npos));
|
||||
ba.consume(v);
|
||||
BEAST_EXPECT(to_string(ba.data()) == "");
|
||||
BEAST_EXPECT(buffers_to_string(ba.data()) == "");
|
||||
ba.consume(1);
|
||||
{
|
||||
auto d = ba.prepare(0);
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <boost/beast/core/buffers_prefix.hpp>
|
||||
|
||||
#include <boost/beast/core/buffers_suffix.hpp>
|
||||
#include <boost/beast/core/buffers_to_string.hpp>
|
||||
#include <boost/beast/core/type_traits.hpp>
|
||||
#include <boost/beast/unit_test/suite.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
@ -88,19 +89,6 @@ public:
|
||||
return n;
|
||||
}
|
||||
|
||||
template<class ConstBufferSequence>
|
||||
static
|
||||
std::string
|
||||
to_string(ConstBufferSequence const& bs)
|
||||
{
|
||||
std::string s;
|
||||
s.reserve(buffer_size(bs));
|
||||
for(auto b : beast::detail::buffers_range(bs))
|
||||
s.append(reinterpret_cast<char const*>(b.data()),
|
||||
b.size());
|
||||
return s;
|
||||
}
|
||||
|
||||
template<class BufferType>
|
||||
void testMatrix()
|
||||
{
|
||||
@ -118,14 +106,14 @@ public:
|
||||
for(std::size_t i = 0; i <= s.size() + 1; ++i)
|
||||
{
|
||||
auto pb = buffers_prefix(i, bs);
|
||||
BEAST_EXPECT(to_string(pb) == s.substr(0, i));
|
||||
BEAST_EXPECT(buffers_to_string(pb) == s.substr(0, i));
|
||||
auto pb2 = pb;
|
||||
BEAST_EXPECT(to_string(pb2) == to_string(pb));
|
||||
BEAST_EXPECT(buffers_to_string(pb2) == buffers_to_string(pb));
|
||||
pb = buffers_prefix(0, bs);
|
||||
pb2 = pb;
|
||||
BEAST_EXPECT(buffer_size(pb2) == 0);
|
||||
pb2 = buffers_prefix(i, bs);
|
||||
BEAST_EXPECT(to_string(pb2) == s.substr(0, i));
|
||||
BEAST_EXPECT(buffers_to_string(pb2) == s.substr(0, i));
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
@ -40,7 +40,7 @@ public:
|
||||
eq(Buffers1 const& lhs, Buffers2 const& rhs)
|
||||
{
|
||||
using namespace test;
|
||||
return to_string(lhs) == to_string(rhs);
|
||||
return buffers_to_string(lhs) == buffers_to_string(rhs);
|
||||
}
|
||||
|
||||
template<class ConstBufferSequence>
|
||||
@ -77,7 +77,7 @@ public:
|
||||
std::string const s = "Hello, world";
|
||||
BEAST_EXPECT(s.size() == sizeof(buf));
|
||||
buffer_copy(buffer(buf), buffer(s));
|
||||
BEAST_EXPECT(to_string(buffer(buf)) == s);
|
||||
BEAST_EXPECT(buffers_to_string(buffer(buf)) == s);
|
||||
for(std::size_t i = 1; i < 4; ++i) {
|
||||
for(std::size_t j = 1; j < 4; ++j) {
|
||||
for(std::size_t x = 1; x < 4; ++x) {
|
||||
@ -90,23 +90,23 @@ public:
|
||||
const_buffer{&buf[i], j},
|
||||
const_buffer{&buf[i+j], k}}};
|
||||
buffers_suffix<decltype(bs)> cb(bs);
|
||||
BEAST_EXPECT(to_string(cb) == s);
|
||||
BEAST_EXPECT(buffers_to_string(cb) == s);
|
||||
expect_size(s.size(), cb);
|
||||
cb.consume(0);
|
||||
BEAST_EXPECT(eq(cb, consumed_buffers(bs, 0)));
|
||||
BEAST_EXPECT(to_string(cb) == s);
|
||||
BEAST_EXPECT(buffers_to_string(cb) == s);
|
||||
expect_size(s.size(), cb);
|
||||
cb.consume(x);
|
||||
BEAST_EXPECT(to_string(cb) == s.substr(x));
|
||||
BEAST_EXPECT(buffers_to_string(cb) == s.substr(x));
|
||||
BEAST_EXPECT(eq(cb, consumed_buffers(bs, x)));
|
||||
cb.consume(y);
|
||||
BEAST_EXPECT(to_string(cb) == s.substr(x+y));
|
||||
BEAST_EXPECT(buffers_to_string(cb) == s.substr(x+y));
|
||||
BEAST_EXPECT(eq(cb, consumed_buffers(bs, x+y)));
|
||||
cb.consume(z);
|
||||
BEAST_EXPECT(to_string(cb) == "");
|
||||
BEAST_EXPECT(buffers_to_string(cb) == "");
|
||||
BEAST_EXPECT(eq(cb, consumed_buffers(bs, x+y+z)));
|
||||
cb.consume(1);
|
||||
BEAST_EXPECT(to_string(cb) == "");
|
||||
BEAST_EXPECT(buffers_to_string(cb) == "");
|
||||
BEAST_EXPECT(eq(cb, consumed_buffers(bs, x+y+z)));
|
||||
}
|
||||
}}}}
|
||||
@ -126,7 +126,7 @@ public:
|
||||
};
|
||||
|
||||
buffers_suffix<test_buffer> cb;
|
||||
BEAST_EXPECT(to_string(cb) == "\r\n");
|
||||
BEAST_EXPECT(buffers_to_string(cb) == "\r\n");
|
||||
}
|
||||
|
||||
void
|
||||
@ -139,7 +139,7 @@ public:
|
||||
boost::in_place_init,
|
||||
boost::asio::const_buffer("\r", 1),
|
||||
boost::asio::const_buffer("\n", 1));
|
||||
BEAST_EXPECT(to_string(cb) == "\r\n");
|
||||
BEAST_EXPECT(buffers_to_string(cb) == "\r\n");
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -76,7 +76,7 @@ public:
|
||||
BEAST_EXPECT(b2.get_allocator()->nmove == 1);
|
||||
BEAST_EXPECT(b1.size() == 0);
|
||||
BEAST_EXPECT(b1.capacity() == 0);
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(b1.max_size() == b2.max_size());
|
||||
}
|
||||
{
|
||||
@ -86,7 +86,7 @@ public:
|
||||
basic_flat_buffer<a_t> b2{std::move(b1), a};
|
||||
BEAST_EXPECT(b1.size() == 0);
|
||||
BEAST_EXPECT(b1.capacity() == 0);
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(b1.max_size() == b2.max_size());
|
||||
}
|
||||
{
|
||||
@ -96,7 +96,7 @@ public:
|
||||
basic_flat_buffer<a_neq_t> b2{std::move(b1), a};
|
||||
BEAST_EXPECT(b1.size() == 0);
|
||||
BEAST_EXPECT(b1.capacity() == 0);
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(b1.max_size() == b2.max_size());
|
||||
}
|
||||
}
|
||||
@ -107,8 +107,8 @@ public:
|
||||
ostream(b1) << "Hello";
|
||||
basic_flat_buffer<a_t> b2(b1);
|
||||
BEAST_EXPECT(b1.get_allocator() == b2.get_allocator());
|
||||
BEAST_EXPECT(to_string(b1.data()) == "Hello");
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b1.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
}
|
||||
{
|
||||
basic_flat_buffer<a_neq_t> b1;
|
||||
@ -116,15 +116,15 @@ public:
|
||||
a_neq_t a;
|
||||
basic_flat_buffer<a_neq_t> b2(b1, a);
|
||||
BEAST_EXPECT(b1.get_allocator() != b2.get_allocator());
|
||||
BEAST_EXPECT(to_string(b1.data()) == "Hello");
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b1.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
}
|
||||
{
|
||||
basic_flat_buffer<a_t> b1;
|
||||
ostream(b1) << "Hello";
|
||||
basic_flat_buffer<a_neq_t> b2(b1);
|
||||
BEAST_EXPECT(to_string(b1.data()) == "Hello");
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b1.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
}
|
||||
{
|
||||
basic_flat_buffer<a_neq_t> b1;
|
||||
@ -132,8 +132,8 @@ public:
|
||||
a_t a;
|
||||
basic_flat_buffer<a_t> b2(b1, a);
|
||||
BEAST_EXPECT(b2.get_allocator() == a);
|
||||
BEAST_EXPECT(to_string(b1.data()) == "Hello");
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b1.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
}
|
||||
|
||||
// move assignment
|
||||
@ -145,7 +145,7 @@ public:
|
||||
b2 = std::move(b1);
|
||||
BEAST_EXPECT(b1.size() == 0);
|
||||
BEAST_EXPECT(b1.capacity() == 0);
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
}
|
||||
{
|
||||
using na_t = test::test_allocator<char,
|
||||
@ -157,7 +157,7 @@ public:
|
||||
BEAST_EXPECT(b1.get_allocator() == b2.get_allocator());
|
||||
BEAST_EXPECT(b1.size() == 0);
|
||||
BEAST_EXPECT(b1.capacity() == 0);
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
}
|
||||
{
|
||||
using na_t = test::test_allocator<char,
|
||||
@ -169,7 +169,7 @@ public:
|
||||
BEAST_EXPECT(b1.get_allocator() != b2.get_allocator());
|
||||
BEAST_EXPECT(b1.size() == 0);
|
||||
BEAST_EXPECT(b1.capacity() == 0);
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
}
|
||||
{
|
||||
// propagate_on_container_move_assignment : true
|
||||
@ -180,7 +180,7 @@ public:
|
||||
basic_flat_buffer<pocma_t> b2;
|
||||
b2 = std::move(b1);
|
||||
BEAST_EXPECT(b1.size() == 0);
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
}
|
||||
{
|
||||
// propagate_on_container_move_assignment : false
|
||||
@ -191,7 +191,7 @@ public:
|
||||
basic_flat_buffer<pocma_t> b2;
|
||||
b2 = std::move(b1);
|
||||
BEAST_EXPECT(b1.size() == 0);
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,11 +202,11 @@ public:
|
||||
ostream(b1) << "Hello";
|
||||
flat_buffer b2;
|
||||
b2 = b1;
|
||||
BEAST_EXPECT(to_string(b1.data()) == "Hello");
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b1.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
basic_flat_buffer<a_t> b3;
|
||||
b3 = b2;
|
||||
BEAST_EXPECT(to_string(b3.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b3.data()) == "Hello");
|
||||
}
|
||||
{
|
||||
// propagate_on_container_copy_assignment : true
|
||||
@ -216,7 +216,7 @@ public:
|
||||
ostream(b1) << "Hello";
|
||||
basic_flat_buffer<pocca_t> b2;
|
||||
b2 = b1;
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
}
|
||||
{
|
||||
// propagate_on_container_copy_assignment : false
|
||||
@ -226,7 +226,7 @@ public:
|
||||
ostream(b1) << "Hello";
|
||||
basic_flat_buffer<pocca_t> b2;
|
||||
b2 = b1;
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
}
|
||||
}
|
||||
|
||||
@ -238,19 +238,19 @@ public:
|
||||
BEAST_EXPECT(b1.max_size() == 64);
|
||||
BEAST_EXPECT(b1.capacity() == 0);
|
||||
ostream(b1) << s;
|
||||
BEAST_EXPECT(to_string(b1.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b1.data()) == s);
|
||||
{
|
||||
flat_buffer b2{b1};
|
||||
BEAST_EXPECT(to_string(b2.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == s);
|
||||
b2.consume(7);
|
||||
BEAST_EXPECT(to_string(b2.data()) == s.substr(7));
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == s.substr(7));
|
||||
}
|
||||
{
|
||||
flat_buffer b2{64};
|
||||
b2 = b1;
|
||||
BEAST_EXPECT(to_string(b2.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == s);
|
||||
b2.consume(7);
|
||||
BEAST_EXPECT(to_string(b2.data()) == s.substr(7));
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == s.substr(7));
|
||||
}
|
||||
}
|
||||
|
||||
@ -260,7 +260,7 @@ public:
|
||||
ostream(b) << "12345";
|
||||
b.consume(3);
|
||||
ostream(b) << "67890123";
|
||||
BEAST_EXPECT(to_string(b.data()) == "4567890123");
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == "4567890123");
|
||||
}
|
||||
|
||||
// read_size
|
||||
@ -288,7 +288,7 @@ public:
|
||||
BEAST_EXPECT(b1.get_allocator() != b2.get_allocator());
|
||||
BEAST_EXPECT(b1.size() == 0);
|
||||
BEAST_EXPECT(b1.capacity() == 0);
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
}
|
||||
{
|
||||
using na_t = test::test_allocator<char,
|
||||
@ -304,7 +304,7 @@ public:
|
||||
BEAST_EXPECT(b1.get_allocator() == b2.get_allocator());
|
||||
BEAST_EXPECT(b1.size() == 0);
|
||||
BEAST_EXPECT(b1.capacity() == 0);
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,17 +105,17 @@ public:
|
||||
ba.commit(2);
|
||||
BEAST_EXPECT(ba.size() == x + y + z);
|
||||
BEAST_EXPECT(buffer_size(ba.data()) == ba.size());
|
||||
BEAST_EXPECT(to_string(ba.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(ba.data()) == s);
|
||||
ba.consume(t);
|
||||
{
|
||||
auto d = ba.prepare(0);
|
||||
BEAST_EXPECT(buffer_size(d) == 0);
|
||||
}
|
||||
BEAST_EXPECT(to_string(ba.data()) == s.substr(t, std::string::npos));
|
||||
BEAST_EXPECT(buffers_to_string(ba.data()) == s.substr(t, std::string::npos));
|
||||
ba.consume(u);
|
||||
BEAST_EXPECT(to_string(ba.data()) == s.substr(t + u, std::string::npos));
|
||||
BEAST_EXPECT(buffers_to_string(ba.data()) == s.substr(t + u, std::string::npos));
|
||||
ba.consume(v);
|
||||
BEAST_EXPECT(to_string(ba.data()) == "");
|
||||
BEAST_EXPECT(buffers_to_string(ba.data()) == "");
|
||||
ba.consume(1);
|
||||
{
|
||||
auto d = ba.prepare(0);
|
||||
@ -145,9 +145,9 @@ public:
|
||||
char buf[64];
|
||||
flat_static_buffer_base b{buf, sizeof(buf)};
|
||||
ostream(b) << s;
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
b.consume(b.size());
|
||||
BEAST_EXPECT(to_string(b.data()) == "");
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == "");
|
||||
}
|
||||
|
||||
// flat_static_buffer
|
||||
@ -157,19 +157,19 @@ public:
|
||||
BEAST_EXPECT(b1.max_size() == 64);
|
||||
BEAST_EXPECT(b1.capacity() == 64);
|
||||
ostream(b1) << s;
|
||||
BEAST_EXPECT(to_string(b1.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b1.data()) == s);
|
||||
{
|
||||
flat_static_buffer<64> b2{b1};
|
||||
BEAST_EXPECT(to_string(b2.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == s);
|
||||
b2.consume(7);
|
||||
BEAST_EXPECT(to_string(b2.data()) == s.substr(7));
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == s.substr(7));
|
||||
}
|
||||
{
|
||||
flat_static_buffer<64> b2;
|
||||
b2 = b1;
|
||||
BEAST_EXPECT(to_string(b2.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == s);
|
||||
b2.consume(7);
|
||||
BEAST_EXPECT(to_string(b2.data()) == s.substr(7));
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == s.substr(7));
|
||||
}
|
||||
}
|
||||
|
||||
@ -179,7 +179,7 @@ public:
|
||||
write_buffer(b, "12345");
|
||||
b.consume(3);
|
||||
write_buffer(b, "67890123");
|
||||
BEAST_EXPECT(to_string(b.data()) == "4567890123");
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == "4567890123");
|
||||
try
|
||||
{
|
||||
b.prepare(1);
|
||||
|
@ -38,8 +38,8 @@ public:
|
||||
eq(basic_multi_buffer<Alloc1> const& mb1,
|
||||
basic_multi_buffer<Alloc2> const& mb2)
|
||||
{
|
||||
return test::to_string(mb1.data()) ==
|
||||
test::to_string(mb2.data());
|
||||
return buffers_to_string(mb1.data()) ==
|
||||
buffers_to_string(mb2.data());
|
||||
}
|
||||
|
||||
template<class ConstBufferSequence>
|
||||
@ -76,7 +76,7 @@ public:
|
||||
b.commit(buffer_copy(b.prepare(x), buffer(s.data(), x)));
|
||||
b.commit(buffer_copy(b.prepare(y), buffer(s.data()+x, y)));
|
||||
b.commit(buffer_copy(b.prepare(z), buffer(s.data()+x+y, z)));
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
{
|
||||
multi_buffer mb2{b};
|
||||
BEAST_EXPECT(eq(b, mb2));
|
||||
@ -88,16 +88,16 @@ public:
|
||||
}
|
||||
{
|
||||
multi_buffer mb2{std::move(b)};
|
||||
BEAST_EXPECT(to_string(mb2.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(mb2.data()) == s);
|
||||
expect_size(0, b.data());
|
||||
b = std::move(mb2);
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
expect_size(0, mb2.data());
|
||||
}
|
||||
self_assign(b, b);
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
self_assign(b, std::move(b));
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
}
|
||||
}}}
|
||||
}
|
||||
@ -178,17 +178,17 @@ public:
|
||||
b.commit(2);
|
||||
BEAST_EXPECT(b.size() == x + y + z);
|
||||
BEAST_EXPECT(buffer_size(b.data()) == b.size());
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
b.consume(t);
|
||||
{
|
||||
auto d = b.prepare(0);
|
||||
BEAST_EXPECT(buffer_size(d) == 0);
|
||||
}
|
||||
BEAST_EXPECT(to_string(b.data()) == s.substr(t, std::string::npos));
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s.substr(t, std::string::npos));
|
||||
b.consume(u);
|
||||
BEAST_EXPECT(to_string(b.data()) == s.substr(t + u, std::string::npos));
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s.substr(t + u, std::string::npos));
|
||||
b.consume(v);
|
||||
BEAST_EXPECT(to_string(b.data()) == "");
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == "");
|
||||
b.consume(1);
|
||||
{
|
||||
auto d = b.prepare(0);
|
||||
@ -255,7 +255,7 @@ public:
|
||||
BEAST_EXPECT(b2.get_allocator()->nmove == 1);
|
||||
BEAST_EXPECT(b1.size() == 0);
|
||||
BEAST_EXPECT(b1.capacity() == 0);
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(b1.max_size() == b2.max_size());
|
||||
}
|
||||
// allocators equal
|
||||
@ -266,7 +266,7 @@ public:
|
||||
basic_multi_buffer<equal_t> b2{std::move(b1), a};
|
||||
BEAST_EXPECT(b1.size() == 0);
|
||||
BEAST_EXPECT(b1.capacity() == 0);
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(b1.max_size() == b2.max_size());
|
||||
}
|
||||
{
|
||||
@ -277,7 +277,7 @@ public:
|
||||
basic_multi_buffer<unequal_t> b2{std::move(b1), a};
|
||||
BEAST_EXPECT(b1.size() == 0);
|
||||
BEAST_EXPECT(b1.capacity() == 0);
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(b1.max_size() == b2.max_size());
|
||||
}
|
||||
}
|
||||
@ -289,8 +289,8 @@ public:
|
||||
ostream(b1) << "Hello";
|
||||
basic_multi_buffer<equal_t> b2{b1};
|
||||
BEAST_EXPECT(b1.get_allocator() == b2.get_allocator());
|
||||
BEAST_EXPECT(to_string(b1.data()) == "Hello");
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b1.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
}
|
||||
{
|
||||
basic_multi_buffer<unequal_t> b1;
|
||||
@ -298,15 +298,15 @@ public:
|
||||
unequal_t a;
|
||||
basic_multi_buffer<unequal_t> b2(b1, a);
|
||||
BEAST_EXPECT(b1.get_allocator() != b2.get_allocator());
|
||||
BEAST_EXPECT(to_string(b1.data()) == "Hello");
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b1.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
}
|
||||
{
|
||||
basic_multi_buffer<equal_t> b1;
|
||||
ostream(b1) << "Hello";
|
||||
basic_multi_buffer<unequal_t> b2(b1);
|
||||
BEAST_EXPECT(to_string(b1.data()) == "Hello");
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b1.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
}
|
||||
{
|
||||
basic_multi_buffer<unequal_t> b1;
|
||||
@ -314,8 +314,8 @@ public:
|
||||
equal_t a;
|
||||
basic_multi_buffer<equal_t> b2(b1, a);
|
||||
BEAST_EXPECT(b2.get_allocator() == a);
|
||||
BEAST_EXPECT(to_string(b1.data()) == "Hello");
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b1.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
}
|
||||
}
|
||||
|
||||
@ -328,7 +328,7 @@ public:
|
||||
b2 = std::move(b1);
|
||||
BEAST_EXPECT(b1.size() == 0);
|
||||
BEAST_EXPECT(b1.capacity() == 0);
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
}
|
||||
{
|
||||
// propagate_on_container_move_assignment : true
|
||||
@ -339,7 +339,7 @@ public:
|
||||
basic_multi_buffer<pocma_t> b2;
|
||||
b2 = std::move(b1);
|
||||
BEAST_EXPECT(b1.size() == 0);
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
}
|
||||
{
|
||||
// propagate_on_container_move_assignment : false
|
||||
@ -350,7 +350,7 @@ public:
|
||||
basic_multi_buffer<pocma_t> b2;
|
||||
b2 = std::move(b1);
|
||||
BEAST_EXPECT(b1.size() == 0);
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
}
|
||||
}
|
||||
|
||||
@ -361,11 +361,11 @@ public:
|
||||
ostream(b1) << "Hello";
|
||||
multi_buffer b2;
|
||||
b2 = b1;
|
||||
BEAST_EXPECT(to_string(b1.data()) == "Hello");
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b1.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
basic_multi_buffer<equal_t> b3;
|
||||
b3 = b2;
|
||||
BEAST_EXPECT(to_string(b3.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b3.data()) == "Hello");
|
||||
}
|
||||
{
|
||||
// propagate_on_container_copy_assignment : true
|
||||
@ -375,7 +375,7 @@ public:
|
||||
ostream(b1) << "Hello";
|
||||
basic_multi_buffer<pocca_t> b2;
|
||||
b2 = b1;
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
}
|
||||
{
|
||||
// propagate_on_container_copy_assignment : false
|
||||
@ -385,7 +385,7 @@ public:
|
||||
ostream(b1) << "Hello";
|
||||
basic_multi_buffer<pocca_t> b2;
|
||||
b2 = b1;
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
}
|
||||
}
|
||||
|
||||
@ -410,19 +410,19 @@ public:
|
||||
BEAST_EXPECT(b1.max_size() == 64);
|
||||
BEAST_EXPECT(b1.capacity() == 0);
|
||||
ostream(b1) << s;
|
||||
BEAST_EXPECT(to_string(b1.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b1.data()) == s);
|
||||
{
|
||||
multi_buffer b2{b1};
|
||||
BEAST_EXPECT(to_string(b2.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == s);
|
||||
b2.consume(7);
|
||||
BEAST_EXPECT(to_string(b2.data()) == s.substr(7));
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == s.substr(7));
|
||||
}
|
||||
{
|
||||
multi_buffer b2{64};
|
||||
b2 = b1;
|
||||
BEAST_EXPECT(to_string(b2.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == s);
|
||||
b2.consume(7);
|
||||
BEAST_EXPECT(to_string(b2.data()) == s.substr(7));
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == s.substr(7));
|
||||
}
|
||||
}
|
||||
{
|
||||
@ -534,11 +534,11 @@ public:
|
||||
BEAST_EXPECT(b1.get_allocator() == a2);
|
||||
BEAST_EXPECT(b2.get_allocator() == a1);
|
||||
BEAST_EXPECT(b1.size() == 0);
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
swap(b1, b2);
|
||||
BEAST_EXPECT(b1.get_allocator() == a1);
|
||||
BEAST_EXPECT(b2.get_allocator() == a2);
|
||||
BEAST_EXPECT(to_string(b1.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b1.data()) == "Hello");
|
||||
BEAST_EXPECT(b2.size() == 0);
|
||||
}
|
||||
{
|
||||
@ -557,11 +557,11 @@ public:
|
||||
BEAST_EXPECT(b1.get_allocator().id() == a1.id());
|
||||
BEAST_EXPECT(b2.get_allocator().id() == a2.id());
|
||||
BEAST_EXPECT(b1.size() == 0);
|
||||
BEAST_EXPECT(to_string(b2.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
||||
swap(b1, b2);
|
||||
BEAST_EXPECT(b1.get_allocator().id() == a1.id());
|
||||
BEAST_EXPECT(b2.get_allocator().id() == a2.id());
|
||||
BEAST_EXPECT(to_string(b1.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b1.data()) == "Hello");
|
||||
BEAST_EXPECT(b2.size() == 0);
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
// Test that header file is self-contained.
|
||||
#include <boost/beast/core/ostream.hpp>
|
||||
|
||||
#include <boost/beast/core/buffers_to_string.hpp>
|
||||
#include <boost/beast/core/multi_buffer.hpp>
|
||||
#include <boost/beast/unit_test/suite.hpp>
|
||||
#include <ostream>
|
||||
@ -20,19 +21,6 @@ namespace beast {
|
||||
class ostream_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
template<class ConstBufferSequence>
|
||||
static
|
||||
std::string
|
||||
to_string(ConstBufferSequence const& bs)
|
||||
{
|
||||
std::string s;
|
||||
s.reserve(buffer_size(bs));
|
||||
for(auto b : beast::detail::buffers_range(bs))
|
||||
s.append(reinterpret_cast<
|
||||
char const*>(b.data()), b.size());
|
||||
return s;
|
||||
}
|
||||
|
||||
void
|
||||
run() override
|
||||
{
|
||||
@ -41,7 +29,7 @@ public:
|
||||
auto os = ostream(b);
|
||||
os << "Hello, world!\n";
|
||||
os.flush();
|
||||
BEAST_EXPECT(to_string(b.data()) == "Hello, world!\n");
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == "Hello, world!\n");
|
||||
auto os2 = std::move(os);
|
||||
}
|
||||
{
|
||||
@ -56,7 +44,7 @@ public:
|
||||
"0123456789abcdef" "0123456789abcdef" "0123456789abcdef" "0123456789abcdef";
|
||||
multi_buffer b;
|
||||
ostream(b) << s;
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -105,17 +105,17 @@ public:
|
||||
ba.commit(2);
|
||||
BEAST_EXPECT(ba.size() == x + y + z);
|
||||
BEAST_EXPECT(buffer_size(ba.data()) == ba.size());
|
||||
BEAST_EXPECT(to_string(ba.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(ba.data()) == s);
|
||||
ba.consume(t);
|
||||
{
|
||||
auto d = ba.prepare(0);
|
||||
BEAST_EXPECT(buffer_size(d) == 0);
|
||||
}
|
||||
BEAST_EXPECT(to_string(ba.data()) == s.substr(t, std::string::npos));
|
||||
BEAST_EXPECT(buffers_to_string(ba.data()) == s.substr(t, std::string::npos));
|
||||
ba.consume(u);
|
||||
BEAST_EXPECT(to_string(ba.data()) == s.substr(t + u, std::string::npos));
|
||||
BEAST_EXPECT(buffers_to_string(ba.data()) == s.substr(t + u, std::string::npos));
|
||||
ba.consume(v);
|
||||
BEAST_EXPECT(to_string(ba.data()) == "");
|
||||
BEAST_EXPECT(buffers_to_string(ba.data()) == "");
|
||||
ba.consume(1);
|
||||
{
|
||||
auto d = ba.prepare(0);
|
||||
@ -145,9 +145,9 @@ public:
|
||||
char buf[64];
|
||||
static_buffer_base b{buf, sizeof(buf)};
|
||||
ostream(b) << s;
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
b.consume(b.size());
|
||||
BEAST_EXPECT(to_string(b.data()) == "");
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == "");
|
||||
}
|
||||
|
||||
// static_buffer
|
||||
@ -157,19 +157,19 @@ public:
|
||||
BEAST_EXPECT(b1.max_size() == 64);
|
||||
BEAST_EXPECT(b1.capacity() == 64);
|
||||
ostream(b1) << s;
|
||||
BEAST_EXPECT(to_string(b1.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b1.data()) == s);
|
||||
{
|
||||
static_buffer<64> b2{b1};
|
||||
BEAST_EXPECT(to_string(b2.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == s);
|
||||
b2.consume(7);
|
||||
BEAST_EXPECT(to_string(b2.data()) == s.substr(7));
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == s.substr(7));
|
||||
}
|
||||
{
|
||||
static_buffer<64> b2;
|
||||
b2 = b1;
|
||||
BEAST_EXPECT(to_string(b2.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == s);
|
||||
b2.consume(7);
|
||||
BEAST_EXPECT(to_string(b2.data()) == s.substr(7));
|
||||
BEAST_EXPECT(buffers_to_string(b2.data()) == s.substr(7));
|
||||
}
|
||||
}
|
||||
|
||||
@ -179,7 +179,7 @@ public:
|
||||
write_buffer(b, "12345");
|
||||
b.consume(3);
|
||||
write_buffer(b, "67890123");
|
||||
BEAST_EXPECT(to_string(b.data()) == "4567890123");
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == "4567890123");
|
||||
try
|
||||
{
|
||||
b.prepare(1);
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
#include "message_fuzz.hpp"
|
||||
|
||||
#include <boost/beast/core/buffers_to_string.hpp>
|
||||
#include <boost/beast/core/static_string.hpp>
|
||||
#include <boost/beast/http/fields.hpp>
|
||||
#include <boost/beast/test/fuzz.hpp>
|
||||
@ -35,30 +36,16 @@ public:
|
||||
BOOST_STATIC_ASSERT(
|
||||
! detail::is_chunk_extensions<not_chunk_extensions>::value);
|
||||
|
||||
template<class ConstBufferSequence>
|
||||
static
|
||||
std::string
|
||||
to_string(ConstBufferSequence const& buffers)
|
||||
{
|
||||
std::string s;
|
||||
s.reserve(boost::asio::buffer_size(buffers));
|
||||
for(boost::asio::const_buffer b : beast::detail::buffers_range(buffers))
|
||||
s.append(
|
||||
reinterpret_cast<char const*>(b.data()),
|
||||
b.size());
|
||||
return s;
|
||||
}
|
||||
|
||||
template<class T, class... Args>
|
||||
void
|
||||
check(string_view match, Args&&... args)
|
||||
{
|
||||
T t(std::forward<Args>(args)...);
|
||||
BEAST_EXPECT(to_string(t) == match);
|
||||
BEAST_EXPECT(buffers_to_string(t) == match);
|
||||
T t2(t);
|
||||
BEAST_EXPECT(to_string(t2) == match);
|
||||
BEAST_EXPECT(buffers_to_string(t2) == match);
|
||||
T t3(std::move(t2));
|
||||
BEAST_EXPECT(to_string(t3) == match);
|
||||
BEAST_EXPECT(buffers_to_string(t3) == match);
|
||||
}
|
||||
|
||||
template<class T, class... Args>
|
||||
@ -66,11 +53,11 @@ public:
|
||||
check_fwd(string_view match, Args&&... args)
|
||||
{
|
||||
T t(std::forward<Args>(args)...);
|
||||
BEAST_EXPECT(to_string(t) == match);
|
||||
BEAST_EXPECT(buffers_to_string(t) == match);
|
||||
T t2(t);
|
||||
BEAST_EXPECT(to_string(t2) == match);
|
||||
BEAST_EXPECT(buffers_to_string(t2) == match);
|
||||
T t3(std::move(t2));
|
||||
BEAST_EXPECT(to_string(t3) == match);
|
||||
BEAST_EXPECT(buffers_to_string(t3) == match);
|
||||
}
|
||||
|
||||
using cb_t = boost::asio::const_buffer;
|
||||
|
@ -10,6 +10,7 @@
|
||||
// Test that header file is self-contained.
|
||||
#include <boost/beast/http/dynamic_body.hpp>
|
||||
|
||||
#include <boost/beast/core/buffers_to_string.hpp>
|
||||
#include <boost/beast/core/ostream.hpp>
|
||||
#include <boost/beast/http/fields.hpp>
|
||||
#include <boost/beast/http/parser.hpp>
|
||||
@ -37,19 +38,6 @@ public:
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template<class ConstBufferSequence>
|
||||
static
|
||||
std::string
|
||||
to_string(ConstBufferSequence const& bs)
|
||||
{
|
||||
std::string s;
|
||||
s.reserve(boost::asio::buffer_size(bs));
|
||||
for(auto b : beast::detail::buffers_range(bs))
|
||||
s.append(reinterpret_cast<char const*>(b.data()),
|
||||
b.size());
|
||||
return s;
|
||||
}
|
||||
|
||||
void
|
||||
run() override
|
||||
{
|
||||
@ -64,7 +52,7 @@ public:
|
||||
multi_buffer b;
|
||||
read(ts, b, p);
|
||||
auto const& m = p.get();
|
||||
BEAST_EXPECT(to_string(m.body().data()) == "xyz");
|
||||
BEAST_EXPECT(buffers_to_string(m.body().data()) == "xyz");
|
||||
BEAST_EXPECT(to_string(m) == s);
|
||||
}
|
||||
};
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <boost/beast/http/message.hpp>
|
||||
#include <boost/beast/http/read.hpp>
|
||||
#include <boost/beast/http/string_body.hpp>
|
||||
#include <boost/beast/core/buffers_to_string.hpp>
|
||||
#include <boost/beast/core/error.hpp>
|
||||
#include <boost/beast/core/multi_buffer.hpp>
|
||||
#include <boost/beast/test/stream.hpp>
|
||||
@ -264,19 +265,6 @@ public:
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template<class ConstBufferSequence>
|
||||
static
|
||||
std::string
|
||||
to_string(ConstBufferSequence const& bs)
|
||||
{
|
||||
std::string s;
|
||||
s.reserve(buffer_size(bs));
|
||||
for(auto b : beast::detail::buffers_range(bs))
|
||||
s.append(reinterpret_cast<char const*>(b),
|
||||
b.size());
|
||||
return s;
|
||||
}
|
||||
|
||||
template<bool isRequest>
|
||||
bool
|
||||
equal_body(string_view sv, string_view body)
|
||||
|
@ -521,7 +521,7 @@ public:
|
||||
system_error{ec});
|
||||
}
|
||||
if(! ec)
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
++count;
|
||||
if(count == 4)
|
||||
BEAST_EXPECT(
|
||||
|
@ -119,7 +119,7 @@ public:
|
||||
"\x80\x81\xff\xff\xff\xff\xd5"));
|
||||
multi_buffer b;
|
||||
w.read(ws, b);
|
||||
BEAST_EXPECT(to_string(b.data()) == "**");
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == "**");
|
||||
});
|
||||
|
||||
// ping
|
||||
@ -141,7 +141,7 @@ public:
|
||||
w.read(ws, b);
|
||||
BEAST_EXPECT(invoked);
|
||||
BEAST_EXPECT(ws.got_text());
|
||||
BEAST_EXPECT(to_string(b.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == "Hello");
|
||||
});
|
||||
|
||||
// ping
|
||||
@ -182,7 +182,7 @@ public:
|
||||
w.read(ws, b);
|
||||
BEAST_EXPECT(once);
|
||||
BEAST_EXPECT(ws.got_binary());
|
||||
BEAST_EXPECT(to_string(b.data()) == "Hello");
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == "Hello");
|
||||
});
|
||||
|
||||
// ping then fragmented message
|
||||
@ -205,7 +205,7 @@ public:
|
||||
multi_buffer b;
|
||||
w.read(ws, b);
|
||||
BEAST_EXPECT(once);
|
||||
BEAST_EXPECT(to_string(b.data()) == "Hello, World!");
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == "Hello, World!");
|
||||
});
|
||||
|
||||
// masked message, big
|
||||
@ -226,7 +226,7 @@ public:
|
||||
multi_buffer b;
|
||||
w.read(ws, b);
|
||||
BEAST_EXPECT(ws.got_text());
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
ws.next_layer().close();
|
||||
}
|
||||
catch(...)
|
||||
@ -486,7 +486,7 @@ public:
|
||||
w.write(ws, buffer(s));
|
||||
multi_buffer b;
|
||||
w.read(ws, b);
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
});
|
||||
pmd.client_no_context_takeover = false;
|
||||
}
|
||||
@ -509,7 +509,7 @@ public:
|
||||
multi_buffer b;
|
||||
w.read(ws, b);
|
||||
BEAST_EXPECT(ws.got_text());
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
});
|
||||
|
||||
// masked message
|
||||
@ -530,7 +530,7 @@ public:
|
||||
multi_buffer b;
|
||||
w.read(ws, b);
|
||||
BEAST_EXPECT(ws.got_text());
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
ws.next_layer().close();
|
||||
}
|
||||
catch(...)
|
||||
@ -549,7 +549,7 @@ public:
|
||||
multi_buffer b;
|
||||
w.read(ws, b);
|
||||
BEAST_EXPECT(ws.got_text());
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
});
|
||||
|
||||
// partial message
|
||||
@ -575,10 +575,10 @@ public:
|
||||
auto bytes_written =
|
||||
w.read_some(ws, 3, b);
|
||||
BEAST_EXPECT(bytes_written > 0);
|
||||
BEAST_EXPECT(to_string(b.data()) ==
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) ==
|
||||
s.substr(0, b.size()));
|
||||
w.read_some(ws, 256, b);
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
});
|
||||
|
||||
// big message
|
||||
@ -589,7 +589,7 @@ public:
|
||||
w.write(ws, buffer(s));
|
||||
multi_buffer b;
|
||||
w.read(ws, b);
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
});
|
||||
|
||||
// message, bad utf8
|
||||
|
@ -114,7 +114,7 @@ public:
|
||||
if(ec)
|
||||
BOOST_THROW_EXCEPTION(
|
||||
system_error{ec});
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
++count;
|
||||
});
|
||||
BEAST_EXPECT(ws.rd_block_.is_locked());
|
||||
@ -154,7 +154,7 @@ public:
|
||||
if(ec)
|
||||
BOOST_THROW_EXCEPTION(
|
||||
system_error{ec});
|
||||
BEAST_EXPECT(to_string(b.data()) == "**");
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == "**");
|
||||
BEAST_EXPECT(++count == 1);
|
||||
b.consume(b.size());
|
||||
ws.async_read(b,
|
||||
@ -256,7 +256,7 @@ public:
|
||||
{
|
||||
++count;
|
||||
BEAST_EXPECTS(! ec, ec.message());
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
});
|
||||
ioc.run_one();
|
||||
es.stream().write_some(
|
||||
@ -331,7 +331,7 @@ public:
|
||||
{
|
||||
++count;
|
||||
BEAST_EXPECTS(! ec, ec.message());
|
||||
BEAST_EXPECT(to_string(b.data()) == "**");
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == "**");
|
||||
});
|
||||
ioc.run_one();
|
||||
es.stream().write_some(
|
||||
|
@ -11,6 +11,7 @@
|
||||
#define BEAST_TEST_WEBSOCKET_TEST_HPP
|
||||
|
||||
#include <boost/beast/core/buffers_prefix.hpp>
|
||||
#include <boost/beast/core/buffers_to_string.hpp>
|
||||
#include <boost/beast/core/ostream.hpp>
|
||||
#include <boost/beast/core/multi_buffer.hpp>
|
||||
#include <boost/beast/websocket/stream.hpp>
|
||||
@ -379,19 +380,6 @@ public:
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
template<class ConstBufferSequence>
|
||||
std::string
|
||||
to_string(ConstBufferSequence const& bs)
|
||||
{
|
||||
std::string s;
|
||||
s.reserve(buffer_size(bs));
|
||||
for(auto b : beast::detail::buffers_range(bs))
|
||||
s.append(
|
||||
reinterpret_cast<char const*>(b.data()),
|
||||
b.size());
|
||||
return s;
|
||||
}
|
||||
|
||||
template<std::size_t N>
|
||||
class cbuf_helper
|
||||
{
|
||||
|
@ -63,7 +63,7 @@ public:
|
||||
multi_buffer b;
|
||||
w.read(ws, b);
|
||||
BEAST_EXPECT(ws.got_text());
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
});
|
||||
|
||||
// empty message
|
||||
@ -90,7 +90,7 @@ public:
|
||||
multi_buffer b;
|
||||
w.read(ws, b);
|
||||
BEAST_EXPECT(ws.got_text());
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
});
|
||||
|
||||
// continuation
|
||||
@ -106,7 +106,7 @@ public:
|
||||
s.data() + chop, s.size() - chop));
|
||||
flat_buffer b;
|
||||
w.read(ws, b);
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
});
|
||||
|
||||
// mask
|
||||
@ -118,7 +118,7 @@ public:
|
||||
w.write(ws, buffer(s));
|
||||
flat_buffer b;
|
||||
w.read(ws, b);
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
});
|
||||
|
||||
// mask (large)
|
||||
@ -131,7 +131,7 @@ public:
|
||||
w.write(ws, buffer(s));
|
||||
flat_buffer b;
|
||||
w.read(ws, b);
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
});
|
||||
|
||||
// mask, autofrag
|
||||
@ -143,7 +143,7 @@ public:
|
||||
w.write(ws, buffer(s));
|
||||
flat_buffer b;
|
||||
w.read(ws, b);
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
});
|
||||
|
||||
// nomask
|
||||
@ -161,7 +161,7 @@ public:
|
||||
w.write(ws, buffer(s));
|
||||
flat_buffer b;
|
||||
w.read(ws, b);
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
w.close(ws, {});
|
||||
}
|
||||
catch(...)
|
||||
@ -187,7 +187,7 @@ public:
|
||||
w.write(ws, buffer(s));
|
||||
flat_buffer b;
|
||||
w.read(ws, b);
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
w.close(ws, {});
|
||||
}
|
||||
catch(...)
|
||||
@ -218,7 +218,7 @@ public:
|
||||
w.write(ws, buffer(s));
|
||||
flat_buffer b;
|
||||
w.read(ws, b);
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
});
|
||||
|
||||
// deflate, continuation
|
||||
@ -235,7 +235,7 @@ public:
|
||||
s.data() + chop, s.size() - chop));
|
||||
flat_buffer b;
|
||||
w.read(ws, b);
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
});
|
||||
|
||||
// deflate, no context takeover
|
||||
@ -247,7 +247,7 @@ public:
|
||||
w.write(ws, buffer(s));
|
||||
flat_buffer b;
|
||||
w.read(ws, b);
|
||||
BEAST_EXPECT(to_string(b.data()) == s);
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == s);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
#include <boost/beast/http.hpp>
|
||||
#include <boost/beast/core/buffers_suffix.hpp>
|
||||
#include <boost/beast/core/buffers_to_string.hpp>
|
||||
#include <boost/beast/core/ostream.hpp>
|
||||
#include <boost/beast/core/flat_buffer.hpp>
|
||||
#include <boost/beast/core/multi_buffer.hpp>
|
||||
@ -37,19 +38,6 @@ public:
|
||||
corpus cres_;
|
||||
std::size_t size_ = 0;
|
||||
|
||||
template<class ConstBufferSequence>
|
||||
static
|
||||
std::string
|
||||
to_string(ConstBufferSequence const& bs)
|
||||
{
|
||||
std::string s;
|
||||
s.reserve(buffer_size(bs));
|
||||
for(auto b : beast::detail::buffers_range(bs))
|
||||
s.append(reinterpret_cast<char const*>(b.data()),
|
||||
b.size());
|
||||
return s;
|
||||
}
|
||||
|
||||
corpus
|
||||
build_corpus(std::size_t n, std::true_type)
|
||||
{
|
||||
@ -121,7 +109,7 @@ public:
|
||||
error_code ec;
|
||||
p.write(b.data(), ec);
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
log << to_string(b.data()) << std::endl;
|
||||
log << buffers_to_string(b.data()) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,7 +125,7 @@ public:
|
||||
error_code ec;
|
||||
feed(b.data(), p, ec);
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
log << to_string(b.data()) << std::endl;
|
||||
log << buffers_to_string(b.data()) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,19 +53,6 @@ public:
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template<class ConstBufferSequence>
|
||||
static
|
||||
std::string
|
||||
to_string(ConstBufferSequence const& bs)
|
||||
{
|
||||
std::string s;
|
||||
s.reserve(buffer_size(bs));
|
||||
for(auto b : beast::detail::buffers_range(bs))
|
||||
s.append(reinterpret_cast<
|
||||
char const*>(b.data()), b.size());
|
||||
return s;
|
||||
}
|
||||
|
||||
template<bool isRequest>
|
||||
bool
|
||||
equal_body(string_view sv, string_view body)
|
||||
@ -368,7 +355,7 @@ public:
|
||||
std::allocator<double>{}
|
||||
), ec);
|
||||
BEAST_EXPECT(
|
||||
to_string(tr.buffer().data()) ==
|
||||
buffers_to_string(tr.buffer().data()) ==
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Server: test\r\n"
|
||||
"Accept: Expires, Content-MD5\r\n"
|
||||
|
Reference in New Issue
Block a user