From da57aaed1295d72d8d840c69c0e08c0bcab46aee Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 11 Jun 2024 11:53:24 +0200 Subject: WIP pb-read --- test/CMakeLists.txt | 1 + test/pbdrv/read.cpp | 16 ++++++++++ test/pbdrv/test.h | 45 +++++++++++++++++++++++++++ test/pbdrv/write.cpp | 86 +++++++++++----------------------------------------- 4 files changed, 80 insertions(+), 68 deletions(-) create mode 100644 test/pbdrv/read.cpp create mode 100644 test/pbdrv/test.h (limited to 'test') diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 311bbfb..a4015a8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,6 +9,7 @@ project(pbtest C CXX ASM) add_executable(test # i2ctcp/main.cpp pbdrv/write.cpp + pbdrv/read.cpp ) add_subdirectory(lib/googletest) diff --git a/test/pbdrv/read.cpp b/test/pbdrv/read.cpp new file mode 100644 index 0000000..1b1eed8 --- /dev/null +++ b/test/pbdrv/read.cpp @@ -0,0 +1,16 @@ +#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 new file mode 100644 index 0000000..aa4f0b1 --- /dev/null +++ b/test/pbdrv/test.h @@ -0,0 +1,45 @@ +#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 index ad775bb..5511734 100644 --- a/test/pbdrv/write.cpp +++ b/test/pbdrv/write.cpp @@ -1,72 +1,22 @@ #include #include "pb-write.h" - -TEST(pbdrv, write_cmd_req_read) { - pbdrv_buf_t buf = pbdrv_write_cmd_req_read({ - .propid = 0, - }); - - ASSERT_NE(buf.data, nullptr); - ASSERT_GE(buf.size, 0); -} - -TEST(pbdrv, write_cmd_res_read) { - pbdrv_buf_t buf = pbdrv_write_cmd_res_read({ - .propid = 0, - .value = (uint8_t[]) { 0x00, }, - ._value_size = 1, - }); - - ASSERT_NE(buf.data, nullptr); - ASSERT_GE(buf.size, 0); -} - -TEST(pbdrv, write_cmd_req_write) { - pbdrv_buf_t buf = pbdrv_write_cmd_req_write({ - .propid = 0, - .value = (uint8_t[]) { 0x00, }, - ._value_size = 1, - }); - - ASSERT_NE(buf.data, nullptr); - ASSERT_GE(buf.size, 0); -} - -TEST(pbdrv, write_cmd_req_state) { - pbdrv_buf_t buf = pbdrv_write_cmd_req_state({ - .state = PB_GS_PLAYING, - }); - - ASSERT_NE(buf.data, nullptr); - ASSERT_GE(buf.size, 0); -} - -TEST(pbdrv, write_cmd_res_state) { - pbdrv_buf_t buf = pbdrv_write_cmd_res_state({ - .state = PB_GS_IDLE, - }); - - ASSERT_NE(buf.data, nullptr); - ASSERT_GE(buf.size, 0); -} - -TEST(pbdrv, write_cmd_req_set_state) { - pbdrv_buf_t buf = pbdrv_write_cmd_req_set_state({ - .state = PB_GS_PLAYING, - }); - - ASSERT_NE(buf.data, nullptr); - ASSERT_GE(buf.size, 0); -} - -TEST(pbdrv, write_cmd_magic) { - pbdrv_buf_t buf = pbdrv_write_cmd_magic({ - .magic = pb_cmd_magic_msg, - ._magic_size = sizeof(pb_cmd_magic_msg), - }); - - ASSERT_NE(buf.data, nullptr); - ASSERT_GE(buf.size, 0); -} +#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