From 2cf895332ffd54ea1a43b090859943665709e420 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 14 Jun 2024 11:48:51 +0200 Subject: decide on pbdrv serialization architecture --- test/CMakeLists.txt | 2 +- test/pbdrv/cmd.cpp | 52 ---------------------------------------------------- test/pbdrv/cmd.h | 32 -------------------------------- test/pbdrv/msg.cpp | 30 ++++++++++++++++++++++++++++++ test/pbdrv/msg.h | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 63 insertions(+), 85 deletions(-) delete mode 100644 test/pbdrv/cmd.cpp delete mode 100644 test/pbdrv/cmd.h create mode 100644 test/pbdrv/msg.cpp create mode 100644 test/pbdrv/msg.h (limited to 'test') diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b2b2937..9b1f40e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -8,7 +8,7 @@ project(pbtest C CXX ASM) add_executable(test # i2ctcp/main.cpp - pbdrv/cmd.cpp + pbdrv/msg.cpp ) add_subdirectory(lib/googletest) 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 - -#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/cmd.h b/test/pbdrv/cmd.h deleted file mode 100644 index 52bee37..0000000 --- a/test/pbdrv/cmd.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include "pb-types.h" - -static const pb_cmd_req_read_t expected_req_read = { - .propid = 0, -}; - -static const pb_cmd_res_read_t expected_res_read = { - .propid = 0, - .value = (uint8_t[]) { 0x00, }, - ._value_size = 1, -}; - -static const pb_cmd_req_write_t expected_req_write = { - .propid = 0, - .value = (uint8_t[]) { 0x00, }, - ._value_size = 1, -}; - -static const pb_cmd_req_state_t expected_req_state = { - .state = PB_GS_PLAYING, -}; - -static const pb_cmd_res_state_t expected_res_state = { - .state = PB_GS_IDLE, -}; - -static const pb_cmd_req_set_state_t expected_req_set_state ={ - .state = PB_GS_PLAYING, -}; - 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 + +#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/msg.h b/test/pbdrv/msg.h new file mode 100644 index 0000000..52bee37 --- /dev/null +++ b/test/pbdrv/msg.h @@ -0,0 +1,32 @@ +#pragma once + +#include "pb-types.h" + +static const pb_cmd_req_read_t expected_req_read = { + .propid = 0, +}; + +static const pb_cmd_res_read_t expected_res_read = { + .propid = 0, + .value = (uint8_t[]) { 0x00, }, + ._value_size = 1, +}; + +static const pb_cmd_req_write_t expected_req_write = { + .propid = 0, + .value = (uint8_t[]) { 0x00, }, + ._value_size = 1, +}; + +static const pb_cmd_req_state_t expected_req_state = { + .state = PB_GS_PLAYING, +}; + +static const pb_cmd_res_state_t expected_res_state = { + .state = PB_GS_IDLE, +}; + +static const pb_cmd_req_set_state_t expected_req_set_state ={ + .state = PB_GS_PLAYING, +}; + -- cgit v1.2.3