From 557b995f9641f7cb7a0566eefac7e576debec61a Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Thu, 13 Jun 2024 17:46:26 +0200 Subject: really WIP driver (de)serialization --- test/CMakeLists.txt | 3 +-- test/pbdrv/cmd.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ test/pbdrv/cmd.h | 32 ++++++++++++++++++++++++++++++++ test/pbdrv/read.cpp | 16 ---------------- test/pbdrv/test.h | 45 --------------------------------------------- test/pbdrv/write.cpp | 22 ---------------------- 6 files changed, 85 insertions(+), 85 deletions(-) create mode 100644 test/pbdrv/cmd.cpp create mode 100644 test/pbdrv/cmd.h delete mode 100644 test/pbdrv/read.cpp delete mode 100644 test/pbdrv/test.h delete mode 100644 test/pbdrv/write.cpp (limited to 'test') diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a4015a8..b2b2937 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -8,8 +8,7 @@ project(pbtest C CXX ASM) add_executable(test # i2ctcp/main.cpp - pbdrv/write.cpp - pbdrv/read.cpp + pbdrv/cmd.cpp ) add_subdirectory(lib/googletest) diff --git a/test/pbdrv/cmd.cpp b/test/pbdrv/cmd.cpp new file mode 100644 index 0000000..8b7ee89 --- /dev/null +++ b/test/pbdrv/cmd.cpp @@ -0,0 +1,52 @@ +#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 new file mode 100644 index 0000000..52bee37 --- /dev/null +++ b/test/pbdrv/cmd.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, +}; + diff --git a/test/pbdrv/read.cpp b/test/pbdrv/read.cpp deleted file mode 100644 index 1b1eed8..0000000 --- a/test/pbdrv/read.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include - -#include "pb-read.h" - -#include "test.h" - -TEST(pbdrv, read_cmd_req_read) { - // pbdrv_read_cmd(cmd_req_read.data, cmd_req_read.size); -} - -// 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/test.h b/test/pbdrv/test.h deleted file mode 100644 index aa4f0b1..0000000 --- a/test/pbdrv/test.h +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once - -#include "pb-types.h" - -extern pbdrv_buf_t cmd_req_read; -extern pbdrv_buf_t cmd_res_read; -extern pbdrv_buf_t cmd_req_write; -extern pbdrv_buf_t cmd_req_state; -extern pbdrv_buf_t cmd_res_state; -extern pbdrv_buf_t cmd_req_set_state; -extern pbdrv_buf_t cmd_magic; - -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, -}; - -static const pb_cmd_magic_t expected_magic = { - .magic = pb_cmd_magic_msg, - ._magic_size = sizeof(pb_cmd_magic_msg), -}; - diff --git a/test/pbdrv/write.cpp b/test/pbdrv/write.cpp deleted file mode 100644 index 5511734..0000000 --- a/test/pbdrv/write.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include - -#include "pb-write.h" -#include "test.h" - -// sorry for metaprogramming -#define test_write_fn(fn) \ - pbdrv_buf_t cmd_##fn; \ - TEST(pbdrv, write_cmd_##fn) { \ - cmd_##fn = pbdrv_write_cmd_##fn(expected_##fn); \ - ASSERT_NE(cmd_##fn.data, nullptr); \ - ASSERT_GE(cmd_##fn.size, 0); \ - } - -test_write_fn(req_read); -test_write_fn(res_read); -test_write_fn(req_write); -test_write_fn(req_state); -test_write_fn(res_state); -test_write_fn(req_set_state); -test_write_fn(magic); - -- cgit v1.2.3