11#if defined(LIBCOPP_MACRO_ENABLE_WIN_FIBER) && LIBCOPP_MACRO_ENABLE_WIN_FIBER
13typedef copp::coroutine_fiber_context_default test_coroutine_context_fiber_test_type;
15static int g_test_coroutine_fiber_status = 0;
17class test_context_fiber_foo_runner {
19 test_context_fiber_foo_runner() : call_times(0) {}
21 int operator()(
void *) {
23 ++g_test_coroutine_fiber_status;
24 copp::this_fiber::get<test_coroutine_context_fiber_test_type>()->yield();
26 ++g_test_coroutine_fiber_status;
32 g_test_coroutine_fiber_status = 0;
33 ++g_test_coroutine_fiber_status;
36 test_context_fiber_foo_runner runner;
38 copp::stack_context test_move_alloc;
40 test_coroutine_context_fiber_test_type::ptr_t co = test_coroutine_context_fiber_test_type::create(&runner);
41 runner.call_times = 0;
45 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_NOT_RUNNING, co->yield());
49 ++g_test_coroutine_fiber_status;
53 ++g_test_coroutine_fiber_status;
56 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_NOT_READY, co->resume());
57 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_ALREADY_EXIST, co->yield());
61 g_test_coroutine_fiber_status = 1;
62 copp::stack_context test_move_alloc;
64 test_coroutine_context_fiber_test_type::ptr_t co = test_coroutine_context_fiber_test_type::create(&runner);
65 runner.call_times = 0;
69 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_NOT_RUNNING, co->yield());
73 ++g_test_coroutine_fiber_status;
77 ++g_test_coroutine_fiber_status;
80 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_NOT_READY, co->resume());
81 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_ALREADY_EXIST, co->yield());
85CASE_TEST(coroutine_fiber, shared_runner) {
86 g_test_coroutine_fiber_status = 0;
87 ++g_test_coroutine_fiber_status;
90 test_context_fiber_foo_runner runner;
91 runner.call_times = 0;
94 test_coroutine_context_fiber_test_type::ptr_t co[4];
95 for (
int i = 0; i < 4; ++i) {
96 co[i] = test_coroutine_context_fiber_test_type::create(&runner);
102 for (
int i = 0; i < 4; ++i) {
112# if defined(LIBCOPP_MACRO_ENABLE_STD_EXCEPTION_PTR) && LIBCOPP_MACRO_ENABLE_STD_EXCEPTION_PTR
113static int test_context_fiber_foo_runner_throw_exception(
void *) {
return static_cast<int>(std::string().at(1)); }
115CASE_TEST(coroutine_fiber, coroutine_context_throw_exception) {
117 copp::stack_context test_move_alloc;
119 test_coroutine_context_fiber_test_type::ptr_t co =
120 test_coroutine_context_fiber_test_type::create(test_context_fiber_foo_runner_throw_exception);
124 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_NOT_RUNNING, co->yield());
127 }
catch (
const std::exception &e) {
128 CASE_MSG_INFO() <<
"Caught exception \"" << e.what() <<
"\"" << std::endl;
#define CASE_EXPECT_EQ(l, r)
#define CASE_TEST(test_name, case_name)
#define CASE_EXPECT_TRUE(c)