2019-05-31 12:55:11 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "device_msg.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2020-06-04 19:22:47 +00:00
|
|
|
|
2019-05-31 12:55:11 +00:00
|
|
|
static void test_deserialize_clipboard(void) {
|
|
|
|
const unsigned char input[] = {
|
|
|
|
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"
|
|
|
|
};
|
|
|
|
|
|
|
|
struct device_msg msg;
|
|
|
|
ssize_t r = 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));
|
|
|
|
|
|
|
|
device_msg_destroy(&msg);
|
|
|
|
}
|
|
|
|
|
2020-06-04 19:22:47 +00:00
|
|
|
static void test_deserialize_clipboard_big(void) {
|
2020-06-04 19:26:38 +00:00
|
|
|
unsigned char 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
|
|
|
|
|
|
|
struct device_msg msg;
|
|
|
|
ssize_t r = 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');
|
|
|
|
|
|
|
|
device_msg_destroy(&msg);
|
|
|
|
}
|
|
|
|
|
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();
|
2019-05-31 12:55:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|