]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/beast/test/beast/http/serializer.cpp
2 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // Official repository: https://github.com/boostorg/beast
10 // Test that header file is self-contained.
11 #include <boost/beast/http/serializer.hpp>
13 #include <boost/beast/http/string_body.hpp>
14 #include <boost/beast/unit_test/suite.hpp>
20 class serializer_test
: public beast::unit_test::suite
23 struct deprecated_body
25 using value_type
= std::string
;
30 using const_buffers_type
=
31 boost::asio::const_buffer
;
33 value_type
const& body_
;
35 template<bool isRequest
, class Fields
>
37 writer(message
<isRequest
, deprecated_body
, Fields
> const& m
):
42 void init(error_code
& ec
)
44 ec
.assign(0, ec
.category());
47 boost::optional
<std::pair
<const_buffers_type
, bool>>
50 ec
.assign(0, ec
.category());
51 return {{const_buffers_type
{
52 body_
.data(), body_
.size()}, false}};
63 using const_buffers_type
=
64 boost::asio::const_buffer
;
66 template<bool isRequest
, class Fields
>
67 writer(header
<isRequest
, Fields
> const&, value_type
const&);
72 boost::optional
<std::pair
<const_buffers_type
, bool>>
83 using const_buffers_type
=
84 boost::asio::const_buffer
;
86 template<bool isRequest
, class Fields
>
87 writer(header
<isRequest
, Fields
>&, value_type
&);
92 boost::optional
<std::pair
<const_buffers_type
, bool>>
97 BOOST_STATIC_ASSERT(std::is_const
< serializer
<
98 true, const_body
>::value_type
>::value
);
100 BOOST_STATIC_ASSERT(! std::is_const
<serializer
<
101 true, mutable_body
>::value_type
>::value
);
103 BOOST_STATIC_ASSERT(std::is_constructible
<
104 serializer
<true, const_body
>,
105 message
<true, const_body
>&>::value
);
107 BOOST_STATIC_ASSERT(std::is_constructible
<
108 serializer
<true, const_body
>,
109 message
<true, const_body
> const&>::value
);
111 BOOST_STATIC_ASSERT(std::is_constructible
<
112 serializer
<true, mutable_body
>,
113 message
<true, mutable_body
>&>::value
);
115 BOOST_STATIC_ASSERT(! std::is_constructible
<
116 serializer
<true, mutable_body
>,
117 message
<true, mutable_body
> const&>::value
);
123 template<class ConstBufferSequence
>
125 operator()(error_code
&,
126 ConstBufferSequence
const& buffers
)
128 size
= boost::asio::buffer_size(buffers
);
135 auto const limit
= 30;
138 response
<string_body
> res
;
139 res
.body().append(1000, '*');
140 serializer
<false, string_body
> sr
{res
};
145 BEAST_EXPECT(visit
.size
<= limit
);
146 sr
.consume(visit
.size
);
152 void testBodyWriterCtor()
154 response
<deprecated_body
> res
;
155 request
<deprecated_body
> req
;
156 serializer
<false, deprecated_body
> sr1
{res
};
157 serializer
<true, deprecated_body
> sr2
{req
};
158 boost::ignore_unused(sr1
, sr2
);
165 testBodyWriterCtor();
169 BEAST_DEFINE_TESTSUITE(beast
,http
,serializer
);