forked from boostorg/beast
Dynamic buffers improvements:
fix #1305 Applies to: flat_buffer flat_static_buffer multi_buffer static_buffer Changes: * Revised all javadocs * Move construction does not invalidate in some cases * non-const data() returns a mutable buffer sequence * Add cdata() to also return constant readable bytes * Eligible member functions are declared noexcept
This commit is contained in:
@@ -15,6 +15,9 @@
|
||||
#include <boost/beast/core/ostream.hpp>
|
||||
#include <boost/beast/core/string.hpp>
|
||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
||||
#include <boost/asio/buffers_iterator.hpp>
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <string>
|
||||
|
||||
namespace boost {
|
||||
@@ -26,6 +29,53 @@ BOOST_STATIC_ASSERT(
|
||||
class static_buffer_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
BOOST_STATIC_ASSERT(
|
||||
boost::asio::is_dynamic_buffer<
|
||||
static_buffer_base>::value);
|
||||
BOOST_STATIC_ASSERT(
|
||||
boost::asio::is_const_buffer_sequence<
|
||||
static_buffer_base::const_buffers_type>::value);
|
||||
BOOST_STATIC_ASSERT(
|
||||
boost::asio::is_mutable_buffer_sequence<
|
||||
static_buffer_base::mutable_data_type>::value);
|
||||
BOOST_STATIC_ASSERT(
|
||||
boost::asio::is_mutable_buffer_sequence<
|
||||
static_buffer_base::mutable_buffers_type>::value);
|
||||
BOOST_STATIC_ASSERT(std::is_convertible<
|
||||
static_buffer_base::mutable_data_type,
|
||||
static_buffer_base::const_buffers_type>::value);
|
||||
|
||||
template<class DynamicBuffer>
|
||||
void
|
||||
testMutableData()
|
||||
{
|
||||
DynamicBuffer b;
|
||||
DynamicBuffer const& cb = b;
|
||||
ostream(b) << "Hello";
|
||||
BOOST_STATIC_ASSERT(
|
||||
boost::asio::is_const_buffer_sequence<
|
||||
decltype(cb.data())>::value &&
|
||||
! boost::asio::is_mutable_buffer_sequence<
|
||||
decltype(cb.data())>::value);
|
||||
BOOST_STATIC_ASSERT(
|
||||
boost::asio::is_const_buffer_sequence<
|
||||
decltype(cb.cdata())>::value &&
|
||||
! boost::asio::is_mutable_buffer_sequence<
|
||||
decltype(cb.cdata())>::value);
|
||||
BOOST_STATIC_ASSERT(
|
||||
boost::asio::is_mutable_buffer_sequence<
|
||||
decltype(b.data())>::value);
|
||||
std::for_each(
|
||||
boost::asio::buffers_iterator<decltype(b.data())>::begin(b.data()),
|
||||
boost::asio::buffers_iterator<decltype(b.data())>::end(b.data()),
|
||||
[](char& c)
|
||||
{
|
||||
c = static_cast<char>(std::toupper(c));
|
||||
});
|
||||
BEAST_EXPECT(buffers_to_string(b.data()) == "HELLO");
|
||||
BEAST_EXPECT(buffers_to_string(b.cdata()) == "HELLO");
|
||||
}
|
||||
|
||||
void
|
||||
testStaticBuffer()
|
||||
{
|
||||
@@ -225,7 +275,8 @@ public:
|
||||
void run() override
|
||||
{
|
||||
testBuffer();
|
||||
//testStaticBuffer();
|
||||
testStaticBuffer();
|
||||
testMutableData<static_buffer<32>>();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user