]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/asio/test/coroutine.cpp
5 // Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
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)
16 // Test that header file is self-contained.
17 #include <boost/asio/coroutine.hpp>
19 #include "unit_test.hpp"
21 // Must come after all other headers.
22 #include <boost/asio/yield.hpp>
24 //------------------------------------------------------------------------------
26 // Coroutine completes via yield break.
28 void yield_break_coro(boost::asio::coroutine
& coro
)
37 void yield_break_test()
39 boost::asio::coroutine coro
;
40 BOOST_ASIO_CHECK(!coro
.is_complete());
41 yield_break_coro(coro
);
42 BOOST_ASIO_CHECK(!coro
.is_complete());
43 yield_break_coro(coro
);
44 BOOST_ASIO_CHECK(coro
.is_complete());
47 //------------------------------------------------------------------------------
49 // Coroutine completes via return.
51 void return_coro(boost::asio::coroutine
& coro
)
61 boost::asio::coroutine coro
;
63 BOOST_ASIO_CHECK(coro
.is_complete());
66 //------------------------------------------------------------------------------
68 // Coroutine completes via exception.
70 void exception_coro(boost::asio::coroutine
& coro
)
80 boost::asio::coroutine coro
;
81 try { exception_coro(coro
); } catch (int) {}
82 BOOST_ASIO_CHECK(coro
.is_complete());
85 //------------------------------------------------------------------------------
87 // Coroutine completes by falling off the end.
89 void fall_off_end_coro(boost::asio::coroutine
& coro
)
96 void fall_off_end_test()
98 boost::asio::coroutine coro
;
99 fall_off_end_coro(coro
);
100 BOOST_ASIO_CHECK(coro
.is_complete());
103 //------------------------------------------------------------------------------
105 BOOST_ASIO_TEST_SUITE
108 BOOST_ASIO_TEST_CASE(yield_break_test
)
109 BOOST_ASIO_TEST_CASE(return_test
)
110 BOOST_ASIO_TEST_CASE(exception_test
)
111 BOOST_ASIO_TEST_CASE(fall_off_end_test
)