public void DisposeTest() { DummyTcpSocket tcpSocket = new DummyTcpSocket(); AdbSocket socket = new AdbSocket(tcpSocket); Assert.IsTrue(socket.Connected); socket.Dispose(); Assert.IsFalse(socket.Connected); }
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 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()); }
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]); }
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 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 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 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()); }