2021-01-08 18:24:51 +00:00
|
|
|
#include "common.h"
|
|
|
|
|
2019-05-31 12:55:11 +00:00
|
|
|
#include <assert.h>
|
2024-02-23 18:59:54 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
2019-05-31 12:55:11 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "device_msg.h"
|
|
|
|
|
|
|
|
static void test_deserialize_clipboard(void) {
|
2024-02-23 18:59:54 +00:00
|
|
|
const uint8_t input[] = {
|
2019-05-31 12:55:11 +00:00
|
|
|
DEVICE_MSG_TYPE_CLIPBOARD,
|
2020-06-04 19:42:09 +00:00
|
|
|
0x00, 0x00, 0x00, 0x03, // text length
|
2019-05-31 12:55:11 +00:00
|
|
|
0x41, 0x42, 0x43, // "ABC"
|
|
|
|
};
|
|
|
|
|
2024-02-23 19:05:12 +00:00
|
|
|
struct sc_device_msg msg;
|
|
|
|
ssize_t r = sc_device_msg_deserialize(input, sizeof(input), &msg);
|
2020-06-04 19:42:09 +00:00
|
|
|
assert(r == 8);
|
2019-05-31 12:55:11 +00:00
|
|
|
|
|
|
|
assert(msg.type == DEVICE_MSG_TYPE_CLIPBOARD);
|
|
|
|
assert(msg.clipboard.text);
|
|
|
|
assert(!strcmp("ABC", msg.clipboard.text));
|
|
|
|
|
2024-02-23 19:05:12 +00:00
|
|
|
sc_device_msg_destroy(&msg);
|
2019-05-31 12:55:11 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 19:22:47 +00:00
|
|
|
static void test_deserialize_clipboard_big(void) {
|
2024-02-23 18:59:54 +00:00
|
|
|
uint8_t input[DEVICE_MSG_MAX_SIZE];
|
2020-06-04 19:22:47 +00:00
|
|
|
input[0] = DEVICE_MSG_TYPE_CLIPBOARD;
|
2020-06-04 19:42:09 +00:00
|
|
|
input[1] = (DEVICE_MSG_TEXT_MAX_LENGTH & 0xff000000u) >> 24;
|
|
|
|
input[2] = (DEVICE_MSG_TEXT_MAX_LENGTH & 0x00ff0000u) >> 16;
|
|
|
|
input[3] = (DEVICE_MSG_TEXT_MAX_LENGTH & 0x0000ff00u) >> 8;
|
|
|
|
input[4] = DEVICE_MSG_TEXT_MAX_LENGTH & 0x000000ffu;
|
2020-06-04 19:22:47 +00:00
|
|
|
|
2020-06-04 19:42:09 +00:00
|
|
|
memset(input + 5, 'a', DEVICE_MSG_TEXT_MAX_LENGTH);
|
2020-06-04 19:22:47 +00:00
|
|
|
|
2024-02-23 19:05:12 +00:00
|
|
|
struct sc_device_msg msg;
|
|
|
|
ssize_t r = sc_device_msg_deserialize(input, sizeof(input), &msg);
|
2020-06-04 19:26:38 +00:00
|
|
|
assert(r == DEVICE_MSG_MAX_SIZE);
|
2020-06-04 19:22:47 +00:00
|
|
|
|
|
|
|
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');
|
|
|
|
|
2024-02-23 19:05:12 +00:00
|
|
|
sc_device_msg_destroy(&msg);
|
2020-06-04 19:22:47 +00:00
|
|
|
}
|
|
|
|
|
2021-11-20 11:10:09 +00:00
|
|
|
static void test_deserialize_ack_set_clipboard(void) {
|
2024-02-23 18:59:54 +00:00
|
|
|
const uint8_t input[] = {
|
2021-11-20 11:10:09 +00:00
|
|
|
DEVICE_MSG_TYPE_ACK_CLIPBOARD,
|
|
|
|
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // sequence
|
|
|
|
};
|
|
|
|
|
2024-02-23 19:05:12 +00:00
|
|
|
struct sc_device_msg msg;
|
|
|
|
ssize_t r = sc_device_msg_deserialize(input, sizeof(input), &msg);
|
2021-11-20 11:10:09 +00:00
|
|
|
assert(r == 9);
|
|
|
|
|
|
|
|
assert(msg.type == DEVICE_MSG_TYPE_ACK_CLIPBOARD);
|
|
|
|
assert(msg.ack_clipboard.sequence == UINT64_C(0x0102030405060708));
|
|
|
|
}
|
|
|
|
|
2020-07-15 10:17:04 +00:00
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
(void) argc;
|
|
|
|
(void) argv;
|
|
|
|
|
2019-05-31 12:55:11 +00:00
|
|
|
test_deserialize_clipboard();
|
2020-06-04 19:22:47 +00:00
|
|
|
test_deserialize_clipboard_big();
|
2021-11-20 11:10:09 +00:00
|
|
|
test_deserialize_ack_set_clipboard();
|
2019-05-31 12:55:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|