Skip to content

Commit

Permalink
Fix sync tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qmfrederik committed Apr 18, 2017
1 parent 72d112e commit 6839295
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
14 changes: 9 additions & 5 deletions SharpAdbClient.Tests/DummyAdbSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,7 @@ public void Read(byte[] data, int length)

Assert.AreEqual(actual.Length, length);

for (int i = 0; i < length; i++)
{
data[i] = actual[i];
}
Buffer.BlockCopy(actual, 0, data, 0, length);
}

public void SendSyncRequest(SyncCommand command, string path)
Expand Down Expand Up @@ -240,7 +237,14 @@ public Task<int> ReadAsync(byte[] data, int length, CancellationToken cancellati

public void Send(byte[] data, int offset, int length)
{
throw new NotImplementedException();
if (offset == 0)
{
this.Send(data, length);
}
else
{
throw new NotImplementedException();
}
}
}
}
6 changes: 6 additions & 0 deletions SharpAdbClient.Tests/SocketBasedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@ protected static IEnumerable<Tuple<SyncCommand, string>> SyncRequests(SyncComman
yield return new Tuple<SyncCommand, string>(command, path);
}

protected static IEnumerable<Tuple<SyncCommand, string>> SyncRequests(SyncCommand command, string path, SyncCommand command2, string path2)
{
yield return new Tuple<SyncCommand, string>(command, path);
yield return new Tuple<SyncCommand, string>(command2, path2);
}

protected static IEnumerable<Tuple<SyncCommand, string>> SyncRequests(SyncCommand command, string path, SyncCommand command2, string path2, SyncCommand command3, string path3)
{
yield return new Tuple<SyncCommand, string>(command, path);
Expand Down
15 changes: 10 additions & 5 deletions SharpAdbClient.Tests/SyncServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,18 @@ public void PullTest()

MemoryStream stream = new MemoryStream();
var content = File.ReadAllBytes("fstab.bin");
var contentLength = BitConverter.GetBytes(content.Length);

this.RunTest(
OkResponses(2),
ResponseMessages(),
Requests("host:transport:169.254.109.177:5555", "sync:"),
SyncRequests(SyncCommand.RECV, "/fstab.donatello"),
new SyncCommand[] { SyncCommand.DATA, SyncCommand.DONE },
SyncRequests(SyncCommand.STAT, "/fstab.donatello").Union(SyncRequests(SyncCommand.RECV, "/fstab.donatello")),
new SyncCommand[] { SyncCommand.STAT, SyncCommand.DATA, SyncCommand.DONE },
new byte[][]
{
new byte[] {85, 2, 0, 0},
new byte[] { 160, 129, 0, 0, 85, 2, 0, 0, 0, 0, 0, 0 },
contentLength,
content
},
null,
Expand Down Expand Up @@ -164,20 +166,23 @@ public void PushTest()

Stream stream = File.OpenRead("fstab.bin");
var content = File.ReadAllBytes("fstab.bin");
var contentMessage = new List<byte>();
contentMessage.AddRange(SyncCommandConverter.GetBytes(SyncCommand.DATA));
contentMessage.AddRange(BitConverter.GetBytes(content.Length));
contentMessage.AddRange(content);

this.RunTest(
OkResponses(2),
ResponseMessages(),
Requests("host:transport:169.254.109.177:5555", "sync:"),
SyncRequests(
SyncCommand.SEND, "/sdcard/test,644",
SyncCommand.DATA, content.Length.ToString(),
SyncCommand.DONE, "1446505200"),
new SyncCommand[] { SyncCommand.OKAY },
null,
new byte[][]
{
content
contentMessage.ToArray()
},
() =>
{
Expand Down

0 comments on commit 6839295

Please sign in to comment.