awtk/tests/action_queue_test.cc

57 lines
1.3 KiB
C++
Raw Normal View History

2020-02-07 11:19:46 +08:00
#include "gtest/gtest.h"
#include "tkc/action_queue.h"
#define NR 10
2020-02-13 10:19:58 +08:00
static ret_t qaction_dummy_exec(qaction_t* action) {
return RET_OK;
}
2020-02-07 11:19:46 +08:00
TEST(ActionQueue, basic) {
2020-02-13 10:19:58 +08:00
qaction_t* r = NULL;
2020-02-07 11:19:46 +08:00
action_queue_t* q = action_queue_create(NR);
2020-02-13 10:19:58 +08:00
qaction_t* w = qaction_create(qaction_dummy_exec, NULL, 0);
2020-02-07 11:19:46 +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);
2020-02-13 10:19:58 +08:00
w->args[0] = 1234;
2020-02-07 11:19:46 +08:00
ASSERT_EQ(action_queue_recv(q, &r), RET_FAIL);
2020-02-13 10:19:58 +08:00
ASSERT_EQ(action_queue_send(q, w), RET_OK);
2020-02-07 11:19:46 +08:00
ASSERT_EQ(action_queue_recv(q, &r), RET_OK);
2020-02-13 10:19:58 +08:00
ASSERT_EQ(r, w);
2020-02-07 11:19:46 +08:00
ASSERT_EQ(action_queue_recv(q, &r), RET_FAIL);
2020-02-13 10:19:58 +08:00
qaction_destroy(w);
action_queue_destroy(q);
}
TEST(ActionQueue, multi) {
uint32_t i = 0;
qaction_t* r = NULL;
action_queue_t* q = action_queue_create(NR);
2020-02-07 11:19:46 +08:00
for (i = 0; i < NR; i++) {
2020-02-13 10:19:58 +08:00
qaction_t* w = qaction_create(qaction_dummy_exec, NULL, 0);
w->args[0] = i;
ASSERT_EQ(action_queue_send(q, w), RET_OK);
2020-02-07 11:19:46 +08:00
}
for (i = 0; i < NR; i++) {
ASSERT_EQ(action_queue_recv(q, &r), RET_OK);
2020-02-13 10:19:58 +08:00
ASSERT_EQ(r->args[0], i);
qaction_destroy(r);
2020-02-07 11:19:46 +08:00
}
2020-02-13 10:19:58 +08:00
for (i = 0; i < NR; i++) {
qaction_t* w = qaction_create(qaction_dummy_exec, NULL, 0);
w->args[0] = i;
ASSERT_EQ(action_queue_send(q, w), RET_OK);
}
2020-02-07 11:19:46 +08:00
action_queue_destroy(q);
}