libcopp
2.2.0
test
case
coroutine_context_private_data_test.cpp
Go to the documentation of this file.
1
// Copyright 2023 owent
2
3
#include <
libcopp/coroutine/coroutine_context_container.h
>
4
5
#include <cstdio>
6
#include <cstring>
7
#include <iostream>
8
9
#include "
frame/test_macros.h
"
10
11
typedef
copp::coroutine_context_container<copp::allocator::default_statck_allocator>
12
test_context_private_data_context_type
;
13
14
static
int
g_test_coroutine_private_data_status
= 0;
15
16
class
test_context_private_data_foo_runner
{
17
public
:
18
int
operator()
(
void
*priv_data) {
19
++
g_test_coroutine_private_data_status
;
20
CASE_EXPECT_EQ
(
g_test_coroutine_private_data_status
, 2);
21
CASE_EXPECT_EQ
(&
g_test_coroutine_private_data_status
, priv_data);
22
23
copp::this_coroutine::get<test_context_private_data_context_type>()->resume();
24
++
g_test_coroutine_private_data_status
;
25
CASE_EXPECT_EQ
(
g_test_coroutine_private_data_status
, 3);
26
27
copp::this_coroutine::get<test_context_private_data_context_type>()->yield(&priv_data);
28
++
g_test_coroutine_private_data_status
;
29
30
CASE_EXPECT_EQ
(copp::this_coroutine::get<test_context_private_data_context_type>(), priv_data);
31
CASE_EXPECT_EQ
(
g_test_coroutine_private_data_status
, 5);
32
33
return
0;
34
}
35
};
36
37
CASE_TEST
(coroutine, context_private_data) {
38
g_test_coroutine_private_data_status
= 0;
39
40
++
g_test_coroutine_private_data_status
;
41
CASE_EXPECT_EQ
(
g_test_coroutine_private_data_status
, 1);
42
43
test_context_private_data_context_type::ptr_t co =
44
test_context_private_data_context_type::create(
test_context_private_data_foo_runner
());
45
co->start(&
g_test_coroutine_private_data_status
);
46
47
++
g_test_coroutine_private_data_status
;
48
CASE_EXPECT_EQ
(
g_test_coroutine_private_data_status
, 4);
49
co->resume(co.get());
50
51
++
g_test_coroutine_private_data_status
;
52
CASE_EXPECT_EQ
(
g_test_coroutine_private_data_status
, 6);
53
}
test_context_private_data_foo_runner
Definition:
coroutine_context_private_data_test.cpp:16
test_context_private_data_foo_runner::operator()
int operator()(void *priv_data)
Definition:
coroutine_context_private_data_test.cpp:18
coroutine_context_container.h
CASE_TEST
CASE_TEST(coroutine, context_private_data)
Definition:
coroutine_context_private_data_test.cpp:37
g_test_coroutine_private_data_status
static int g_test_coroutine_private_data_status
Definition:
coroutine_context_private_data_test.cpp:14
test_context_private_data_context_type
copp::coroutine_context_container< copp::allocator::default_statck_allocator > test_context_private_data_context_type
Definition:
coroutine_context_private_data_test.cpp:12
test_macros.h
CASE_EXPECT_EQ
#define CASE_EXPECT_EQ(l, r)
Definition:
test_macros.h:96
Generated by
1.9.1