diff --git a/CHANGELOG.md b/CHANGELOG.md index 359db166..111b927b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +Version 169: + +* Use buffers_to_string in tests + +-------------------------------------------------------------------------------- + Version 168: * Use executor_work_guard in composed operations diff --git a/include/boost/beast/core/buffers_to_string.hpp b/include/boost/beast/core/buffers_to_string.hpp index aae3d3aa..bf3d6415 100644 --- a/include/boost/beast/core/buffers_to_string.hpp +++ b/include/boost/beast/core/buffers_to_string.hpp @@ -41,6 +41,7 @@ namespace beast { @endcode */ template +inline std::string buffers_to_string(ConstBufferSequence const& buffers) { diff --git a/test/beast/core/buffer_test.hpp b/test/beast/core/buffer_test.hpp index d2d78bd5..ccd26582 100644 --- a/test/beast/core/buffer_test.hpp +++ b/test/beast/core/buffer_test.hpp @@ -10,6 +10,7 @@ #ifndef BOOST_BEAST_TEST_BUFFER_TEST_HPP #define BOOST_BEAST_TEST_BUFFER_TEST_HPP +#include #include #include #include @@ -23,20 +24,6 @@ namespace boost { namespace beast { namespace test { -template -typename std::enable_if< - boost::asio::is_const_buffer_sequence::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(b.data()), - b.size()); - return s; -} - template void write_buffer(DynamicBuffer& b, string_view s) diff --git a/test/beast/core/buffers_adapter.cpp b/test/beast/core/buffers_adapter.cpp index b22316ed..3ce922dd 100644 --- a/test/beast/core/buffers_adapter.cpp +++ b/test/beast/core/buffers_adapter.cpp @@ -24,19 +24,6 @@ namespace beast { class buffers_adapter_test : public unit_test::suite { public: - template - 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); diff --git a/test/beast/core/buffers_prefix.cpp b/test/beast/core/buffers_prefix.cpp index 39e8f5eb..11bb2638 100644 --- a/test/beast/core/buffers_prefix.cpp +++ b/test/beast/core/buffers_prefix.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -88,19 +89,6 @@ public: return n; } - template - 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(b.data()), - b.size()); - return s; - } - template 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)); } } }} diff --git a/test/beast/core/buffers_suffix.cpp b/test/beast/core/buffers_suffix.cpp index 383d2a80..fbb340f0 100644 --- a/test/beast/core/buffers_suffix.cpp +++ b/test/beast/core/buffers_suffix.cpp @@ -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 @@ -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 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 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 diff --git a/test/beast/core/flat_buffer.cpp b/test/beast/core/flat_buffer.cpp index 87ff033b..85e88539 100644 --- a/test/beast/core/flat_buffer.cpp +++ b/test/beast/core/flat_buffer.cpp @@ -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 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 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 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 b1; @@ -116,15 +116,15 @@ public: a_neq_t a; basic_flat_buffer 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 b1; ostream(b1) << "Hello"; basic_flat_buffer 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 b1; @@ -132,8 +132,8 @@ public: a_t a; basic_flat_buffer 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 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 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 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 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 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 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); diff --git a/test/beast/core/multi_buffer.cpp b/test/beast/core/multi_buffer.cpp index 982cbef8..c43ad337 100644 --- a/test/beast/core/multi_buffer.cpp +++ b/test/beast/core/multi_buffer.cpp @@ -38,8 +38,8 @@ public: eq(basic_multi_buffer const& mb1, basic_multi_buffer 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 @@ -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 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 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 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 b1; @@ -298,15 +298,15 @@ public: unequal_t a; basic_multi_buffer 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 b1; ostream(b1) << "Hello"; basic_multi_buffer 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 b1; @@ -314,8 +314,8 @@ public: equal_t a; basic_multi_buffer 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 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 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 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 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 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); } } diff --git a/test/beast/core/ostream.cpp b/test/beast/core/ostream.cpp index 0c069a47..6f59ce28 100644 --- a/test/beast/core/ostream.cpp +++ b/test/beast/core/ostream.cpp @@ -10,6 +10,7 @@ // Test that header file is self-contained. #include +#include #include #include #include @@ -20,19 +21,6 @@ namespace beast { class ostream_test : public beast::unit_test::suite { public: - template - 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); } } }; diff --git a/test/beast/core/static_buffer.cpp b/test/beast/core/static_buffer.cpp index 485ab26c..775bb3e2 100644 --- a/test/beast/core/static_buffer.cpp +++ b/test/beast/core/static_buffer.cpp @@ -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); diff --git a/test/beast/http/chunk_encode.cpp b/test/beast/http/chunk_encode.cpp index ed6ebe8c..95455cdd 100644 --- a/test/beast/http/chunk_encode.cpp +++ b/test/beast/http/chunk_encode.cpp @@ -12,6 +12,7 @@ #include "message_fuzz.hpp" +#include #include #include #include @@ -35,30 +36,16 @@ public: BOOST_STATIC_ASSERT( ! detail::is_chunk_extensions::value); - template - 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(b.data()), - b.size()); - return s; - } - template void check(string_view match, Args&&... args) { T t(std::forward(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 @@ -66,11 +53,11 @@ public: check_fwd(string_view match, Args&&... args) { T t(std::forward(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; diff --git a/test/beast/http/dynamic_body.cpp b/test/beast/http/dynamic_body.cpp index 14bf3191..eccb9ad7 100644 --- a/test/beast/http/dynamic_body.cpp +++ b/test/beast/http/dynamic_body.cpp @@ -10,6 +10,7 @@ // Test that header file is self-contained. #include +#include #include #include #include @@ -37,19 +38,6 @@ public: return ss.str(); } - template - 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(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); } }; diff --git a/test/beast/http/write.cpp b/test/beast/http/write.cpp index f7666ce0..8ac1b1c5 100644 --- a/test/beast/http/write.cpp +++ b/test/beast/http/write.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -264,19 +265,6 @@ public: return ss.str(); } - template - 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(b), - b.size()); - return s; - } - template bool equal_body(string_view sv, string_view body) diff --git a/test/beast/websocket/close.cpp b/test/beast/websocket/close.cpp index 0e5f26c8..91d7fa6e 100644 --- a/test/beast/websocket/close.cpp +++ b/test/beast/websocket/close.cpp @@ -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( diff --git a/test/beast/websocket/read1.cpp b/test/beast/websocket/read1.cpp index c34df34b..6af7abec 100644 --- a/test/beast/websocket/read1.cpp +++ b/test/beast/websocket/read1.cpp @@ -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 diff --git a/test/beast/websocket/read2.cpp b/test/beast/websocket/read2.cpp index fab35569..24d5387e 100644 --- a/test/beast/websocket/read2.cpp +++ b/test/beast/websocket/read2.cpp @@ -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( diff --git a/test/beast/websocket/test.hpp b/test/beast/websocket/test.hpp index 2cb6c09d..6fe1f141 100644 --- a/test/beast/websocket/test.hpp +++ b/test/beast/websocket/test.hpp @@ -11,6 +11,7 @@ #define BEAST_TEST_WEBSOCKET_TEST_HPP #include +#include #include #include #include @@ -379,19 +380,6 @@ public: //-------------------------------------------------------------------------- - template - 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(b.data()), - b.size()); - return s; - } - template class cbuf_helper { diff --git a/test/beast/websocket/write.cpp b/test/beast/websocket/write.cpp index f3a31819..f2ad5071 100644 --- a/test/beast/websocket/write.cpp +++ b/test/beast/websocket/write.cpp @@ -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); }); } diff --git a/test/bench/parser/bench_parser.cpp b/test/bench/parser/bench_parser.cpp index 3b4a8327..c6d8e4ad 100644 --- a/test/bench/parser/bench_parser.cpp +++ b/test/bench/parser/bench_parser.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -37,19 +38,6 @@ public: corpus cres_; std::size_t size_ = 0; - template - 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(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; } } diff --git a/test/doc/http_examples.cpp b/test/doc/http_examples.cpp index 4aac72ad..b95e0a25 100644 --- a/test/doc/http_examples.cpp +++ b/test/doc/http_examples.cpp @@ -53,19 +53,6 @@ public: return ss.str(); } - template - 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 equal_body(string_view sv, string_view body) @@ -368,7 +355,7 @@ public: std::allocator{} ), 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"