From d202d7b2059eb440c044477993a6e0d6aa4d5086 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Thu, 4 Jun 2020 21:22:47 +0200 Subject: [PATCH] Add unit test for big clipboard device message Test clipboard synchronization from the device to the computer. --- app/tests/test_device_msg_deserialize.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/tests/test_device_msg_deserialize.c b/app/tests/test_device_msg_deserialize.c index e163ad72..2e29d087 100644 --- a/app/tests/test_device_msg_deserialize.c +++ b/app/tests/test_device_msg_deserialize.c @@ -4,6 +4,7 @@ #include "device_msg.h" #include + static void test_deserialize_clipboard(void) { const unsigned char input[] = { DEVICE_MSG_TYPE_CLIPBOARD, @@ -22,7 +23,28 @@ static void test_deserialize_clipboard(void) { device_msg_destroy(&msg); } +static void test_deserialize_clipboard_big(void) { + unsigned char input[DEVICE_MSG_SERIALIZED_MAX_SIZE]; + input[0] = DEVICE_MSG_TYPE_CLIPBOARD; + input[1] = DEVICE_MSG_TEXT_MAX_LENGTH >> 8; // MSB + input[2] = DEVICE_MSG_TEXT_MAX_LENGTH & 0xff; // LSB + + memset(input + 3, 'a', DEVICE_MSG_TEXT_MAX_LENGTH); + + struct device_msg msg; + ssize_t r = device_msg_deserialize(input, sizeof(input), &msg); + assert(r == DEVICE_MSG_SERIALIZED_MAX_SIZE); + + assert(msg.type == DEVICE_MSG_TYPE_CLIPBOARD); + assert(msg.clipboard.text); + assert(strlen(msg.clipboard.text) == DEVICE_MSG_TEXT_MAX_LENGTH); + assert(msg.clipboard.text[0] == 'a'); + + device_msg_destroy(&msg); +} + int main(void) { test_deserialize_clipboard(); + test_deserialize_clipboard_big(); return 0; }