]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/beast/test/beast/_experimental/stream.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / beast / test / beast / _experimental / 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/_experimental/test/stream.hpp>
12
13 #include <boost/beast/_experimental/unit_test/suite.hpp>
14 #include <boost/beast/_experimental/test/handler.hpp>
15
16 namespace boost {
17 namespace beast {
18
19 class stream_test
20 : public unit_test::suite
21 {
22 public:
23 void
24 testTestStream()
25 {
26 char buf[1] = {};
27 net::mutable_buffer m0;
28 net::mutable_buffer m1(buf, sizeof(buf));
29
30 {
31 net::io_context ioc;
32
33 {
34 test::stream ts(ioc);
35 }
36 {
37 test::stream ts(ioc);
38 ts.close();
39 }
40 {
41 test::stream t1(ioc);
42 auto t2 = connect(t1);
43 }
44 {
45 test::stream t1(ioc);
46 auto t2 = connect(t1);
47 t2.close();
48 }
49 }
50 {
51 // abandon
52 net::io_context ioc;
53 test::stream ts(ioc);
54 ts.async_read_some(m1,
55 [](error_code, std::size_t)
56 {
57 BEAST_FAIL();
58 });
59 }
60 //---
61 {
62 net::io_context ioc;
63 {
64 test::stream ts(ioc);
65 ts.async_read_some(m1,
66 test::fail_handler(
67 net::error::operation_aborted));
68 }
69 test::run(ioc);
70 }
71 {
72 net::io_context ioc;
73 test::stream ts(ioc);
74 ts.async_read_some(m1,
75 test::fail_handler(
76 net::error::operation_aborted));
77 ts.close();
78 test::run(ioc);
79 }
80 {
81 net::io_context ioc;
82 test::stream t1(ioc);
83 auto t2 = connect(t1);
84 t1.async_read_some(m1,
85 test::fail_handler(
86 net::error::eof));
87 t2.close();
88 test::run(ioc);
89 }
90 {
91 net::io_context ioc;
92 test::stream t1(ioc);
93 auto t2 = connect(t1);
94 t1.async_read_some(m1,
95 test::fail_handler(
96 net::error::operation_aborted));
97 t1.close();
98 test::run(ioc);
99 }
100 }
101
102 void
103 testSharedAbandon()
104 {
105 struct handler
106 {
107 std::shared_ptr<test::stream> ts_;
108
109 void
110 operator()(error_code, std::size_t)
111 {
112 }
113 };
114
115 char buf[1] = {};
116 net::mutable_buffer m1(buf, sizeof(buf));
117
118 std::weak_ptr<test::stream> wp;
119
120 {
121 net::io_context ioc;
122 {
123 auto sp = std::make_shared<test::stream>(ioc);
124
125 sp->async_read_some(m1, handler{sp});
126 wp = sp;
127 }
128 }
129 BEAST_EXPECT(! wp.lock());
130 }
131
132 void
133 testLifetimeViolation()
134 {
135 // This should assert
136 std::shared_ptr<test::stream> sp;
137 {
138 net::io_context ioc;
139 sp = std::make_shared<test::stream>(ioc);
140 }
141 sp.reset();
142 }
143
144 void
145 run() override
146 {
147 testTestStream();
148 testSharedAbandon();
149 //testLifetimeViolation();
150 }
151 };
152
153 BEAST_DEFINE_TESTSUITE(beast,test,stream);
154
155 } // beast
156 } // boost