aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-06-11 10:44:54 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-06-11 10:44:54 +0200
commit63fed0e85b72e27049ce14c80127859b387460dd (patch)
treee0542ae194c04cb904f323042090f78fe8b886f5
parent91325080d96f721b290223420d224135cda40358 (diff)
fix write_cmd_req_set_state
-rw-r--r--lib/pbdrv/pb-write.c9
-rw-r--r--test/pbdrv/write.cpp10
2 files changed, 7 insertions, 12 deletions
diff --git a/lib/pbdrv/pb-write.c b/lib/pbdrv/pb-write.c
index 752a4ac..294452e 100644
--- a/lib/pbdrv/pb-write.c
+++ b/lib/pbdrv/pb-write.c
@@ -7,10 +7,8 @@ typedef struct {
pbdrv_buf_t buf;
} pbdrv_writer_t;
-static pbdrv_writer_t pbdrv_write_init() {
- pbdrv_writer_t writer;
- mpack_writer_init_growable(&writer.writer, &writer.buf.data, &writer.buf.size);
- return writer;
+static void pbdrv_write_init(pbdrv_writer_t * writer) {
+ mpack_writer_init_growable(&writer->writer, &writer->buf.data, &writer->buf.size);
}
static pbdrv_buf_t pbdrv_write_finish(pbdrv_writer_t * writer) {
@@ -27,7 +25,8 @@ static void pbdrv_write_msg_header(pbdrv_writer_t * writer, pb_msg_header_t head
}
pbdrv_buf_t pbdrv_write_cmd_req_set_state(pb_cmd_req_set_state_t data) {
- pbdrv_writer_t writer = pbdrv_write_init();
+ pbdrv_writer_t writer;
+ pbdrv_write_init(&writer);
pbdrv_write_msg_header(&writer, data.header);
mpack_write_u8(&writer.writer, data.state);
return pbdrv_write_finish(&writer);
diff --git a/test/pbdrv/write.cpp b/test/pbdrv/write.cpp
index de7e88a..31e5d8d 100644
--- a/test/pbdrv/write.cpp
+++ b/test/pbdrv/write.cpp
@@ -2,17 +2,13 @@
#include "pb-write.h"
-TEST(pbdrv, write) {
-
+TEST(pbdrv, write_cmd_req_set_state) {
pbdrv_buf_t buf = pbdrv_write_cmd_req_set_state({
.header = { .sender = 0xf0, },
.state = PB_GS_PLAYING,
});
- for (size_t i = 0; i < buf.size; i++) {
- printf("%02x ", buf.data[i] & 0xff);
- }
- printf("\n");
- ASSERT_TRUE(true);
+ ASSERT_NE(buf.data, nullptr);
+ ASSERT_GE(buf.size, 0);
}