Skip to content

Commit

Permalink
Add tests for control message length
Browse files Browse the repository at this point in the history
This will avoid regressions for #1245.

<#1245>
  • Loading branch information
rom1v committed Mar 26, 2020
1 parent 89d1602 commit 3504c00
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

public class ControlMessageReader {

private static final int INJECT_KEYCODE_PAYLOAD_LENGTH = 9;
private static final int INJECT_TOUCH_EVENT_PAYLOAD_LENGTH = 27;
private static final int INJECT_SCROLL_EVENT_PAYLOAD_LENGTH = 20;
private static final int SET_SCREEN_POWER_MODE_PAYLOAD_LENGTH = 1;
static final int INJECT_KEYCODE_PAYLOAD_LENGTH = 9;
static final int INJECT_TOUCH_EVENT_PAYLOAD_LENGTH = 27;
static final int INJECT_SCROLL_EVENT_PAYLOAD_LENGTH = 20;
static final int SET_SCREEN_POWER_MODE_PAYLOAD_LENGTH = 1;

public static final int TEXT_MAX_LENGTH = 300;
public static final int CLIPBOARD_TEXT_MAX_LENGTH = 4093;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public void testParseKeycodeEvent() throws IOException {
dos.writeInt(KeyEvent.META_CTRL_ON);
byte[] packet = bos.toByteArray();

// The message type (1 byte) does not count
Assert.assertEquals(ControlMessageReader.INJECT_KEYCODE_PAYLOAD_LENGTH, packet.length - 1);

reader.readFrom(new ByteArrayInputStream(packet));
ControlMessage event = reader.next();

Expand Down Expand Up @@ -95,6 +98,9 @@ public void testParseTouchEvent() throws IOException {

byte[] packet = bos.toByteArray();

// The message type (1 byte) does not count
Assert.assertEquals(ControlMessageReader.INJECT_TOUCH_EVENT_PAYLOAD_LENGTH, packet.length - 1);

reader.readFrom(new ByteArrayInputStream(packet));
ControlMessage event = reader.next();

Expand Down Expand Up @@ -126,6 +132,9 @@ public void testParseScrollEvent() throws IOException {

byte[] packet = bos.toByteArray();

// The message type (1 byte) does not count
Assert.assertEquals(ControlMessageReader.INJECT_SCROLL_EVENT_PAYLOAD_LENGTH, packet.length - 1);

reader.readFrom(new ByteArrayInputStream(packet));
ControlMessage event = reader.next();

Expand Down Expand Up @@ -233,6 +242,9 @@ public void testParseSetScreenPowerMode() throws IOException {

byte[] packet = bos.toByteArray();

// The message type (1 byte) does not count
Assert.assertEquals(ControlMessageReader.SET_SCREEN_POWER_MODE_PAYLOAD_LENGTH, packet.length - 1);

reader.readFrom(new ByteArrayInputStream(packet));
ControlMessage event = reader.next();

Expand Down

0 comments on commit 3504c00

Please sign in to comment.