diff options
-rw-r--r-- | lib/pbdrv/pb-write.c | 9 | ||||
-rw-r--r-- | test/pbdrv/write.cpp | 10 |
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); } |