aboutsummaryrefslogtreecommitdiff
path: root/test/pbdrv
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-06-13 17:46:26 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-06-13 17:46:26 +0200
commit557b995f9641f7cb7a0566eefac7e576debec61a (patch)
tree1b2b0966f6b1671e5accfe0d980ee1f370d21b58 /test/pbdrv
parentda57aaed1295d72d8d840c69c0e08c0bcab46aee (diff)
really WIP driver (de)serialization
Diffstat (limited to 'test/pbdrv')
-rw-r--r--test/pbdrv/cmd.cpp52
-rw-r--r--test/pbdrv/cmd.h (renamed from test/pbdrv/test.h)13
-rw-r--r--test/pbdrv/read.cpp16
-rw-r--r--test/pbdrv/write.cpp22
4 files changed, 52 insertions, 51 deletions
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 <gtest/gtest.h>
+
+#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/test.h b/test/pbdrv/cmd.h
index aa4f0b1..52bee37 100644
--- a/test/pbdrv/test.h
+++ b/test/pbdrv/cmd.h
@@ -2,14 +2,6 @@
#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,
};
@@ -38,8 +30,3 @@ 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/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 <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/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 <gtest/gtest.h>
-
-#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);
-