Esempio n. 1
0
        public void DisposeTest()
        {
            DummyTcpSocket tcpSocket = new DummyTcpSocket();
            AdbSocket socket = new AdbSocket(tcpSocket);

            Assert.IsTrue(socket.Connected);

            socket.Dispose();
            Assert.IsFalse(socket.Connected);
        }
Esempio n. 2
0
        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());
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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());
        }
Esempio n. 5
0
        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]);
        }
Esempio n. 6
0
        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();
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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));
        }
Esempio n. 9
0
        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());
        }