extern_interface/tests/test_event.cpp

56 lines
1005 B
C++

#include <vector>
#include <thread>
#include <unistd.h>
#include "exint/event.h"
#include "exint/detail.h"
#include "c_testcase.h"
static std::vector<int> g_vec;
ON_EVENT(test) {
int* arg = (int*)args;
g_vec.push_back(*arg);
}
SETUP {
g_vec.clear();
return 0;
}
TEARDOWN {
exint_event_thread_stop();
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) {
exint_event_thread_start(2);
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:
exint_event_thread_stop();
END_TEST;
}