mirror of https://github.com/Genymobile/scrcpy
Add unit tests for control events serialization
Add missing tests for serialization and deserialization of control events.
This commit is contained in:
parent
63207d9cd5
commit
3aa5426cad
|
@ -133,11 +133,59 @@ static void test_serialize_scroll_event(void) {
|
|||
assert(!memcmp(buf, expected, sizeof(expected)));
|
||||
}
|
||||
|
||||
static void test_serialize_back_or_screen_on_event(void) {
|
||||
struct control_event event = {
|
||||
.type = CONTROL_EVENT_TYPE_BACK_OR_SCREEN_ON,
|
||||
};
|
||||
|
||||
unsigned char buf[CONTROL_EVENT_SERIALIZED_MAX_SIZE];
|
||||
int size = control_event_serialize(&event, buf);
|
||||
assert(size == 1);
|
||||
|
||||
const unsigned char expected[] = {
|
||||
0x04, // CONTROL_EVENT_TYPE_BACK_OR_SCREEN_ON
|
||||
};
|
||||
assert(!memcmp(buf, expected, sizeof(expected)));
|
||||
}
|
||||
|
||||
static void test_serialize_expand_notification_panel_event(void) {
|
||||
struct control_event event = {
|
||||
.type = CONTROL_EVENT_TYPE_EXPAND_NOTIFICATION_PANEL,
|
||||
};
|
||||
|
||||
unsigned char buf[CONTROL_EVENT_SERIALIZED_MAX_SIZE];
|
||||
int size = control_event_serialize(&event, buf);
|
||||
assert(size == 1);
|
||||
|
||||
const unsigned char expected[] = {
|
||||
0x05, // CONTROL_EVENT_TYPE_EXPAND_NOTIFICATION_PANEL
|
||||
};
|
||||
assert(!memcmp(buf, expected, sizeof(expected)));
|
||||
}
|
||||
|
||||
static void test_serialize_collapse_notification_panel_event(void) {
|
||||
struct control_event event = {
|
||||
.type = CONTROL_EVENT_TYPE_COLLAPSE_NOTIFICATION_PANEL,
|
||||
};
|
||||
|
||||
unsigned char buf[CONTROL_EVENT_SERIALIZED_MAX_SIZE];
|
||||
int size = control_event_serialize(&event, buf);
|
||||
assert(size == 1);
|
||||
|
||||
const unsigned char expected[] = {
|
||||
0x06, // CONTROL_EVENT_TYPE_COLLAPSE_NOTIFICATION_PANEL
|
||||
};
|
||||
assert(!memcmp(buf, expected, sizeof(expected)));
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_serialize_keycode_event();
|
||||
test_serialize_text_event();
|
||||
test_serialize_long_text_event();
|
||||
test_serialize_mouse_event();
|
||||
test_serialize_scroll_event();
|
||||
test_serialize_back_or_screen_on_event();
|
||||
test_serialize_expand_notification_panel_event();
|
||||
test_serialize_collapse_notification_panel_event();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -97,6 +97,83 @@ public class ControlEventReaderTest {
|
|||
Assert.assertEquals(KeyEvent.META_CTRL_ON, event.getMetaState());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("checkstyle:MagicNumber")
|
||||
public void testParseScrollEvent() throws IOException {
|
||||
ControlEventReader reader = new ControlEventReader();
|
||||
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
DataOutputStream dos = new DataOutputStream(bos);
|
||||
dos.writeByte(ControlEvent.TYPE_SCROLL);
|
||||
dos.writeInt(260);
|
||||
dos.writeInt(1026);
|
||||
dos.writeShort(1080);
|
||||
dos.writeShort(1920);
|
||||
dos.writeInt(1);
|
||||
dos.writeInt(-1);
|
||||
|
||||
byte[] packet = bos.toByteArray();
|
||||
|
||||
reader.readFrom(new ByteArrayInputStream(packet));
|
||||
ControlEvent event = reader.next();
|
||||
|
||||
Assert.assertEquals(ControlEvent.TYPE_SCROLL, event.getType());
|
||||
Assert.assertEquals(260, event.getPosition().getPoint().getX());
|
||||
Assert.assertEquals(1026, event.getPosition().getPoint().getY());
|
||||
Assert.assertEquals(1080, event.getPosition().getScreenSize().getWidth());
|
||||
Assert.assertEquals(1920, event.getPosition().getScreenSize().getHeight());
|
||||
Assert.assertEquals(1, event.getHScroll());
|
||||
Assert.assertEquals(-1, event.getVScroll());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseBackOrScreenOnEvent() throws IOException {
|
||||
ControlEventReader reader = new ControlEventReader();
|
||||
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
DataOutputStream dos = new DataOutputStream(bos);
|
||||
dos.writeByte(ControlEvent.TYPE_BACK_OR_SCREEN_ON);
|
||||
|
||||
byte[] packet = bos.toByteArray();
|
||||
|
||||
reader.readFrom(new ByteArrayInputStream(packet));
|
||||
ControlEvent event = reader.next();
|
||||
|
||||
Assert.assertEquals(ControlEvent.TYPE_BACK_OR_SCREEN_ON, event.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseExpandNotificationPanelEvent() throws IOException {
|
||||
ControlEventReader reader = new ControlEventReader();
|
||||
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
DataOutputStream dos = new DataOutputStream(bos);
|
||||
dos.writeByte(ControlEvent.TYPE_EXPAND_NOTIFICATION_PANEL);
|
||||
|
||||
byte[] packet = bos.toByteArray();
|
||||
|
||||
reader.readFrom(new ByteArrayInputStream(packet));
|
||||
ControlEvent event = reader.next();
|
||||
|
||||
Assert.assertEquals(ControlEvent.TYPE_EXPAND_NOTIFICATION_PANEL, event.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseCollapseNotificationPanelEvent() throws IOException {
|
||||
ControlEventReader reader = new ControlEventReader();
|
||||
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
DataOutputStream dos = new DataOutputStream(bos);
|
||||
dos.writeByte(ControlEvent.TYPE_COLLAPSE_NOTIFICATION_PANEL);
|
||||
|
||||
byte[] packet = bos.toByteArray();
|
||||
|
||||
reader.readFrom(new ByteArrayInputStream(packet));
|
||||
ControlEvent event = reader.next();
|
||||
|
||||
Assert.assertEquals(ControlEvent.TYPE_COLLAPSE_NOTIFICATION_PANEL, event.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiEvents() throws IOException {
|
||||
ControlEventReader reader = new ControlEventReader();
|
||||
|
|
Loading…
Reference in New Issue