awtk/tests/event_source_idle_test.cc

35 lines
1.1 KiB
C++
Raw Normal View History

2019-09-30 12:29:06 +08:00
#include "gtest/gtest.h"
#include "tkc/event_source_idle.h"
static uint32_t s_idle_times = 0;
static ret_t idle_once(const idle_info_t* idle) {
s_idle_times++;
return RET_OK;
}
TEST(EventSourceIdle, basic) {
idle_manager_t* tm = idle_manager_create();
event_source_t* event_source = event_source_idle_create(tm);
ASSERT_EQ(event_source_get_fd(event_source), -1);
ASSERT_EQ(event_source_check(event_source), RET_OK);
2021-09-16 16:06:55 +08:00
ASSERT_EQ(event_source_get_wakeup_time(event_source), 0xffffu);
2019-09-30 12:29:06 +08:00
ASSERT_EQ(event_source_dispatch(event_source), RET_OK);
2021-09-16 16:06:55 +08:00
ASSERT_EQ(s_idle_times, 0u);
2019-09-30 12:29:06 +08:00
2022-09-14 16:04:51 +08:00
uint32_t id = idle_manager_get_next_idle_id(tm);
ASSERT_EQ(id != TK_INVALID_ID, TRUE);
ASSERT_EQ(idle_manager_add_with_id(tm, id, idle_once, NULL), id);
ASSERT_EQ(idle_manager_add_with_id(tm, id, idle_once, NULL), TK_INVALID_ID);
2019-09-30 12:29:06 +08:00
idle_manager_add(tm, idle_once, NULL);
2021-09-16 16:06:55 +08:00
ASSERT_EQ(event_source_get_wakeup_time(event_source), 0u);
2019-09-30 12:29:06 +08:00
ASSERT_EQ(event_source_dispatch(event_source), RET_OK);
2022-09-14 16:04:51 +08:00
ASSERT_EQ(s_idle_times, 2u);
2019-09-30 12:29:06 +08:00
tk_object_unref(TK_OBJECT(event_source));
2019-09-30 12:29:06 +08:00
idle_manager_destroy(tm);
}