2019-09-30 12:29:06 +08:00
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
#include "tkc/socket_pair.h"
|
|
|
|
|
#include "tkc/event_source_idle.h"
|
|
|
|
|
#include "tkc/event_source_timer.h"
|
|
|
|
|
#include "tkc/event_source_manager.h"
|
|
|
|
|
#include "tkc/event_source_manager_default.h"
|
|
|
|
|
|
|
|
|
|
TEST(EventSourceManager, basic) {
|
|
|
|
|
idle_manager_t* tm = idle_manager_create();
|
|
|
|
|
event_source_manager_t* manager = event_source_manager_default_create();
|
|
|
|
|
event_source_t* source = event_source_idle_create(tm);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(event_source_manager_exist(manager, source), FALSE);
|
|
|
|
|
ASSERT_EQ(event_source_manager_add(manager, source), RET_OK);
|
|
|
|
|
ASSERT_EQ(event_source_manager_exist(manager, source), TRUE);
|
|
|
|
|
ASSERT_EQ(event_source_manager_remove(manager, source), RET_OK);
|
|
|
|
|
ASSERT_EQ(event_source_manager_exist(manager, source), FALSE);
|
|
|
|
|
|
2021-12-02 17:57:04 +08:00
|
|
|
|
tk_object_unref(TK_OBJECT(source));
|
2019-09-30 12:29:06 +08:00
|
|
|
|
event_source_manager_destroy(manager);
|
|
|
|
|
idle_manager_destroy(tm);
|
|
|
|
|
}
|
2019-11-07 14:59:03 +08:00
|
|
|
|
|
|
|
|
|
TEST(EventSourceManager, tag) {
|
|
|
|
|
idle_manager_t* tm = idle_manager_create();
|
|
|
|
|
event_source_manager_t* manager = event_source_manager_default_create();
|
|
|
|
|
event_source_t* source1 = event_source_idle_create(tm);
|
|
|
|
|
event_source_t* source2 = event_source_idle_create(tm);
|
|
|
|
|
|
|
|
|
|
event_source_set_tag(source1, tm);
|
|
|
|
|
event_source_set_tag(source2, tm);
|
|
|
|
|
ASSERT_EQ(event_source_manager_add(manager, source1), RET_OK);
|
|
|
|
|
ASSERT_EQ(event_source_manager_add(manager, source2), RET_OK);
|
|
|
|
|
ASSERT_EQ(event_source_manager_exist(manager, source1), TRUE);
|
|
|
|
|
ASSERT_EQ(event_source_manager_exist(manager, source2), TRUE);
|
|
|
|
|
ASSERT_EQ(event_source_manager_remove_by_tag(manager, tm), RET_OK);
|
|
|
|
|
ASSERT_EQ(event_source_manager_exist(manager, source1), FALSE);
|
|
|
|
|
ASSERT_EQ(event_source_manager_exist(manager, source2), FALSE);
|
|
|
|
|
|
2021-12-02 17:57:04 +08:00
|
|
|
|
tk_object_unref(TK_OBJECT(source1));
|
|
|
|
|
tk_object_unref(TK_OBJECT(source2));
|
2019-11-07 14:59:03 +08:00
|
|
|
|
event_source_manager_destroy(manager);
|
|
|
|
|
idle_manager_destroy(tm);
|
|
|
|
|
}
|