#include #include #include #include "exint/event.h" #include "exint/detail.h" #include "c_testcase.h" static std::vector g_vec; ON_EVENT(test) { int* arg = (int*)args; g_vec.push_back(*arg); } SETUP { g_vec.clear(); g_bKeepExintRuning = true; return 0; } TEARDOWN { g_bKeepExintRuning = false; exint_event_thread_exit(); return 0; } TEST_CASE(test_unknow_event) { exint_event("unknow_event", 0, NULL); END_TEST; } TEST_CASE(test_event) { int i = 1; exint_event("test", sizeof(int), &i); assert_eq(g_vec.size(), 1); assert_eq(g_vec[0], i); END_TEST; } TEST_CASE(test_event_thread) { bool started = false; std::thread t([&]() { started = true; exint_event_thread(NULL); }); t.detach(); while (!started) { std::this_thread::sleep_for(std::chrono::milliseconds(1)); } int i = 2; exint_event("test", sizeof(int), &i); for (int i = 0; i < 10; i++) { std::this_thread::sleep_for(std::chrono::milliseconds(1)); if (g_vec.size() != 1) { continue; } assert_eq(g_vec[0], 2); goto end; } assert(false); end: END_TEST; }