]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/beast/test/beast/http/serializer.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / beast / test / beast / http / serializer.cpp
1 //
2 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
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)
6 //
7 // Official repository: https://github.com/boostorg/beast
8 //
9
10 // Test that header file is self-contained.
11 #include <boost/beast/http/serializer.hpp>
12
13 #include <boost/beast/http/string_body.hpp>
14 #include <boost/beast/unit_test/suite.hpp>
15
16 namespace boost {
17 namespace beast {
18 namespace http {
19
20 class serializer_test : public beast::unit_test::suite
21 {
22 public:
23 struct const_body
24 {
25 struct value_type{};
26
27 struct writer
28 {
29 using const_buffers_type =
30 boost::asio::const_buffer;
31
32 template<bool isRequest, class Fields>
33 writer(message<isRequest, const_body, Fields> const&);
34
35 void
36 init(error_code& ec);
37
38 boost::optional<std::pair<const_buffers_type, bool>>
39 get(error_code&);
40 };
41 };
42
43 struct mutable_body
44 {
45 struct value_type{};
46
47 struct writer
48 {
49 using const_buffers_type =
50 boost::asio::const_buffer;
51
52 template<bool isRequest, class Fields>
53 writer(message<isRequest, mutable_body, Fields>&);
54
55 void
56 init(error_code& ec);
57
58 boost::optional<std::pair<const_buffers_type, bool>>
59 get(error_code&);
60 };
61 };
62
63 BOOST_STATIC_ASSERT(std::is_const< serializer<
64 true, const_body>::value_type>::value);
65
66 BOOST_STATIC_ASSERT(! std::is_const<serializer<
67 true, mutable_body>::value_type>::value);
68
69 BOOST_STATIC_ASSERT(std::is_constructible<
70 serializer<true, const_body>,
71 message <true, const_body>&>::value);
72
73 BOOST_STATIC_ASSERT(std::is_constructible<
74 serializer<true, const_body>,
75 message <true, const_body> const&>::value);
76
77 BOOST_STATIC_ASSERT(std::is_constructible<
78 serializer<true, mutable_body>,
79 message <true, mutable_body>&>::value);
80
81 BOOST_STATIC_ASSERT(! std::is_constructible<
82 serializer<true, mutable_body>,
83 message <true, mutable_body> const&>::value);
84
85 struct lambda
86 {
87 std::size_t size;
88
89 template<class ConstBufferSequence>
90 void
91 operator()(error_code&,
92 ConstBufferSequence const& buffers)
93 {
94 size = boost::asio::buffer_size(buffers);
95 }
96 };
97
98 void
99 testWriteLimit()
100 {
101 auto const limit = 30;
102 lambda visit;
103 error_code ec;
104 response<string_body> res;
105 res.body().append(1000, '*');
106 serializer<false, string_body> sr{res};
107 sr.limit(limit);
108 for(;;)
109 {
110 sr.next(ec, visit);
111 BEAST_EXPECT(visit.size <= limit);
112 sr.consume(visit.size);
113 if(sr.is_done())
114 break;
115 }
116 }
117
118 void
119 run() override
120 {
121 testWriteLimit();
122 }
123 };
124
125 BEAST_DEFINE_TESTSUITE(beast,http,serializer);
126
127 } // http
128 } // beast
129 } // boost