mirror of
https://github.com/boostorg/beast.git
synced 2026-01-27 09:42:18 +01:00
These types now perform error-based initialization in a separate init() functions instead of in the constructor. Actions Required: * Modify instances of user-defined BodyReader and BodyWriter types to perfrom two-phase initialization, as per the updated documented type requirements.
126 lines
3.0 KiB
C++
126 lines
3.0 KiB
C++
//
|
|
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
|
|
//
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
//
|
|
|
|
// Test that header file is self-contained.
|
|
#include <beast/http/serializer.hpp>
|
|
|
|
#include <beast/http/string_body.hpp>
|
|
#include <beast/unit_test/suite.hpp>
|
|
|
|
namespace beast {
|
|
namespace http {
|
|
|
|
class serializer_test : public beast::unit_test::suite
|
|
{
|
|
public:
|
|
struct const_body
|
|
{
|
|
struct value_type{};
|
|
|
|
struct reader
|
|
{
|
|
using const_buffers_type =
|
|
boost::asio::const_buffers_1;
|
|
|
|
template<bool isRequest, class Fields>
|
|
reader(message<isRequest, const_body, Fields> const&);
|
|
|
|
void
|
|
init(error_code& ec);
|
|
|
|
boost::optional<std::pair<const_buffers_type, bool>>
|
|
get(error_code&);
|
|
};
|
|
};
|
|
|
|
struct mutable_body
|
|
{
|
|
struct value_type{};
|
|
|
|
struct reader
|
|
{
|
|
using const_buffers_type =
|
|
boost::asio::const_buffers_1;
|
|
|
|
template<bool isRequest, class Fields>
|
|
reader(message<isRequest, mutable_body, Fields>&);
|
|
|
|
void
|
|
init(error_code& ec);
|
|
|
|
boost::optional<std::pair<const_buffers_type, bool>>
|
|
get(error_code&);
|
|
};
|
|
};
|
|
|
|
BOOST_STATIC_ASSERT(std::is_const< serializer<
|
|
true, const_body>::value_type>::value);
|
|
|
|
BOOST_STATIC_ASSERT(! std::is_const<serializer<
|
|
true, mutable_body>::value_type>::value);
|
|
|
|
BOOST_STATIC_ASSERT(std::is_constructible<
|
|
serializer<true, const_body>,
|
|
message <true, const_body>&>::value);
|
|
|
|
BOOST_STATIC_ASSERT(std::is_constructible<
|
|
serializer<true, const_body>,
|
|
message <true, const_body> const&>::value);
|
|
|
|
BOOST_STATIC_ASSERT(std::is_constructible<
|
|
serializer<true, mutable_body>,
|
|
message <true, mutable_body>&>::value);
|
|
|
|
BOOST_STATIC_ASSERT(! std::is_constructible<
|
|
serializer<true, mutable_body>,
|
|
message <true, mutable_body> const&>::value);
|
|
|
|
struct lambda
|
|
{
|
|
std::size_t size;
|
|
|
|
template<class ConstBufferSequence>
|
|
void
|
|
operator()(error_code&,
|
|
ConstBufferSequence const& buffers)
|
|
{
|
|
size = boost::asio::buffer_size(buffers);
|
|
}
|
|
};
|
|
|
|
void
|
|
testWriteLimit()
|
|
{
|
|
auto const limit = 30;
|
|
lambda visit;
|
|
error_code ec;
|
|
response<string_body> res;
|
|
res.body.append(1000, '*');
|
|
serializer<false, string_body> sr{res};
|
|
sr.limit(limit);
|
|
for(;;)
|
|
{
|
|
sr.next(ec, visit);
|
|
BEAST_EXPECT(visit.size <= limit);
|
|
sr.consume(visit.size);
|
|
if(sr.is_done())
|
|
break;
|
|
}
|
|
}
|
|
|
|
void
|
|
run() override
|
|
{
|
|
testWriteLimit();
|
|
}
|
|
};
|
|
|
|
BEAST_DEFINE_TESTSUITE(serializer,http,beast);
|
|
|
|
} // http
|
|
} // beast
|