]>
Commit | Line | Data |
---|---|---|
20effc67 TL |
1 | // |
2 | // set_done.cpp | |
3 | // ~~~~~~~~~~~~ | |
4 | // | |
f51cf556 | 5 | // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com) |
20effc67 TL |
6 | // |
7 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
8 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
9 | // | |
10 | ||
11 | // Disable autolinking for unit tests. | |
12 | #if !defined(BOOST_ALL_NO_LIB) | |
13 | #define BOOST_ALL_NO_LIB 1 | |
14 | #endif // !defined(BOOST_ALL_NO_LIB) | |
15 | ||
16 | // Test that header file is self-contained. | |
17 | #include <boost/asio/execution/set_done.hpp> | |
18 | ||
19 | #include <boost/system/error_code.hpp> | |
20 | #include "../unit_test.hpp" | |
21 | ||
f51cf556 TL |
22 | #if !defined(BOOST_ASIO_NO_DEPRECATED) |
23 | ||
20effc67 TL |
24 | namespace exec = boost::asio::execution; |
25 | ||
26 | static int call_count = 0; | |
27 | ||
28 | struct no_set_done | |
29 | { | |
30 | }; | |
31 | ||
32 | struct const_member_set_done | |
33 | { | |
34 | void set_done() const BOOST_ASIO_NOEXCEPT | |
35 | { | |
36 | ++call_count; | |
37 | } | |
38 | }; | |
39 | ||
40 | #if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT) | |
41 | ||
42 | namespace boost { | |
43 | namespace asio { | |
44 | namespace traits { | |
45 | ||
46 | template <> | |
47 | struct set_done_member<const const_member_set_done> | |
48 | { | |
49 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true); | |
50 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true); | |
51 | typedef void result_type; | |
52 | }; | |
53 | ||
54 | } // namespace traits | |
55 | } // namespace asio | |
56 | } // namespace boost | |
57 | ||
58 | #endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT) | |
59 | ||
60 | struct free_set_done_const_receiver | |
61 | { | |
62 | friend void set_done(const free_set_done_const_receiver&) BOOST_ASIO_NOEXCEPT | |
63 | { | |
64 | ++call_count; | |
65 | } | |
66 | }; | |
67 | ||
68 | #if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_FREE_TRAIT) | |
69 | ||
70 | namespace boost { | |
71 | namespace asio { | |
72 | namespace traits { | |
73 | ||
74 | template <> | |
75 | struct set_done_free<const free_set_done_const_receiver> | |
76 | { | |
77 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true); | |
78 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true); | |
79 | typedef void result_type; | |
80 | }; | |
81 | ||
82 | } // namespace traits | |
83 | } // namespace asio | |
84 | } // namespace boost | |
85 | ||
86 | #endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_FREE_TRAIT) | |
87 | ||
88 | struct non_const_member_set_done | |
89 | { | |
90 | void set_done() BOOST_ASIO_NOEXCEPT | |
91 | { | |
92 | ++call_count; | |
93 | } | |
94 | }; | |
95 | ||
96 | #if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT) | |
97 | ||
98 | namespace boost { | |
99 | namespace asio { | |
100 | namespace traits { | |
101 | ||
102 | template <> | |
103 | struct set_done_member<non_const_member_set_done> | |
104 | { | |
105 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true); | |
106 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true); | |
107 | typedef void result_type; | |
108 | }; | |
109 | ||
110 | } // namespace traits | |
111 | } // namespace asio | |
112 | } // namespace boost | |
113 | ||
114 | #endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_MEMBER_TRAIT) | |
115 | ||
116 | struct free_set_done_non_const_receiver | |
117 | { | |
118 | friend void set_done(free_set_done_non_const_receiver&) BOOST_ASIO_NOEXCEPT | |
119 | { | |
120 | ++call_count; | |
121 | } | |
122 | }; | |
123 | ||
124 | #if !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_FREE_TRAIT) | |
125 | ||
126 | namespace boost { | |
127 | namespace asio { | |
128 | namespace traits { | |
129 | ||
130 | template <> | |
131 | struct set_done_free<free_set_done_non_const_receiver> | |
132 | { | |
133 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_valid = true); | |
134 | BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true); | |
135 | typedef void result_type; | |
136 | }; | |
137 | ||
138 | } // namespace traits | |
139 | } // namespace asio | |
140 | } // namespace boost | |
141 | ||
142 | #endif // !defined(BOOST_ASIO_HAS_DEDUCED_SET_DONE_FREE_TRAIT) | |
143 | ||
144 | void test_can_set_done() | |
145 | { | |
146 | BOOST_ASIO_CONSTEXPR bool b1 = exec::can_set_done< | |
147 | no_set_done&>::value; | |
148 | BOOST_ASIO_CHECK(b1 == false); | |
149 | ||
150 | BOOST_ASIO_CONSTEXPR bool b2 = exec::can_set_done< | |
151 | const no_set_done&>::value; | |
152 | BOOST_ASIO_CHECK(b2 == false); | |
153 | ||
154 | BOOST_ASIO_CONSTEXPR bool b3 = exec::can_set_done< | |
155 | const_member_set_done&>::value; | |
156 | BOOST_ASIO_CHECK(b3 == true); | |
157 | ||
158 | BOOST_ASIO_CONSTEXPR bool b4 = exec::can_set_done< | |
159 | const const_member_set_done&>::value; | |
160 | BOOST_ASIO_CHECK(b4 == true); | |
161 | ||
162 | BOOST_ASIO_CONSTEXPR bool b5 = exec::can_set_done< | |
163 | free_set_done_const_receiver&>::value; | |
164 | BOOST_ASIO_CHECK(b5 == true); | |
165 | ||
166 | BOOST_ASIO_CONSTEXPR bool b6 = exec::can_set_done< | |
167 | const free_set_done_const_receiver&>::value; | |
168 | BOOST_ASIO_CHECK(b6 == true); | |
169 | ||
170 | BOOST_ASIO_CONSTEXPR bool b7 = exec::can_set_done< | |
171 | non_const_member_set_done&>::value; | |
172 | BOOST_ASIO_CHECK(b7 == true); | |
173 | ||
174 | BOOST_ASIO_CONSTEXPR bool b8 = exec::can_set_done< | |
175 | const non_const_member_set_done&>::value; | |
176 | BOOST_ASIO_CHECK(b8 == false); | |
177 | ||
178 | BOOST_ASIO_CONSTEXPR bool b9 = exec::can_set_done< | |
179 | free_set_done_non_const_receiver&>::value; | |
180 | BOOST_ASIO_CHECK(b9 == true); | |
181 | ||
182 | BOOST_ASIO_CONSTEXPR bool b10 = exec::can_set_done< | |
183 | const free_set_done_non_const_receiver&>::value; | |
184 | BOOST_ASIO_CHECK(b10 == false); | |
185 | } | |
186 | ||
187 | void increment(int* count) | |
188 | { | |
189 | ++(*count); | |
190 | } | |
191 | ||
192 | void test_set_done() | |
193 | { | |
194 | call_count = 0; | |
195 | const_member_set_done ex1 = {}; | |
196 | exec::set_done(ex1); | |
197 | BOOST_ASIO_CHECK(call_count == 1); | |
198 | ||
199 | call_count = 0; | |
200 | const const_member_set_done ex2 = {}; | |
201 | exec::set_done(ex2); | |
202 | BOOST_ASIO_CHECK(call_count == 1); | |
203 | ||
204 | call_count = 0; | |
205 | exec::set_done(const_member_set_done()); | |
206 | BOOST_ASIO_CHECK(call_count == 1); | |
207 | ||
208 | call_count = 0; | |
209 | free_set_done_const_receiver ex3 = {}; | |
210 | exec::set_done(ex3); | |
211 | BOOST_ASIO_CHECK(call_count == 1); | |
212 | ||
213 | call_count = 0; | |
214 | const free_set_done_const_receiver ex4 = {}; | |
215 | exec::set_done(ex4); | |
216 | BOOST_ASIO_CHECK(call_count == 1); | |
217 | ||
218 | call_count = 0; | |
219 | exec::set_done(free_set_done_const_receiver()); | |
220 | BOOST_ASIO_CHECK(call_count == 1); | |
221 | ||
222 | call_count = 0; | |
223 | non_const_member_set_done ex5 = {}; | |
224 | exec::set_done(ex5); | |
225 | BOOST_ASIO_CHECK(call_count == 1); | |
226 | ||
227 | call_count = 0; | |
228 | free_set_done_non_const_receiver ex6 = {}; | |
229 | exec::set_done(ex6); | |
230 | BOOST_ASIO_CHECK(call_count == 1); | |
231 | } | |
232 | ||
233 | BOOST_ASIO_TEST_SUITE | |
234 | ( | |
235 | "set_done", | |
236 | BOOST_ASIO_TEST_CASE(test_can_set_done) | |
237 | BOOST_ASIO_TEST_CASE(test_set_done) | |
238 | ) | |
f51cf556 TL |
239 | |
240 | #else // !defined(BOOST_ASIO_NO_DEPRECATED) | |
241 | ||
242 | BOOST_ASIO_TEST_SUITE | |
243 | ( | |
244 | "set_done", | |
245 | BOOST_ASIO_TEST_CASE(null_test) | |
246 | ) | |
247 | ||
248 | #endif // !defined(BOOST_ASIO_NO_DEPRECATED) |