diff options
-rw-r--r-- | lib/pbdrv/pb-read.h | 5 | ||||
-rw-r--r-- | lib/pbdrv/pb-types.h | 8 | ||||
-rw-r--r-- | lib/pbdrv/pb-write.h | 6 | ||||
-rw-r--r-- | test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/pbdrv/read.cpp | 16 | ||||
-rw-r--r-- | test/pbdrv/test.h | 45 | ||||
-rw-r--r-- | test/pbdrv/write.cpp | 86 |
7 files changed, 93 insertions, 74 deletions
diff --git a/lib/pbdrv/pb-read.h b/lib/pbdrv/pb-read.h index 7a6f0df..a6d7cde 100644 --- a/lib/pbdrv/pb-read.h +++ b/lib/pbdrv/pb-read.h @@ -1,9 +1,14 @@ #pragma once +#include <stdint.h> +#include <stddef.h> + #ifdef __cplusplus extern "C" { #endif +void pbdrv_read_cmd(const char * data, size_t size); + #ifdef __cplusplus } #endif diff --git a/lib/pbdrv/pb-types.h b/lib/pbdrv/pb-types.h index 76292f6..0cafab5 100644 --- a/lib/pbdrv/pb-types.h +++ b/lib/pbdrv/pb-types.h @@ -1,4 +1,5 @@ #pragma once + #include <stdint.h> #include <stddef.h> @@ -14,8 +15,15 @@ extern "C" { #define __weak #endif +//! I2C address (10 or 7 bit) typedef uint16_t i2c_addr_t; +//! binary buffer struct +typedef struct { + char * data; //! pointer to data + size_t size; //! size of data +} pbdrv_buf_t; + //! puzzle bus command types enum pb_cmd_id { PB_CMD_REQ_READ, //!< request a puzzle module property diff --git a/lib/pbdrv/pb-write.h b/lib/pbdrv/pb-write.h index 3245898..3bd53c5 100644 --- a/lib/pbdrv/pb-write.h +++ b/lib/pbdrv/pb-write.h @@ -6,12 +6,6 @@ extern "C" { #endif -//! binary buffer struct -typedef struct { - char * data; //! pointer to data - size_t size; //! size of data -} pbdrv_buf_t; - pbdrv_buf_t pbdrv_write_cmd_req_read(pb_cmd_req_read_t data); pbdrv_buf_t pbdrv_write_cmd_res_read(pb_cmd_res_read_t data); pbdrv_buf_t pbdrv_write_cmd_req_write(pb_cmd_req_write_t data); 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 <gtest/gtest.h> + +#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 <gtest/gtest.h> #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); |