Skip to content

Commit

Permalink
加一点点单元测试,看看能不能把覆盖率拉到80%以上
Browse files Browse the repository at this point in the history
  • Loading branch information
owent committed Jan 26, 2018
1 parent d365af4 commit bf3d2c1
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
2 changes: 1 addition & 1 deletion include/libcopp/utils/config/compiler_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
# undef UTIL_CONFIG_COMPILER_IS_ADSP
# define UTIL_CONFIG_COMPILER_IS_ADSP 1

#elif defined(__IAR_SYSTEMS_ICC__ ) || defined(__IAR_SYSTEMS_ICC)
#elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC)
# undef UTIL_CONFIG_COMPILER_IS_IAR
# define UTIL_CONFIG_COMPILER_IS_IAR 1

Expand Down
50 changes: 46 additions & 4 deletions test/case/coroutine_context_base_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
#include <libcopp/coroutine/coroutine_context_container.h>


typedef copp::coroutine_context_container<copp::allocator::stack_allocator_memory>
test_context_base_coroutine_context_test_type;
typedef copp::coroutine_context_container<copp::allocator::stack_allocator_memory> test_context_base_coroutine_context_test_type;

static int g_test_coroutine_base_status = 0;

class test_context_base_foo_runner {
public:
int call_times;
int operator()(void*) {
int operator()(void *) {
++call_times;
++g_test_coroutine_base_status;
copp::this_coroutine::get<test_context_base_coroutine_context_test_type>()->yield();
Expand All @@ -32,12 +31,54 @@ CASE_TEST(coroutine, context_base) {

test_context_base_foo_runner runner;
{
copp::allocator::stack_allocator_memory alloc(stack_buff, 128 * 1024);
copp::stack_context test_move_alloc;

copp::allocator::stack_allocator_memory alloc_created(stack_buff, 128 * 1024);
copp::allocator::stack_allocator_memory alloc(alloc_created);

alloc_created.allocate(test_move_alloc, 64 * 1024);
CASE_EXPECT_EQ(NULL, test_move_alloc.sp);

test_context_base_coroutine_context_test_type::ptr_t co = test_context_base_coroutine_context_test_type::create(&runner, alloc);
runner.call_times = 0;

CASE_EXPECT_TRUE(!!co);

CASE_EXPECT_EQ(::copp::COPP_EC_NOT_RUNNING, co->yield());

co->start();

++g_test_coroutine_base_status;
CASE_EXPECT_EQ(g_test_coroutine_base_status, 3);
co->resume();

++g_test_coroutine_base_status;
CASE_EXPECT_EQ(g_test_coroutine_base_status, 5);

CASE_EXPECT_EQ(::copp::COPP_EC_NOT_READY, co->resume());
CASE_EXPECT_EQ(::copp::COPP_EC_ALREADY_EXIST, co->yield());
}

{
g_test_coroutine_base_status = 1;
copp::stack_context test_move_alloc;

copp::allocator::stack_allocator_memory alloc_created;
alloc_created.attach(stack_buff, 128 * 1024);
copp::allocator::stack_allocator_memory alloc;
alloc = alloc_created;

alloc_created.allocate(test_move_alloc, 64 * 1024);
CASE_EXPECT_EQ(NULL, test_move_alloc.sp);


test_context_base_coroutine_context_test_type::ptr_t co = test_context_base_coroutine_context_test_type::create(&runner, alloc);
runner.call_times = 0;

CASE_EXPECT_TRUE(!!co);

CASE_EXPECT_EQ(::copp::COPP_EC_NOT_RUNNING, co->yield());

co->start();

++g_test_coroutine_base_status;
Expand All @@ -48,6 +89,7 @@ CASE_TEST(coroutine, context_base) {
CASE_EXPECT_EQ(g_test_coroutine_base_status, 5);

CASE_EXPECT_EQ(::copp::COPP_EC_NOT_READY, co->resume());
CASE_EXPECT_EQ(::copp::COPP_EC_ALREADY_EXIST, co->yield());
}

delete[] stack_buff;
Expand Down
4 changes: 4 additions & 0 deletions test/case/coroutine_task_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ CASE_TEST(coroutine_task, custom_action) {

CASE_EXPECT_EQ(g_test_coroutine_task_status, 1);
CASE_EXPECT_FALSE(co_task->is_completed());
CASE_EXPECT_FALSE(co_task->is_canceled());
CASE_EXPECT_FALSE(co_task->is_faulted());

CASE_EXPECT_EQ(0, co_another_task->start(&g_test_coroutine_task_status));
CASE_EXPECT_EQ(g_test_coroutine_task_status, 2);
Expand All @@ -78,6 +80,8 @@ CASE_TEST(coroutine_task, custom_action) {

CASE_EXPECT_TRUE(co_task->is_completed());
CASE_EXPECT_TRUE(co_another_task->is_completed());
CASE_EXPECT_FALSE(co_task->is_canceled());
CASE_EXPECT_FALSE(co_task->is_faulted());

CASE_EXPECT_GT(0, co_another_task->resume(co_another_task.get()));
CASE_EXPECT_EQ(g_test_coroutine_task_status, 4);
Expand Down

0 comments on commit bf3d2c1

Please sign in to comment.