]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/beast/test/beast/websocket/stream.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / beast / test / beast / websocket / stream.cpp
1 //
2 // Copyright (c) 2016-2019 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/websocket/stream.hpp>
12
13 #include <boost/beast/core/tcp_stream.hpp>
14 #include <boost/asio/strand.hpp>
15
16 #include "test.hpp"
17
18 namespace boost {
19 namespace beast {
20 namespace websocket {
21
22 class stream_test : public websocket_test_suite
23 {
24 public:
25 void
26 testGetSetOption()
27 {
28 net::io_context ioc;
29 stream<test::stream> ws(ioc);
30
31 {
32 ws.set_option(
33 stream_base::decorator(
34 [](request_type&)
35 {
36 }));
37
38 ws.set_option(
39 stream_base::decorator(
40 [](response_type&)
41 {
42 }));
43 }
44
45 {
46 ws.set_option(
47 stream_base::timeout::suggested(
48 role_type::client));
49
50 ws.set_option(
51 stream_base::timeout::suggested(
52 role_type::server));
53
54 ws.set_option({
55 std::chrono::seconds(30),
56 std::chrono::seconds(300),
57 true});
58
59 stream_base::timeout opt;
60 ws.get_option(opt);
61 ws.set_option(opt);
62 }
63 }
64
65 void
66 testOptions()
67 {
68 {
69 std::seed_seq ss{42};
70 seed_prng(ss);
71 }
72
73 stream<test::stream> ws{ioc_};
74 ws.auto_fragment(true);
75 ws.write_buffer_bytes(2048);
76 ws.binary(false);
77 ws.read_message_max(1 * 1024 * 1024);
78 try
79 {
80 ws.write_buffer_bytes(7);
81 fail();
82 }
83 catch(std::exception const&)
84 {
85 pass();
86 }
87
88 ws.secure_prng(true);
89 ws.secure_prng(false);
90
91 auto const bad =
92 [&](permessage_deflate const& pmd)
93 {
94 stream<test::stream> ws{ioc_};
95 try
96 {
97 ws.set_option(pmd);
98 fail("", __FILE__, __LINE__);
99 }
100 catch(std::exception const&)
101 {
102 pass();
103 }
104 };
105
106 {
107 permessage_deflate pmd;
108 pmd.server_max_window_bits = 16;
109 bad(pmd);
110 }
111
112 {
113 permessage_deflate pmd;
114 pmd.server_max_window_bits = 8;
115 bad(pmd);
116 }
117
118 {
119 permessage_deflate pmd;
120 pmd.client_max_window_bits = 16;
121 bad(pmd);
122 }
123
124 {
125 permessage_deflate pmd;
126 pmd.client_max_window_bits = 8;
127 bad(pmd);
128 }
129
130 {
131 permessage_deflate pmd;
132 pmd.compLevel = -1;
133 bad(pmd);
134 }
135
136 {
137 permessage_deflate pmd;
138 pmd.compLevel = 10;
139 bad(pmd);
140 }
141
142 {
143 permessage_deflate pmd;
144 pmd.memLevel = 0;
145 bad(pmd);
146 }
147
148 {
149 permessage_deflate pmd;
150 pmd.memLevel = 10;
151 bad(pmd);
152 }
153 }
154
155 void
156 testJavadoc()
157 {
158 net::io_context ioc;
159 {
160 websocket::stream<tcp_stream> ws{net::make_strand(ioc)};
161 }
162 {
163 websocket::stream<tcp_stream> ws(ioc);
164 }
165 }
166
167 void
168 run() override
169 {
170 BOOST_STATIC_ASSERT(std::is_constructible<
171 stream<test::stream>, net::io_context&>::value);
172
173 BOOST_STATIC_ASSERT(std::is_move_constructible<
174 stream<test::stream>>::value);
175
176 #if 0
177 BOOST_STATIC_ASSERT(std::is_move_assignable<
178 stream<test::stream>>::value);
179 #endif
180
181 BOOST_STATIC_ASSERT(std::is_constructible<
182 stream<test::stream&>, test::stream&>::value);
183
184 // VFALCO Should these be allowed for NextLayer references?
185 BOOST_STATIC_ASSERT(std::is_move_constructible<
186 stream<test::stream&>>::value);
187 #if 0
188 BOOST_STATIC_ASSERT(std::is_move_assignable<
189 stream<test::stream&>>::value);
190 #endif
191
192 log << "sizeof(websocket::stream) == " <<
193 sizeof(websocket::stream<test::stream&>) << std::endl;
194 log << "sizeof(websocket::stream::impl_type) == " <<
195 sizeof(websocket::stream<test::stream&>::impl_type) << std::endl;
196
197 testOptions();
198 testJavadoc();
199 }
200 };
201
202 BEAST_DEFINE_TESTSUITE(beast,websocket,stream);
203
204 } // websocket
205 } // beast
206 } // boost