diff options
Diffstat (limited to 'test/pbdrv')
-rw-r--r-- | test/pbdrv/read.cpp | 16 | ||||
-rw-r--r-- | test/pbdrv/test.h | 45 | ||||
-rw-r--r-- | test/pbdrv/write.cpp | 86 |
3 files changed, 79 insertions, 68 deletions
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); |