Replace unsigned char by uint8_t for buffers
For consistency.
This commit is contained in:
parent
d527a5c84c
commit
56fdc01fd2
@ -87,7 +87,7 @@ write_position(uint8_t *buf, const struct sc_position *position) {
|
|||||||
|
|
||||||
// write length (4 bytes) + string (non null-terminated)
|
// write length (4 bytes) + string (non null-terminated)
|
||||||
static size_t
|
static size_t
|
||||||
write_string(const char *utf8, size_t max_len, unsigned char *buf) {
|
write_string(const char *utf8, size_t max_len, uint8_t *buf) {
|
||||||
size_t len = sc_str_utf8_truncation_index(utf8, max_len);
|
size_t len = sc_str_utf8_truncation_index(utf8, max_len);
|
||||||
sc_write32be(buf, len);
|
sc_write32be(buf, len);
|
||||||
memcpy(&buf[4], utf8, len);
|
memcpy(&buf[4], utf8, len);
|
||||||
@ -95,7 +95,7 @@ write_string(const char *utf8, size_t max_len, unsigned char *buf) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
sc_control_msg_serialize(const struct sc_control_msg *msg, unsigned char *buf) {
|
sc_control_msg_serialize(const struct sc_control_msg *msg, uint8_t *buf) {
|
||||||
buf[0] = msg->type;
|
buf[0] = msg->type;
|
||||||
switch (msg->type) {
|
switch (msg->type) {
|
||||||
case SC_CONTROL_MSG_TYPE_INJECT_KEYCODE:
|
case SC_CONTROL_MSG_TYPE_INJECT_KEYCODE:
|
||||||
|
@ -98,7 +98,7 @@ struct sc_control_msg {
|
|||||||
// buf size must be at least CONTROL_MSG_MAX_SIZE
|
// buf size must be at least CONTROL_MSG_MAX_SIZE
|
||||||
// return the number of bytes written
|
// return the number of bytes written
|
||||||
size_t
|
size_t
|
||||||
sc_control_msg_serialize(const struct sc_control_msg *msg, unsigned char *buf);
|
sc_control_msg_serialize(const struct sc_control_msg *msg, uint8_t *buf);
|
||||||
|
|
||||||
void
|
void
|
||||||
sc_control_msg_log(const struct sc_control_msg *msg);
|
sc_control_msg_log(const struct sc_control_msg *msg);
|
||||||
|
@ -84,7 +84,7 @@ sc_controller_push_msg(struct sc_controller *controller,
|
|||||||
static bool
|
static bool
|
||||||
process_msg(struct sc_controller *controller,
|
process_msg(struct sc_controller *controller,
|
||||||
const struct sc_control_msg *msg) {
|
const struct sc_control_msg *msg) {
|
||||||
static unsigned char serialized_msg[SC_CONTROL_MSG_MAX_SIZE];
|
static uint8_t serialized_msg[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t length = sc_control_msg_serialize(msg, serialized_msg);
|
size_t length = sc_control_msg_serialize(msg, serialized_msg);
|
||||||
if (!length) {
|
if (!length) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -8,8 +8,7 @@
|
|||||||
#include "util/log.h"
|
#include "util/log.h"
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
device_msg_deserialize(const unsigned char *buf, size_t len,
|
device_msg_deserialize(const uint8_t *buf, size_t len, struct device_msg *msg) {
|
||||||
struct device_msg *msg) {
|
|
||||||
if (len < 5) {
|
if (len < 5) {
|
||||||
// at least type + empty string length
|
// at least type + empty string length
|
||||||
return 0; // not available
|
return 0; // not available
|
||||||
|
@ -30,8 +30,7 @@ struct device_msg {
|
|||||||
|
|
||||||
// return the number of bytes consumed (0 for no msg available, -1 on error)
|
// return the number of bytes consumed (0 for no msg available, -1 on error)
|
||||||
ssize_t
|
ssize_t
|
||||||
device_msg_deserialize(const unsigned char *buf, size_t len,
|
device_msg_deserialize(const uint8_t *buf, size_t len, struct device_msg *msg);
|
||||||
struct device_msg *msg);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
device_msg_destroy(struct device_msg *msg);
|
device_msg_destroy(struct device_msg *msg);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "receiver.h"
|
#include "receiver.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <SDL2/SDL_clipboard.h>
|
#include <SDL2/SDL_clipboard.h>
|
||||||
|
|
||||||
#include "device_msg.h"
|
#include "device_msg.h"
|
||||||
@ -51,7 +52,7 @@ process_msg(struct sc_receiver *receiver, struct device_msg *msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t
|
static ssize_t
|
||||||
process_msgs(struct sc_receiver *receiver, const unsigned char *buf, size_t len) {
|
process_msgs(struct sc_receiver *receiver, const uint8_t *buf, size_t len) {
|
||||||
size_t head = 0;
|
size_t head = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
struct device_msg msg;
|
struct device_msg msg;
|
||||||
@ -78,7 +79,7 @@ static int
|
|||||||
run_receiver(void *data) {
|
run_receiver(void *data) {
|
||||||
struct sc_receiver *receiver = data;
|
struct sc_receiver *receiver = data;
|
||||||
|
|
||||||
static unsigned char buf[DEVICE_MSG_MAX_SIZE];
|
static uint8_t buf[DEVICE_MSG_MAX_SIZE];
|
||||||
size_t head = 0;
|
size_t head = 0;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -498,7 +498,7 @@ sc_server_init(struct sc_server *server, const struct sc_server_params *params,
|
|||||||
static bool
|
static bool
|
||||||
device_read_info(struct sc_intr *intr, sc_socket device_socket,
|
device_read_info(struct sc_intr *intr, sc_socket device_socket,
|
||||||
struct sc_server_info *info) {
|
struct sc_server_info *info) {
|
||||||
unsigned char buf[SC_DEVICE_NAME_FIELD_LENGTH];
|
uint8_t buf[SC_DEVICE_NAME_FIELD_LENGTH];
|
||||||
ssize_t r = net_recv_all_intr(intr, device_socket, buf, sizeof(buf));
|
ssize_t r = net_recv_all_intr(intr, device_socket, buf, sizeof(buf));
|
||||||
if (r < SC_DEVICE_NAME_FIELD_LENGTH) {
|
if (r < SC_DEVICE_NAME_FIELD_LENGTH) {
|
||||||
LOGE("Could not retrieve device information");
|
LOGE("Could not retrieve device information");
|
||||||
|
@ -94,7 +94,7 @@ sc_aoa_register_hid(struct sc_aoa *aoa, uint16_t accessory_id,
|
|||||||
|
|
||||||
static bool
|
static bool
|
||||||
sc_aoa_set_hid_report_desc(struct sc_aoa *aoa, uint16_t accessory_id,
|
sc_aoa_set_hid_report_desc(struct sc_aoa *aoa, uint16_t accessory_id,
|
||||||
const unsigned char *report_desc,
|
const uint8_t *report_desc,
|
||||||
uint16_t report_desc_size) {
|
uint16_t report_desc_size) {
|
||||||
uint8_t request_type = LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR;
|
uint8_t request_type = LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR;
|
||||||
uint8_t request = ACCESSORY_SET_HID_REPORT_DESC;
|
uint8_t request = ACCESSORY_SET_HID_REPORT_DESC;
|
||||||
@ -131,7 +131,7 @@ sc_aoa_set_hid_report_desc(struct sc_aoa *aoa, uint16_t accessory_id,
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
sc_aoa_setup_hid(struct sc_aoa *aoa, uint16_t accessory_id,
|
sc_aoa_setup_hid(struct sc_aoa *aoa, uint16_t accessory_id,
|
||||||
const unsigned char *report_desc, uint16_t report_desc_size) {
|
const uint8_t *report_desc, uint16_t report_desc_size) {
|
||||||
bool ok = sc_aoa_register_hid(aoa, accessory_id, report_desc_size);
|
bool ok = sc_aoa_register_hid(aoa, accessory_id, report_desc_size);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -51,7 +51,7 @@ sc_aoa_join(struct sc_aoa *aoa);
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
sc_aoa_setup_hid(struct sc_aoa *aoa, uint16_t accessory_id,
|
sc_aoa_setup_hid(struct sc_aoa *aoa, uint16_t accessory_id,
|
||||||
const unsigned char *report_desc, uint16_t report_desc_size);
|
const uint8_t *report_desc, uint16_t report_desc_size);
|
||||||
|
|
||||||
bool
|
bool
|
||||||
sc_aoa_unregister_hid(struct sc_aoa *aoa, uint16_t accessory_id);
|
sc_aoa_unregister_hid(struct sc_aoa *aoa, uint16_t accessory_id);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "control_msg.h"
|
#include "control_msg.h"
|
||||||
@ -16,11 +17,11 @@ static void test_serialize_inject_keycode(void) {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
uint8_t buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 14);
|
assert(size == 14);
|
||||||
|
|
||||||
const unsigned char expected[] = {
|
const uint8_t expected[] = {
|
||||||
SC_CONTROL_MSG_TYPE_INJECT_KEYCODE,
|
SC_CONTROL_MSG_TYPE_INJECT_KEYCODE,
|
||||||
0x01, // AKEY_EVENT_ACTION_UP
|
0x01, // AKEY_EVENT_ACTION_UP
|
||||||
0x00, 0x00, 0x00, 0x42, // AKEYCODE_ENTER
|
0x00, 0x00, 0x00, 0x42, // AKEYCODE_ENTER
|
||||||
@ -38,11 +39,11 @@ static void test_serialize_inject_text(void) {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
uint8_t buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 18);
|
assert(size == 18);
|
||||||
|
|
||||||
const unsigned char expected[] = {
|
const uint8_t expected[] = {
|
||||||
SC_CONTROL_MSG_TYPE_INJECT_TEXT,
|
SC_CONTROL_MSG_TYPE_INJECT_TEXT,
|
||||||
0x00, 0x00, 0x00, 0x0d, // text length
|
0x00, 0x00, 0x00, 0x0d, // text length
|
||||||
'h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', // text
|
'h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', // text
|
||||||
@ -58,11 +59,11 @@ static void test_serialize_inject_text_long(void) {
|
|||||||
text[SC_CONTROL_MSG_INJECT_TEXT_MAX_LENGTH] = '\0';
|
text[SC_CONTROL_MSG_INJECT_TEXT_MAX_LENGTH] = '\0';
|
||||||
msg.inject_text.text = text;
|
msg.inject_text.text = text;
|
||||||
|
|
||||||
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
uint8_t buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 5 + SC_CONTROL_MSG_INJECT_TEXT_MAX_LENGTH);
|
assert(size == 5 + SC_CONTROL_MSG_INJECT_TEXT_MAX_LENGTH);
|
||||||
|
|
||||||
unsigned char expected[5 + SC_CONTROL_MSG_INJECT_TEXT_MAX_LENGTH];
|
uint8_t expected[5 + SC_CONTROL_MSG_INJECT_TEXT_MAX_LENGTH];
|
||||||
expected[0] = SC_CONTROL_MSG_TYPE_INJECT_TEXT;
|
expected[0] = SC_CONTROL_MSG_TYPE_INJECT_TEXT;
|
||||||
expected[1] = 0x00;
|
expected[1] = 0x00;
|
||||||
expected[2] = 0x00;
|
expected[2] = 0x00;
|
||||||
@ -95,11 +96,11 @@ static void test_serialize_inject_touch_event(void) {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
uint8_t buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 32);
|
assert(size == 32);
|
||||||
|
|
||||||
const unsigned char expected[] = {
|
const uint8_t expected[] = {
|
||||||
SC_CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
SC_CONTROL_MSG_TYPE_INJECT_TOUCH_EVENT,
|
||||||
0x00, // AKEY_EVENT_ACTION_DOWN
|
0x00, // AKEY_EVENT_ACTION_DOWN
|
||||||
0x12, 0x34, 0x56, 0x78, 0x87, 0x65, 0x43, 0x21, // pointer id
|
0x12, 0x34, 0x56, 0x78, 0x87, 0x65, 0x43, 0x21, // pointer id
|
||||||
@ -132,11 +133,11 @@ static void test_serialize_inject_scroll_event(void) {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
uint8_t buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 21);
|
assert(size == 21);
|
||||||
|
|
||||||
const unsigned char expected[] = {
|
const uint8_t expected[] = {
|
||||||
SC_CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT,
|
SC_CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT,
|
||||||
0x00, 0x00, 0x01, 0x04, 0x00, 0x00, 0x04, 0x02, // 260 1026
|
0x00, 0x00, 0x01, 0x04, 0x00, 0x00, 0x04, 0x02, // 260 1026
|
||||||
0x04, 0x38, 0x07, 0x80, // 1080 1920
|
0x04, 0x38, 0x07, 0x80, // 1080 1920
|
||||||
@ -155,11 +156,11 @@ static void test_serialize_back_or_screen_on(void) {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
uint8_t buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 2);
|
assert(size == 2);
|
||||||
|
|
||||||
const unsigned char expected[] = {
|
const uint8_t expected[] = {
|
||||||
SC_CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON,
|
SC_CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON,
|
||||||
0x01, // AKEY_EVENT_ACTION_UP
|
0x01, // AKEY_EVENT_ACTION_UP
|
||||||
};
|
};
|
||||||
@ -171,11 +172,11 @@ static void test_serialize_expand_notification_panel(void) {
|
|||||||
.type = SC_CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL,
|
.type = SC_CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL,
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
uint8_t buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 1);
|
assert(size == 1);
|
||||||
|
|
||||||
const unsigned char expected[] = {
|
const uint8_t expected[] = {
|
||||||
SC_CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL,
|
SC_CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL,
|
||||||
};
|
};
|
||||||
assert(!memcmp(buf, expected, sizeof(expected)));
|
assert(!memcmp(buf, expected, sizeof(expected)));
|
||||||
@ -186,11 +187,11 @@ static void test_serialize_expand_settings_panel(void) {
|
|||||||
.type = SC_CONTROL_MSG_TYPE_EXPAND_SETTINGS_PANEL,
|
.type = SC_CONTROL_MSG_TYPE_EXPAND_SETTINGS_PANEL,
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
uint8_t buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 1);
|
assert(size == 1);
|
||||||
|
|
||||||
const unsigned char expected[] = {
|
const uint8_t expected[] = {
|
||||||
SC_CONTROL_MSG_TYPE_EXPAND_SETTINGS_PANEL,
|
SC_CONTROL_MSG_TYPE_EXPAND_SETTINGS_PANEL,
|
||||||
};
|
};
|
||||||
assert(!memcmp(buf, expected, sizeof(expected)));
|
assert(!memcmp(buf, expected, sizeof(expected)));
|
||||||
@ -201,11 +202,11 @@ static void test_serialize_collapse_panels(void) {
|
|||||||
.type = SC_CONTROL_MSG_TYPE_COLLAPSE_PANELS,
|
.type = SC_CONTROL_MSG_TYPE_COLLAPSE_PANELS,
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
uint8_t buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 1);
|
assert(size == 1);
|
||||||
|
|
||||||
const unsigned char expected[] = {
|
const uint8_t expected[] = {
|
||||||
SC_CONTROL_MSG_TYPE_COLLAPSE_PANELS,
|
SC_CONTROL_MSG_TYPE_COLLAPSE_PANELS,
|
||||||
};
|
};
|
||||||
assert(!memcmp(buf, expected, sizeof(expected)));
|
assert(!memcmp(buf, expected, sizeof(expected)));
|
||||||
@ -219,11 +220,11 @@ static void test_serialize_get_clipboard(void) {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
uint8_t buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 2);
|
assert(size == 2);
|
||||||
|
|
||||||
const unsigned char expected[] = {
|
const uint8_t expected[] = {
|
||||||
SC_CONTROL_MSG_TYPE_GET_CLIPBOARD,
|
SC_CONTROL_MSG_TYPE_GET_CLIPBOARD,
|
||||||
SC_COPY_KEY_COPY,
|
SC_COPY_KEY_COPY,
|
||||||
};
|
};
|
||||||
@ -240,11 +241,11 @@ static void test_serialize_set_clipboard(void) {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
uint8_t buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 27);
|
assert(size == 27);
|
||||||
|
|
||||||
const unsigned char expected[] = {
|
const uint8_t expected[] = {
|
||||||
SC_CONTROL_MSG_TYPE_SET_CLIPBOARD,
|
SC_CONTROL_MSG_TYPE_SET_CLIPBOARD,
|
||||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // sequence
|
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // sequence
|
||||||
1, // paste
|
1, // paste
|
||||||
@ -269,11 +270,11 @@ static void test_serialize_set_clipboard_long(void) {
|
|||||||
text[SC_CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH] = '\0';
|
text[SC_CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH] = '\0';
|
||||||
msg.set_clipboard.text = text;
|
msg.set_clipboard.text = text;
|
||||||
|
|
||||||
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
uint8_t buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == SC_CONTROL_MSG_MAX_SIZE);
|
assert(size == SC_CONTROL_MSG_MAX_SIZE);
|
||||||
|
|
||||||
unsigned char expected[SC_CONTROL_MSG_MAX_SIZE] = {
|
uint8_t expected[SC_CONTROL_MSG_MAX_SIZE] = {
|
||||||
SC_CONTROL_MSG_TYPE_SET_CLIPBOARD,
|
SC_CONTROL_MSG_TYPE_SET_CLIPBOARD,
|
||||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // sequence
|
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // sequence
|
||||||
1, // paste
|
1, // paste
|
||||||
@ -296,11 +297,11 @@ static void test_serialize_set_screen_power_mode(void) {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
uint8_t buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 2);
|
assert(size == 2);
|
||||||
|
|
||||||
const unsigned char expected[] = {
|
const uint8_t expected[] = {
|
||||||
SC_CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE,
|
SC_CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE,
|
||||||
0x02, // SC_SCREEN_POWER_MODE_NORMAL
|
0x02, // SC_SCREEN_POWER_MODE_NORMAL
|
||||||
};
|
};
|
||||||
@ -312,11 +313,11 @@ static void test_serialize_rotate_device(void) {
|
|||||||
.type = SC_CONTROL_MSG_TYPE_ROTATE_DEVICE,
|
.type = SC_CONTROL_MSG_TYPE_ROTATE_DEVICE,
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char buf[SC_CONTROL_MSG_MAX_SIZE];
|
uint8_t buf[SC_CONTROL_MSG_MAX_SIZE];
|
||||||
size_t size = sc_control_msg_serialize(&msg, buf);
|
size_t size = sc_control_msg_serialize(&msg, buf);
|
||||||
assert(size == 1);
|
assert(size == 1);
|
||||||
|
|
||||||
const unsigned char expected[] = {
|
const uint8_t expected[] = {
|
||||||
SC_CONTROL_MSG_TYPE_ROTATE_DEVICE,
|
SC_CONTROL_MSG_TYPE_ROTATE_DEVICE,
|
||||||
};
|
};
|
||||||
assert(!memcmp(buf, expected, sizeof(expected)));
|
assert(!memcmp(buf, expected, sizeof(expected)));
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "device_msg.h"
|
#include "device_msg.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
static void test_deserialize_clipboard(void) {
|
static void test_deserialize_clipboard(void) {
|
||||||
const unsigned char input[] = {
|
const uint8_t input[] = {
|
||||||
DEVICE_MSG_TYPE_CLIPBOARD,
|
DEVICE_MSG_TYPE_CLIPBOARD,
|
||||||
0x00, 0x00, 0x00, 0x03, // text length
|
0x00, 0x00, 0x00, 0x03, // text length
|
||||||
0x41, 0x42, 0x43, // "ABC"
|
0x41, 0x42, 0x43, // "ABC"
|
||||||
@ -26,7 +26,7 @@ static void test_deserialize_clipboard(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void test_deserialize_clipboard_big(void) {
|
static void test_deserialize_clipboard_big(void) {
|
||||||
unsigned char input[DEVICE_MSG_MAX_SIZE];
|
uint8_t input[DEVICE_MSG_MAX_SIZE];
|
||||||
input[0] = DEVICE_MSG_TYPE_CLIPBOARD;
|
input[0] = DEVICE_MSG_TYPE_CLIPBOARD;
|
||||||
input[1] = (DEVICE_MSG_TEXT_MAX_LENGTH & 0xff000000u) >> 24;
|
input[1] = (DEVICE_MSG_TEXT_MAX_LENGTH & 0xff000000u) >> 24;
|
||||||
input[2] = (DEVICE_MSG_TEXT_MAX_LENGTH & 0x00ff0000u) >> 16;
|
input[2] = (DEVICE_MSG_TEXT_MAX_LENGTH & 0x00ff0000u) >> 16;
|
||||||
@ -48,7 +48,7 @@ static void test_deserialize_clipboard_big(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void test_deserialize_ack_set_clipboard(void) {
|
static void test_deserialize_ack_set_clipboard(void) {
|
||||||
const unsigned char input[] = {
|
const uint8_t input[] = {
|
||||||
DEVICE_MSG_TYPE_ACK_CLIPBOARD,
|
DEVICE_MSG_TYPE_ACK_CLIPBOARD,
|
||||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // sequence
|
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // sequence
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user