diff options
Diffstat (limited to 'test/pbdrv')
-rw-r--r-- | test/pbdrv/cmd.cpp | 52 | ||||
-rw-r--r-- | test/pbdrv/msg.cpp | 30 | ||||
-rw-r--r-- | test/pbdrv/msg.h (renamed from test/pbdrv/cmd.h) | 0 |
3 files changed, 30 insertions, 52 deletions
diff --git a/test/pbdrv/cmd.cpp b/test/pbdrv/cmd.cpp deleted file mode 100644 index 8b7ee89..0000000 --- a/test/pbdrv/cmd.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include <gtest/gtest.h> - -#include "pb-write.h" -#include "pb-read.h" - -#include "cmd.h" - -// sorry for metaprogramming -#define test_cmd(fn) \ - TEST(pbdrv_cmd, fn) { \ - pbdrv_buf_t cmd = pbdrv_write_cmd_##fn(expected_##fn); \ - ASSERT_NE(cmd.data, nullptr); \ - ASSERT_GE(cmd.size, 0); \ - } - -// test_cmd(req_read); -// test_cmd(res_read); -// test_cmd(req_write); -// test_cmd(req_state); -// test_cmd(res_state); -// test_cmd(req_set_state); -// test_cmd(magic); - -TEST(pbdrv_cmd_rw, magic) { - pb_cmd_req_read_t content = { - .propid = 0, - }; - pb_msg_t msg = { - .type = PB_CMD_REQ_READ, - .sender = 0xff, - .msg = &content, - }; - pbdrv_buf_t buf = pbdrv_write_msg(&msg); - - ASSERT_NE(buf.data, nullptr); - ASSERT_GE(buf.size, 0); - - // void * _cmd = NULL; - // pb_cmd_id type = pbdrv_read_msg(); - // ASSERT_EQ(type, PB_CMD_MAGIC); -} - -// pb_cmd_req_read_t * msg = (pb_cmd_req_read_t *) pbdrv_read_unknown(cmd_req_read.data, cmd_req_read.size); -// ASSERT_NE(msg, nullptr); -// ASSERT_EQ(msg->header.type, PB_CMD_REQ_READ); - -// TEST(pbdrv, read_cmd_res_read) { } -// TEST(pbdrv, read_cmd_req_state) { } -// TEST(pbdrv, read_cmd_res_state) { } -// TEST(pbdrv, read_cmd_req_set_state) { } -// TEST(pbdrv, read_cmd_magic) { } - diff --git a/test/pbdrv/msg.cpp b/test/pbdrv/msg.cpp new file mode 100644 index 0000000..3d2b48d --- /dev/null +++ b/test/pbdrv/msg.cpp @@ -0,0 +1,30 @@ +#include <gtest/gtest.h> + +#include "pb-msg.h" + +TEST(pbdrv_msg_rw, cmd_req_read) { + pb_cmd_req_read_t content = { + .propid = 2, + }; + pb_msg_t msg_write = { + .type = PB_CMD_REQ_READ, + .sender = 0xff, + .msg = &content, + }; + pbdrv_buf_t buf = pbdrv_msg_write(&msg_write); + + ASSERT_NE(buf.data, nullptr); + ASSERT_GE(buf.size, 0); + + pb_msg_t * msg_read = pbdrv_msg_read(&buf); + pbdrv_buf_free(&buf); + + ASSERT_EQ(buf.data, nullptr); + + EXPECT_EQ(msg_write.type, msg_read->type); + EXPECT_EQ(msg_write.sender, msg_read->sender); + EXPECT_EQ(((pb_cmd_req_read_t *) msg_write.msg)->propid, ((pb_cmd_req_read_t *) msg_read->msg)->propid); + + pbdrv_msg_free(msg_read); +} + diff --git a/test/pbdrv/cmd.h b/test/pbdrv/msg.h index 52bee37..52bee37 100644 --- a/test/pbdrv/cmd.h +++ b/test/pbdrv/msg.h |