public async Task ReadAsyncTest() { DummyTcpSocket tcpSocket = new DummyTcpSocket(); AdbSocket socket = new AdbSocket(tcpSocket); // Read 100 bytes from a stream which has 101 bytes available byte[] data = new byte[101]; for (int i = 0; i < 101; i++) { data[i] = (byte)i; } tcpSocket.InputStream.Write(data, 0, 101); tcpSocket.InputStream.Position = 0; // Buffer has a capacity of 101, but we'll only want to read 100 bytes byte[] received = new byte[101]; await socket.ReadAsync(received, 100, CancellationToken.None); for (int i = 0; i < 100; i++) { Assert.AreEqual(received[i], (byte)i); } Assert.AreEqual(0, received[100]); }
private void InitAdbSocket() { IPAddress ipaddress = IPAddress.Parse("127.0.0.1"); IPEndPoint ipendpoint = new IPEndPoint(ipaddress, 5037);//the default . AdbSocket = new AdbSocket(ipendpoint); }
public void IsOkayTest() { var okay = Encoding.ASCII.GetBytes("OKAY"); var fail = Encoding.ASCII.GetBytes("FAIL"); Assert.IsTrue(AdbSocket.IsOkay(okay)); Assert.IsFalse(AdbSocket.IsOkay(fail)); }
public static void Test(string cmd) { using (AdbSocket socket = new AdbSocket(AdbClient.Instance.EndPoint)) { socket.SendAdbRequest(cmd); var response = socket.ReadAdbResponse(); Main.IO.Print(response.Message, ConsoleColor.Magenta); } }
public void DisposeTest() { DummyTcpSocket tcpSocket = new DummyTcpSocket(); AdbSocket socket = new AdbSocket(tcpSocket); Assert.IsTrue(socket.Connected); socket.Dispose(); Assert.IsFalse(socket.Connected); }
private void RunTest(Action <IAdbSocket> test, byte[] expectedDataSent) { DummyTcpSocket tcpSocket = new DummyTcpSocket(); AdbSocket socket = new AdbSocket(tcpSocket); // Run the test. test(socket); // Validate the data that was sent over the wire. CollectionAssert.AreEqual(expectedDataSent, tcpSocket.GetBytesSent()); }
public void GetShellStreamTest() { DummyTcpSocket tcpSocket = new DummyTcpSocket(); AdbSocket socket = new AdbSocket(tcpSocket); var stream = socket.GetShellStream(); Assert.IsInstanceOfType(stream, typeof(ShellStream)); var shellStream = (ShellStream)stream; Assert.AreEqual(tcpSocket.OutputStream, shellStream.Inner); }
public void GetShellStreamTest() { DummyTcpSocket tcpSocket = new DummyTcpSocket(); AdbSocket socket = new AdbSocket(tcpSocket); var stream = socket.GetShellStream(); Assert.IsType <ShellStream>(stream); var shellStream = (ShellStream)stream; Assert.Equal(tcpSocket.OutputStream, shellStream.Inner); }
private async Task <RemoteAdbDevice> Connect(IPEndPoint endpoint) { this.EndPoint = endpoint; _socket = new AdbSocket(endpoint); //_socket.Connect(endpoint); var cmd = Command.CreateConnectCommand(); _socket.Send(cmd, cmd.Length); var connectionPacket = await ReceivePacket(true); StartReading(); return(this); }
public void ReadSyncResponse() { DummyTcpSocket tcpSocket = new DummyTcpSocket(); AdbSocket socket = new AdbSocket(tcpSocket); using (StreamWriter writer = new StreamWriter(tcpSocket.InputStream, Encoding.ASCII, 4, true)) { writer.Write("DENT"); } tcpSocket.InputStream.Position = 0; Assert.AreEqual(SyncCommand.DENT, socket.ReadSyncResponse()); }
public void ReadSyncString() { DummyTcpSocket tcpSocket = new DummyTcpSocket(); AdbSocket socket = new AdbSocket(tcpSocket); using (BinaryWriter writer = new BinaryWriter(tcpSocket.InputStream, Encoding.ASCII, true)) { writer.Write(5); writer.Write(Encoding.ASCII.GetBytes("Hello")); writer.Flush(); } tcpSocket.InputStream.Position = 0; Assert.AreEqual("Hello", socket.ReadSyncString()); }
public void ReadAdbFailResponseTest() { DummyTcpSocket tcpSocket = new DummyTcpSocket(); AdbSocket socket = new AdbSocket(tcpSocket); using (StreamWriter writer = new StreamWriter(tcpSocket.InputStream, Encoding.ASCII, 4, true)) { writer.Write("FAIL"); writer.Write(17.ToString("X4")); writer.Write("This did not work"); } tcpSocket.InputStream.Position = 0; var response = socket.ReadAdbResponse(); }
public async Task ReadStringAsyncTest() { DummyTcpSocket tcpSocket = new DummyTcpSocket(); AdbSocket socket = new AdbSocket(tcpSocket); using (BinaryWriter writer = new BinaryWriter(tcpSocket.InputStream, Encoding.ASCII, true)) { writer.Write(Encoding.ASCII.GetBytes(5.ToString("X4"))); writer.Write(Encoding.ASCII.GetBytes("Hello")); writer.Flush(); } tcpSocket.InputStream.Position = 0; Assert.AreEqual("Hello", await socket.ReadStringAsync(CancellationToken.None)); }
public void ReadAdbOkayResponseTest() { DummyTcpSocket tcpSocket = new DummyTcpSocket(); AdbSocket socket = new AdbSocket(tcpSocket); using (StreamWriter writer = new StreamWriter(tcpSocket.InputStream, Encoding.ASCII, 4, true)) { writer.Write("OKAY"); } tcpSocket.InputStream.Position = 0; var response = socket.ReadAdbResponse(); Assert.IsTrue(response.IOSuccess); Assert.AreEqual(string.Empty, response.Message); Assert.IsTrue(response.Okay); Assert.IsFalse(response.Timeout); }
public byte[] GetScreenshot() { var isConnected = EnsureAdbServerRunning(); if (isConnected == false) { return(Array.Empty <byte>()); } var device = _adbClient.GetDevices()[0]; const string screenshotPathOnDevice = "/sdcard/DCIM/raid.png"; _adbClient.ExecuteRemoteCommand($"screencap -p {screenshotPathOnDevice}", device, new DebugReceiver()); using var memoryStream = new MemoryStream(); using var adbSocket = new AdbSocket(_adbClient.EndPoint); using var syncService = _syncServiceFactory.Create(adbSocket, device); syncService.Pull(screenshotPathOnDevice, memoryStream, null, CancellationToken.None); return(memoryStream.ToArray()); }
public void GetShellStreamTest() { DummyTcpSocket tcpSocket = new DummyTcpSocket(); AdbSocket socket = new AdbSocket(tcpSocket); var stream = socket.GetShellStream(); Assert.IsInstanceOfType(stream, typeof(ShellStream)); var shellStream = (ShellStream)stream; Assert.AreEqual(tcpSocket.InputStream, shellStream.Inner); }
private void RunTest(Action<IAdbSocket> test, byte[] expectedDataSent) { DummyTcpSocket tcpSocket = new DummyTcpSocket(); AdbSocket socket = new AdbSocket(tcpSocket); // Run the test. test(socket); // Validate the data that was sent over the wire. CollectionAssert.AreEqual(expectedDataSent, tcpSocket.GetBytesSent()); }