feat: manage multiple desktop device connections independently

This commit is contained in:
tongtong committed 2026-11-12 18:15:04 +08:00
1 parent 08d60de364
commit 05d4d5fea6
12 files changed
+504 -249

No files matched your search

@@ -0,0 +1,23 @@
using System.Net;
using System.Net.Sockets;
using Ads.Desktop;
using Xunit;
namespace Ads.Desktop.Tests;
public class ConnectionPortsTests
{
[Fact] public void AllocationSkipsReservedAndForeignListenerWithoutClosingIt()
{
var occupied = new TcpListener(IPAddress.Loopback, 0); occupied.Start();
try {
var first = ((IPEndPoint)occupied.LocalEndpoint).Port;
var a = ConnectionPorts.Allocate(first, [first + 1]);
var b = ConnectionPorts.Allocate(first, [first + 1, a]);
Assert.NotEqual(first, a); Assert.NotEqual(first + 1, a); Assert.NotEqual(a, b);
Assert.True(occupied.Server.IsBound);
} finally { occupied.Stop(); }
}
[Fact] public void AdbServerPortIsNeverAllocated() => Assert.NotEqual(5037, ConnectionPorts.Allocate(5037, []));
[Fact] public void ExhaustedRangeFailsWithoutReusingReservedPort() => Assert.Throws<InvalidOperationException>(() => ConnectionPorts.Allocate(65535, [65535]));
[Theory] [InlineData(0)] [InlineData(65536)]
public void InvalidBasePortFails(int port) => Assert.Throws<InvalidOperationException>(() => ConnectionPorts.Allocate(port, []));
}