diff options
| author | Lena <lena@omega> | 2026-07-01 00:00:00 +0000 |
|---|---|---|
| committer | Lena <lena@omega> | 2026-07-01 00:00:00 +0000 |
| commit | 30ee8be82e44d1a8250d1f6e27e71f7d5f24aec5 (patch) | |
| tree | ef45988151ad217ecf2fcc81875b43e334e3aa85 /app/src/test/java | |
| parent | c03f0464c1f834c2f4d8642cbfad322033d368b7 (diff) | |
| download | scrcpy-android-30ee8be82e44d1a8250d1f6e27e71f7d5f24aec5.tar.gz | |
app: enter the device address as one host:port field
The form asked for a host, a pairing port and a connection port as three
separate fields. Nothing on screen says which port is which, and the two
are only distinguishable if the reader already knows how adb pair works
on Android 11+.
Take the connection endpoint the way the target prints it, as a single
"ip:port" string copied off the Wireless debugging screen, and leave the
pairing dialog with just its port and code. Devices.parseAddress() does
the split and rejects anything malformed rather than guessing: an
unbracketed IPv6 literal would otherwise be split at the wrong colon.
Reported on the F-Droid submission (fdroiddata!41394).
Diffstat (limited to 'app/src/test/java')
| -rw-r--r-- | app/src/test/java/invalid/lena/scrcpy/DevicesTest.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/app/src/test/java/invalid/lena/scrcpy/DevicesTest.java b/app/src/test/java/invalid/lena/scrcpy/DevicesTest.java index d1e4f02..dcd04ca 100644 --- a/app/src/test/java/invalid/lena/scrcpy/DevicesTest.java +++ b/app/src/test/java/invalid/lena/scrcpy/DevicesTest.java @@ -1,6 +1,7 @@ package invalid.lena.scrcpy; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import org.junit.Test; @@ -53,6 +54,47 @@ public class DevicesTest { } @Test + public void parseAddressSplitsHostAndPort() { + Devices.Device d = Devices.parseAddress(" 192.168.1.42:41234 "); + assertEquals("192.168.1.42", d.host); + assertEquals(41234, d.port); + + Devices.Device v6 = Devices.parseAddress("[fe80::1]:5555"); + assertEquals("fe80::1", v6.host); + assertEquals(5555, v6.port); + // Round-trips through the display form. + assertEquals("[fe80::1]:5555", v6.toString()); + } + + @Test + public void parseAddressRejectsMalformed() { + // No port, empty host, non-numeric and out-of-range ports. + assertNull(Devices.parseAddress(null)); + assertNull(Devices.parseAddress("")); + assertNull(Devices.parseAddress("192.168.1.42")); + assertNull(Devices.parseAddress(":5555")); + assertNull(Devices.parseAddress("192.168.1.42:")); + assertNull(Devices.parseAddress("192.168.1.42:port")); + assertNull(Devices.parseAddress("192.168.1.42:0")); + assertNull(Devices.parseAddress("192.168.1.42:65536")); + // Unbracketed IPv6 would otherwise split at the wrong colon. + assertNull(Devices.parseAddress("fe80::1:5555")); + assertNull(Devices.parseAddress("[fe80::1]5555")); + } + + @Test + public void parsePortRejectsNonDigits() { + assertEquals(5555, Devices.parsePort(" 5555 ")); + assertEquals(1, Devices.parsePort("1")); + assertEquals(65535, Devices.parsePort("65535")); + assertEquals(-1, Devices.parsePort("")); + assertEquals(-1, Devices.parsePort("+5555")); + assertEquals(-1, Devices.parsePort("-1")); + assertEquals(-1, Devices.parsePort("55x5")); + assertEquals(-1, Devices.parsePort("655360")); + } + + @Test public void deviceEqualsByHostAndPort() { Devices.Device a = new Devices.Device("1.1.1.1", 5555); Devices.Device b = new Devices.Device("1.1.1.1", 5555); |