| 1 | // Copyright (c) 2023 Klemens D. Morgenstern |
|---|---|
| 2 | // |
| 3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 5 | |
| 6 | #include <boost/cobalt/detail/fork.hpp> |
| 7 | |
| 8 | |
| 9 | #include <boost/cobalt/config.hpp> |
| 10 | using namespace boost; |
| 11 | |
| 12 | #include <boost/test/unit_test.hpp> |
| 13 | #include "test.hpp" |
| 14 | |
| 15 | BOOST_AUTO_TEST_SUITE(fork_); |
| 16 | |
| 17 | struct tester : cobalt::detail::fork::shared_state |
| 18 | { |
| 19 | char buf[4096]; |
| 20 | |
| 21 | tester() : cobalt::detail::fork::shared_state{buf, 4096} {} |
| 22 | |
| 23 | static cobalt::detail::fork step(tester & , int i= 0) |
| 24 | { |
| 25 | if (i == 42) |
| 26 | co_await cobalt::detail::fork::wired_up; |
| 27 | co_return; |
| 28 | } |
| 29 | }; |
| 30 | |
| 31 | CO_TEST_CASE(fork) |
| 32 | { |
| 33 | tester t; |
| 34 | auto x = tester::step(t); |
| 35 | BOOST_CHECK(x.done()); |
| 36 | |
| 37 | x = tester::step(t, i: 42); |
| 38 | |
| 39 | BOOST_CHECK(!x.done()); |
| 40 | co_return; |
| 41 | } |
| 42 | |
| 43 | BOOST_AUTO_TEST_SUITE_END(); |
| 44 |
