awtk/tests/event_queue_test.cc

57 lines
1.4 KiB
C++
Raw Normal View History

2018-06-27 13:46:42 +08:00
#include "gtest/gtest.h"
2018-03-13 21:23:34 +08:00
#include "base/event_queue.h"
#define NR 10
TEST(EventQueue, basic) {
uint16_t i = 0;
event_queue_req_t r;
event_queue_req_t w;
2018-03-13 21:23:34 +08:00
event_queue_t* q = event_queue_create(NR);
2018-08-04 11:58:43 +08:00
memset(&r, 0x00, sizeof(r));
memset(&w, 0x00, sizeof(w));
2018-03-13 21:23:34 +08:00
ASSERT_EQ(q != NULL, true);
ASSERT_EQ(q->r, 0);
ASSERT_EQ(q->w, 0);
ASSERT_EQ(q->full, FALSE);
ASSERT_EQ(q->capacity, 10);
memset(&r, 0x00, sizeof(r));
memset(&r, 0x00, sizeof(w));
w.pointer_event.e.type = EVT_POINTER_DOWN;
w.pointer_event.x = 100;
w.pointer_event.y = 200;
2018-03-13 21:23:34 +08:00
ASSERT_EQ(event_queue_recv(q, &r), RET_FAIL);
ASSERT_EQ(event_queue_send(q, &w), RET_OK);
ASSERT_EQ(event_queue_recv(q, &r), RET_OK);
ASSERT_EQ(memcmp(&r, &w, sizeof(r)), 0);
ASSERT_EQ(event_queue_recv(q, &r), RET_FAIL);
2018-03-15 22:07:01 +08:00
for (i = 0; i < NR; i++) {
w.pointer_event.e.type = i;
2018-03-13 21:23:34 +08:00
ASSERT_EQ(event_queue_send(q, &w), RET_OK);
}
ASSERT_EQ(q->full, TRUE);
ASSERT_EQ(event_queue_send(q, &w), RET_FAIL);
2018-03-15 22:07:01 +08:00
for (i = 0; i < NR; i++) {
2018-03-13 21:23:34 +08:00
ASSERT_EQ(event_queue_recv(q, &r), RET_OK);
ASSERT_EQ(r.pointer_event.e.type, i);
2018-03-13 21:23:34 +08:00
}
ASSERT_EQ(event_queue_recv(q, &r), RET_FAIL);
ASSERT_EQ(q->full, FALSE);
2018-03-15 22:07:01 +08:00
w.pointer_event.e.type = 1;
2018-03-13 21:23:34 +08:00
ASSERT_EQ(event_queue_send(q, &w), RET_OK);
2018-03-15 22:07:01 +08:00
w.pointer_event.e.type = 2;
2018-03-13 21:23:34 +08:00
ASSERT_EQ(event_queue_replace_last(q, &w), RET_OK);
ASSERT_EQ(event_queue_recv(q, &r), RET_OK);
ASSERT_EQ(memcmp(&r, &w, sizeof(r)), 0);
event_queue_destroy(q);
}