14 copp::coroutine_context_container<copp::allocator::stack_allocator_memory>;
16#if defined(LIBCOPP_MACRO_ENABLE_WIN_FIBER) && LIBCOPP_MACRO_ENABLE_WIN_FIBER
17using test_context_channel_coroutine_context_fiber_test_type =
18 copp::coroutine_context_fiber_container<copp::allocator::stack_allocator_memory>;
28 int operator()(copp::copp_error_code err_code) {
return static_cast<int>(err_code) - 10000; }
42 return copp::this_coroutine::get<test_context_channel_coroutine_context_test_type>();
46#if defined(LIBCOPP_MACRO_ENABLE_WIN_FIBER) && LIBCOPP_MACRO_ENABLE_WIN_FIBER
49 static test_context_channel_coroutine_context_fiber_test_type *
get() {
50 return copp::this_fiber::get<test_context_channel_coroutine_context_fiber_test_type>();
55template <
class TCTX,
class T>
62 copp::memory::strong_rc_ptr<copp::stackful_channel_sender<T>>
sender;
66 auto ret = copp::make_stackful_channel<T>();
67 sender = copp::memory::make_strong_rc<copp::stackful_channel_sender<T>>(ret.second);
68 return std::move(ret.first);
88 unsigned char *stack_buff =
new unsigned char[128 * 1024];
95 copp::stack_context test_move_alloc;
97 copp::allocator::stack_allocator_memory alloc_created(stack_buff, 128 * 1024);
98 copp::allocator::stack_allocator_memory alloc(alloc_created);
100 alloc_created.allocate(test_move_alloc, 64 * 1024);
103 test_context_channel_coroutine_context_test_type::ptr_t co =
104 test_context_channel_coroutine_context_test_type::create(&runner, alloc);
113 runner.
sender->set_value(137);
118 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_NOT_READY, co->resume());
119 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_ALREADY_EXIST, co->yield());
126 copp::stack_context test_move_alloc;
128 copp::allocator::stack_allocator_memory alloc_created(stack_buff, 128 * 1024);
129 copp::allocator::stack_allocator_memory alloc(alloc_created);
131 alloc_created.allocate(test_move_alloc, 64 * 1024);
134 test_context_channel_coroutine_context_test_type::ptr_t co =
135 test_context_channel_coroutine_context_test_type::create(&runner, alloc);
149 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_NOT_READY, co->resume());
150 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_ALREADY_EXIST, co->yield());
157 copp::stack_context test_move_alloc;
159 copp::allocator::stack_allocator_memory alloc_created(stack_buff, 128 * 1024);
160 copp::allocator::stack_allocator_memory alloc(alloc_created);
162 alloc_created.allocate(test_move_alloc, 64 * 1024);
165 test_context_channel_coroutine_context_test_type::ptr_t co =
166 test_context_channel_coroutine_context_test_type::create(&runner, alloc);
181 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_NOT_READY, co->resume());
182 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_ALREADY_EXIST, co->yield());
189 unsigned char *stack_buff =
new unsigned char[128 * 1024];
196 copp::stack_context test_move_alloc;
198 copp::allocator::stack_allocator_memory alloc_created(stack_buff, 128 * 1024);
199 copp::allocator::stack_allocator_memory alloc(alloc_created);
201 alloc_created.allocate(test_move_alloc, 64 * 1024);
204 test_context_channel_coroutine_context_test_type::ptr_t co =
205 test_context_channel_coroutine_context_test_type::create(&runner, alloc);
214 runner.
sender->set_value(
reinterpret_cast<int *
>(stack_buff));
219 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_NOT_READY, co->resume());
220 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_ALREADY_EXIST, co->yield());
227 copp::stack_context test_move_alloc;
229 copp::allocator::stack_allocator_memory alloc_created(stack_buff, 128 * 1024);
230 copp::allocator::stack_allocator_memory alloc(alloc_created);
232 alloc_created.allocate(test_move_alloc, 64 * 1024);
235 test_context_channel_coroutine_context_test_type::ptr_t co =
236 test_context_channel_coroutine_context_test_type::create(&runner, alloc);
250 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_NOT_READY, co->resume());
251 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_ALREADY_EXIST, co->yield());
258 copp::stack_context test_move_alloc;
260 copp::allocator::stack_allocator_memory alloc_created(stack_buff, 128 * 1024);
261 copp::allocator::stack_allocator_memory alloc(alloc_created);
263 alloc_created.allocate(test_move_alloc, 64 * 1024);
266 test_context_channel_coroutine_context_test_type::ptr_t co =
267 test_context_channel_coroutine_context_test_type::create(&runner, alloc);
282 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_NOT_READY, co->resume());
283 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_ALREADY_EXIST, co->yield());
289#if defined(LIBCOPP_MACRO_ENABLE_WIN_FIBER) && LIBCOPP_MACRO_ENABLE_WIN_FIBER
291CASE_TEST(coroutine_channel, fiber_channel_int) {
292 unsigned char *stack_buff =
new unsigned char[128 * 1024];
299 copp::stack_context test_move_alloc;
301 copp::allocator::stack_allocator_memory alloc_created(stack_buff, 128 * 1024);
302 copp::allocator::stack_allocator_memory alloc(alloc_created);
304 alloc_created.allocate(test_move_alloc, 64 * 1024);
307 test_context_channel_coroutine_context_fiber_test_type::ptr_t co =
308 test_context_channel_coroutine_context_fiber_test_type::create(&runner, alloc);
317 runner.
sender->set_value(157);
322 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_NOT_READY, co->resume());
323 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_ALREADY_EXIST, co->yield());
330 copp::stack_context test_move_alloc;
332 copp::allocator::stack_allocator_memory alloc_created(stack_buff, 128 * 1024);
333 copp::allocator::stack_allocator_memory alloc(alloc_created);
335 alloc_created.allocate(test_move_alloc, 64 * 1024);
338 test_context_channel_coroutine_context_fiber_test_type::ptr_t co =
339 test_context_channel_coroutine_context_fiber_test_type::create(&runner, alloc);
353 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_NOT_READY, co->resume());
354 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_ALREADY_EXIST, co->yield());
361 copp::stack_context test_move_alloc;
363 copp::allocator::stack_allocator_memory alloc_created(stack_buff, 128 * 1024);
364 copp::allocator::stack_allocator_memory alloc(alloc_created);
366 alloc_created.allocate(test_move_alloc, 64 * 1024);
369 test_context_channel_coroutine_context_fiber_test_type::ptr_t co =
370 test_context_channel_coroutine_context_fiber_test_type::create(&runner, alloc);
385 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_NOT_READY, co->resume());
386 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_ALREADY_EXIST, co->yield());
392CASE_TEST(coroutine_channel, fiber_channel_pointer) {
393 unsigned char *stack_buff =
new unsigned char[128 * 1024];
400 copp::stack_context test_move_alloc;
402 copp::allocator::stack_allocator_memory alloc_created(stack_buff, 128 * 1024);
403 copp::allocator::stack_allocator_memory alloc(alloc_created);
405 alloc_created.allocate(test_move_alloc, 64 * 1024);
408 test_context_channel_coroutine_context_fiber_test_type::ptr_t co =
409 test_context_channel_coroutine_context_fiber_test_type::create(&runner, alloc);
418 runner.
sender->set_value(
reinterpret_cast<int *
>(stack_buff));
423 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_NOT_READY, co->resume());
424 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_ALREADY_EXIST, co->yield());
431 copp::stack_context test_move_alloc;
433 copp::allocator::stack_allocator_memory alloc_created(stack_buff, 128 * 1024);
434 copp::allocator::stack_allocator_memory alloc(alloc_created);
436 alloc_created.allocate(test_move_alloc, 64 * 1024);
439 test_context_channel_coroutine_context_fiber_test_type::ptr_t co =
440 test_context_channel_coroutine_context_fiber_test_type::create(&runner, alloc);
454 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_NOT_READY, co->resume());
455 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_ALREADY_EXIST, co->yield());
462 copp::stack_context test_move_alloc;
464 copp::allocator::stack_allocator_memory alloc_created(stack_buff, 128 * 1024);
465 copp::allocator::stack_allocator_memory alloc(alloc_created);
467 alloc_created.allocate(test_move_alloc, 64 * 1024);
470 test_context_channel_coroutine_context_fiber_test_type::ptr_t co =
471 test_context_channel_coroutine_context_fiber_test_type::create(&runner, alloc);
486 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_NOT_READY, co->resume());
487 CASE_EXPECT_EQ(LIBCOPP_COPP_NAMESPACE_ID::COPP_EC_ALREADY_EXIST, co->yield());
copp::memory::strong_rc_ptr< copp::stackful_channel_sender< T > > sender
test_context_channel_foo_runner()
copp::stackful_channel_receiver< T > create_channel()
static int g_test_coroutine_channel_status
copp::coroutine_context_container< copp::allocator::stack_allocator_memory > test_context_channel_coroutine_context_test_type
LIBCOPP_COPP_API_HEAD_ONLY Tc * get()
get current coroutine and try to convert type
int operator()(copp::copp_error_code err_code)
int * operator()(copp::copp_error_code)
static test_context_channel_coroutine_context_test_type * get()
#define CASE_EXPECT_EQ(l, r)
#define CASE_TEST(test_name, case_name)
#define CASE_EXPECT_TRUE(c)