Skip to content

Commit eb93e70

Browse files
committed
Add tests [8] --filter=[core] --asan
1 parent 3f3fda7 commit eb93e70

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

core-tests/src/coroutine/base.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ TEST(coroutine_base, get_init_msec) {
3535

3636
TEST(coroutine_base, yield_resume) {
3737
Coroutine::set_on_yield([](void *arg) {
38-
long task = *(long *) Coroutine::get_current_task();
39-
ASSERT_EQ(task, Coroutine::get_current_cid());
38+
auto task = static_cast<long *>(Coroutine::get_current_task());
39+
ASSERT_NE(task, nullptr);
40+
ASSERT_EQ(*task, Coroutine::get_current_cid());
4041
});
4142

4243
Coroutine::set_on_resume([](void *arg) {
@@ -45,18 +46,19 @@ TEST(coroutine_base, yield_resume) {
4546
});
4647

4748
Coroutine::set_on_close([](void *arg) {
48-
long task = *(long *) Coroutine::get_current_task();
49-
ASSERT_EQ(task, Coroutine::get_current_cid());
49+
auto task = static_cast<long *>(Coroutine::get_current_task());
50+
ASSERT_NE(task, nullptr);
51+
ASSERT_EQ(*task, Coroutine::get_current_cid());
5052
});
5153

52-
long _cid;
54+
long _cid, _cid2;
5355
long cid = Coroutine::create(
54-
[](void *arg) {
55-
long cid = Coroutine::get_current_cid();
56-
Coroutine *co = Coroutine::get_by_cid(cid);
57-
co->set_task((void *) &cid);
56+
[&_cid2](void *arg) {
57+
_cid2 = Coroutine::get_current_cid();
58+
Coroutine *co = Coroutine::get_by_cid(_cid2);
59+
co->set_task(&_cid2);
5860
co->yield();
59-
*(long *) arg = Coroutine::get_current_cid();
61+
*static_cast<long *>(arg) = Coroutine::get_current_cid();
6062
},
6163
&_cid);
6264

0 commit comments

Comments
 (0)