Skip to content

Commit 479eac4

Browse files
authored
Merge pull request #134 from SharpAdb/feature/sync-v2
Add ADB Sync V2 supports
2 parents 6ee88f5 + 7797553 commit 479eac4

File tree

74 files changed

+4025
-1044
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+4025
-1044
lines changed

.github/ISSUE_TEMPLATE/bug_report.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: Bug report
22
description: Create a report to help us improve
33
title: Bug title
44
labels: [bug]
5+
type: Bug
56
body:
67
- type: textarea
78
validations:

.github/ISSUE_TEMPLATE/feature_request.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: Feature request
22
description: Suggest an idea for this project
33
title: Feature title
44
labels: [enhancement]
5+
type: Feature
56
body:
67
- type: textarea
78
validations:

AdvancedSharpAdbClient.Tests/AdbClientTests.Async.cs

Lines changed: 145 additions & 97 deletions
Large diffs are not rendered by default.

AdvancedSharpAdbClient.Tests/AdbCommandLineClientTests.Async.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public async Task GetVersionAsyncTest()
2020
{
2121
Version = new AdbCommandLineStatus(adbVersion, fileVersion, filePath)
2222
};
23-
AdbCommandLineStatus status = await commandLine.GetVersionAsync();
23+
AdbCommandLineStatus status = await commandLine.GetVersionAsync(TestContext.Current.CancellationToken);
2424
Assert.Equal(adbVersion, status.AdbVersion);
2525
Assert.Equal(fileVersion, status.FileVersion);
2626
Assert.Equal(filePath, status.FilePath);
@@ -36,7 +36,7 @@ public async Task GetVersionAsyncNullTest()
3636
{
3737
Version = default
3838
};
39-
_ = await Assert.ThrowsAsync<AdbException>(() => commandLine.GetVersionAsync());
39+
_ = await Assert.ThrowsAsync<AdbException>(() => commandLine.GetVersionAsync(TestContext.Current.CancellationToken));
4040
}
4141

4242
/// <summary>
@@ -49,7 +49,7 @@ public async Task GetOutdatedVersionAsyncTest()
4949
{
5050
Version = AdbCommandLineStatus.GetVersionFromOutput(["Android Debug Bridge version 1.0.1"])
5151
};
52-
_ = await Assert.ThrowsAsync<AdbException>(() => commandLine.GetVersionAsync());
52+
_ = await Assert.ThrowsAsync<AdbException>(() => commandLine.GetVersionAsync(TestContext.Current.CancellationToken));
5353
}
5454

5555
/// <summary>
@@ -60,7 +60,7 @@ public async Task StartServerAsyncTest()
6060
{
6161
DummyAdbCommandLineClient commandLine = new();
6262
Assert.False(commandLine.ServerStarted);
63-
await commandLine.StartServerAsync();
63+
await commandLine.StartServerAsync(TestContext.Current.CancellationToken);
6464
Assert.True(commandLine.ServerStarted);
6565
}
6666
}

AdvancedSharpAdbClient.Tests/AdbServerTests.Async.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public async Task GetStatusAsyncNotRunningTest()
2121

2222
AdbServer adbServer = new(endPoint => adbSocketMock, adbCommandLineClientFactory);
2323

24-
AdbServerStatus status = await adbServer.GetStatusAsync();
24+
AdbServerStatus status = await adbServer.GetStatusAsync(TestContext.Current.CancellationToken);
2525
Assert.False(status.IsRunning);
2626
Assert.Null(status.Version);
2727
}
@@ -35,7 +35,7 @@ public async Task GetStatusAsyncRunningTest()
3535
socket.Responses.Enqueue(AdbResponse.OK);
3636
socket.ResponseMessages.Enqueue("0020");
3737

38-
AdbServerStatus status = await adbServer.GetStatusAsync();
38+
AdbServerStatus status = await adbServer.GetStatusAsync(TestContext.Current.CancellationToken);
3939

4040
Assert.Empty(socket.Responses);
4141
Assert.Empty(socket.ResponseMessages);
@@ -56,7 +56,7 @@ public async Task GetStatusAsyncOtherSocketExceptionTest()
5656

5757
adbServer = new AdbServer(adbSocketFactory, adbCommandLineClientFactory);
5858

59-
_ = await Assert.ThrowsAsync<SocketException>(async () => await adbServer.GetStatusAsync());
59+
_ = await Assert.ThrowsAsync<SocketException>(() => adbServer.GetStatusAsync(TestContext.Current.CancellationToken));
6060
}
6161

6262
/// <summary>
@@ -69,7 +69,7 @@ public async Task GetStatusAsyncOtherExceptionTest()
6969

7070
adbServer = new AdbServer(adbSocketFactory, adbCommandLineClientFactory);
7171

72-
_ = await Assert.ThrowsAsync<Exception>(async () => await adbServer.GetStatusAsync());
72+
_ = await Assert.ThrowsAsync<Exception>(() => adbServer.GetStatusAsync(TestContext.Current.CancellationToken));
7373
}
7474

7575
/// <summary>
@@ -82,7 +82,7 @@ public async Task StartServerAsyncAlreadyRunningTest()
8282
socket.Responses.Enqueue(AdbResponse.OK);
8383
socket.ResponseMessages.Enqueue("0020");
8484

85-
StartServerResult result = await adbServer.StartServerAsync(null, false);
85+
StartServerResult result = await adbServer.StartServerAsync(null, false, TestContext.Current.CancellationToken);
8686

8787
Assert.Equal(StartServerResult.AlreadyRunning, result);
8888

@@ -99,7 +99,7 @@ public async Task StartServerAsyncOutdatedRunningNoExecutableTest()
9999
socket.Responses.Enqueue(AdbResponse.OK);
100100
socket.ResponseMessages.Enqueue("0010");
101101

102-
AggregateException exception = await Assert.ThrowsAsync<AggregateException>(async () => await adbServer.StartServerAsync(null, false));
102+
AggregateException exception = await Assert.ThrowsAsync<AggregateException>(() => adbServer.StartServerAsync(null, false, TestContext.Current.CancellationToken));
103103
Assert.IsType<AdbException>(exception.InnerException);
104104
}
105105

@@ -113,7 +113,7 @@ public async Task StartServerAsyncNotRunningNoExecutableTest()
113113

114114
adbServer = new AdbServer(adbSocketFactory, adbCommandLineClientFactory);
115115

116-
AggregateException exception = await Assert.ThrowsAsync<AggregateException>(async () => await adbServer.StartServerAsync(null, false));
116+
AggregateException exception = await Assert.ThrowsAsync<AggregateException>(() => adbServer.StartServerAsync(null, false, TestContext.Current.CancellationToken));
117117
Assert.IsType<AdbException>(exception.InnerException);
118118
}
119119

@@ -129,7 +129,7 @@ public async Task StartServerAsyncOutdatedRunningTest()
129129
commandLineClient.Version = AdbCommandLineStatus.GetVersionFromOutput(["Android Debug Bridge version 1.0.32"]);
130130

131131
Assert.False(commandLineClient.ServerStarted);
132-
_ = await adbServer.StartServerAsync(ServerName, false);
132+
_ = await adbServer.StartServerAsync(ServerName, false, TestContext.Current.CancellationToken);
133133

134134
Assert.True(commandLineClient.ServerStarted);
135135

@@ -152,7 +152,7 @@ public async Task StartServerAsyncNotRunningTest()
152152

153153
Assert.False(commandLineClient.ServerStarted);
154154

155-
StartServerResult result = await adbServer.StartServerAsync(ServerName, false);
155+
StartServerResult result = await adbServer.StartServerAsync(ServerName, false, TestContext.Current.CancellationToken);
156156

157157
Assert.True(commandLineClient.ServerStarted);
158158
}
@@ -169,7 +169,7 @@ public async Task StartServerAsyncIntermediateRestartRequestedRunningTest()
169169
commandLineClient.Version = AdbCommandLineStatus.GetVersionFromOutput(["Android Debug Bridge version 1.0.32"]);
170170

171171
Assert.False(commandLineClient.ServerStarted);
172-
_ = await adbServer.StartServerAsync(ServerName, true);
172+
_ = await adbServer.StartServerAsync(ServerName, true, TestContext.Current.CancellationToken);
173173

174174
Assert.True(commandLineClient.ServerStarted);
175175

@@ -190,7 +190,7 @@ public async Task StartServerAsyncIntermediateRestartNotRequestedRunningTest()
190190
commandLineClient.Version = AdbCommandLineStatus.GetVersionFromOutput(["Android Debug Bridge version 1.0.32"]);
191191

192192
Assert.False(commandLineClient.ServerStarted);
193-
_ = await adbServer.StartServerAsync(ServerName, false);
193+
_ = await adbServer.StartServerAsync(ServerName, false, TestContext.Current.CancellationToken);
194194

195195
Assert.False(commandLineClient.ServerStarted);
196196

@@ -210,7 +210,7 @@ public async Task RestartServerAsyncTest()
210210
commandLineClient.Version = AdbCommandLineStatus.GetVersionFromOutput(["Android Debug Bridge version 1.0.32"]);
211211

212212
Assert.False(commandLineClient.ServerStarted);
213-
_ = await adbServer.RestartServerAsync(ServerName);
213+
_ = await adbServer.RestartServerAsync(ServerName, TestContext.Current.CancellationToken);
214214

215215
Assert.True(commandLineClient.ServerStarted);
216216

@@ -225,7 +225,7 @@ public async Task RestartServerAsyncTest()
225225
[Fact]
226226
public async Task StopServerAsyncTest()
227227
{
228-
await adbServer.StopServerAsync();
228+
await adbServer.StopServerAsync(TestContext.Current.CancellationToken);
229229

230230
Assert.Single(socket.Requests);
231231
Assert.Equal("host:kill", socket.Requests[0]);

AdvancedSharpAdbClient.Tests/AdbSocketTests.Async.cs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,37 @@ public partial class AdbSocketTests
1515
[Fact]
1616
public async Task SendSyncDATARequestAsyncTest() =>
1717
await RunTestAsync(
18-
socket => socket.SendSyncRequestAsync(SyncCommand.DATA, 2, default),
19-
[(byte)'D', (byte)'A', (byte)'T', (byte)'A', 2, 0, 0, 0]);
18+
(socket, ctx) => socket.SendSyncRequestAsync(SyncCommand.DATA, 2, ctx),
19+
[(byte)'D', (byte)'A', (byte)'T', (byte)'A', 2, 0, 0, 0],
20+
TestContext.Current.CancellationToken);
2021

2122
/// <summary>
2223
/// Tests the <see cref="AdbSocket.SendSyncRequestAsync(SyncCommand, string, UnixFileStatus, CancellationToken)"/> method.
2324
/// </summary>
2425
[Fact]
2526
public async Task SendSyncSENDRequestAsyncTest() =>
2627
await RunTestAsync(
27-
socket => socket.SendSyncRequestAsync(SyncCommand.SEND, "/test", UnixFileStatus.GroupMask | UnixFileStatus.StickyBit | UnixFileStatus.UserExecute | UnixFileStatus.OtherExecute, default),
28-
[(byte)'S', (byte)'E', (byte)'N', (byte)'D', 9, 0, 0, 0, (byte)'/', (byte)'t', (byte)'e', (byte)'s', (byte)'t', (byte)',', (byte)'6', (byte)'3', (byte)'3']);
28+
(socket, ctx) => socket.SendSyncRequestAsync(SyncCommand.SEND, "/test", UnixFileStatus.GroupMask | UnixFileStatus.StickyBit | UnixFileStatus.UserExecute | UnixFileStatus.OtherExecute, ctx),
29+
[(byte)'S', (byte)'E', (byte)'N', (byte)'D', 9, 0, 0, 0, (byte)'/', (byte)'t', (byte)'e', (byte)'s', (byte)'t', (byte)',', (byte)'6', (byte)'3', (byte)'3'],
30+
TestContext.Current.CancellationToken);
2931

3032
/// <summary>
3133
/// Tests the <see cref="AdbSocket.SendSyncRequestAsync(SyncCommand, string, CancellationToken)"/> method.
3234
/// </summary>
3335
[Fact]
3436
public async Task SendSyncDENTRequestAsyncTest() =>
3537
await RunTestAsync(
36-
socket => socket.SendSyncRequestAsync(SyncCommand.DENT, "/data", default),
37-
[(byte)'D', (byte)'E', (byte)'N', (byte)'T', 5, 0, 0, 0, (byte)'/', (byte)'d', (byte)'a', (byte)'t', (byte)'a']);
38+
(socket, ctx) => socket.SendSyncRequestAsync(SyncCommand.DENT, "/data", ctx),
39+
[(byte)'D', (byte)'E', (byte)'N', (byte)'T', 5, 0, 0, 0, (byte)'/', (byte)'d', (byte)'a', (byte)'t', (byte)'a'],
40+
TestContext.Current.CancellationToken);
3841

3942
/// <summary>
4043
/// Tests the <see cref="AdbSocket.SendSyncRequestAsync(SyncCommand, string, CancellationToken)"/> method.
4144
/// </summary>
4245
[Fact]
4346
public async Task SendSyncNullRequestAsyncTest() =>
4447
_ = await Assert.ThrowsAsync<ArgumentNullException>(() =>
45-
RunTestAsync(socket => socket.SendSyncRequestAsync(SyncCommand.DATA, null, default), []));
48+
RunTestAsync((socket, ctx) => socket.SendSyncRequestAsync(SyncCommand.DATA, null, ctx), [], TestContext.Current.CancellationToken));
4649

4750
/// <summary>
4851
/// Tests the <see cref="AdbSocket.ReadSyncResponseAsync(CancellationToken)"/> method.
@@ -60,7 +63,7 @@ public async Task ReadSyncResponseAsync()
6063

6164
tcpSocket.InputStream.Position = 0;
6265

63-
Assert.Equal(SyncCommand.DENT, await socket.ReadSyncResponseAsync());
66+
Assert.Equal(SyncCommand.DENT, await socket.ReadSyncResponseAsync(TestContext.Current.CancellationToken));
6467
}
6568

6669
/// <summary>
@@ -81,7 +84,7 @@ public async Task ReadStringAsyncTest()
8184

8285
tcpSocket.InputStream.Position = 0;
8386

84-
Assert.Equal("Hello", await socket.ReadStringAsync());
87+
Assert.Equal("Hello", await socket.ReadStringAsync(TestContext.Current.CancellationToken));
8588
}
8689

8790
/// <summary>
@@ -103,7 +106,7 @@ public async Task ReadFailStringAsyncTest()
103106

104107
tcpSocket.InputStream.Position = 0;
105108

106-
Assert.Equal("Hello", await socket.ReadStringAsync());
109+
Assert.Equal("Hello", await socket.ReadStringAsync(TestContext.Current.CancellationToken));
107110
}
108111

109112
/// <summary>
@@ -124,7 +127,7 @@ public async Task ReadSyncStringAsyncTest()
124127

125128
tcpSocket.InputStream.Position = 0;
126129

127-
Assert.Equal("Hello", await socket.ReadSyncStringAsync());
130+
Assert.Equal("Hello", await socket.ReadSyncStringAsync(TestContext.Current.CancellationToken));
128131
}
129132

130133
/// <summary>
@@ -143,7 +146,7 @@ public async Task ReadAdbOkayResponseAsyncTest()
143146

144147
tcpSocket.InputStream.Position = 0;
145148

146-
AdbResponse response = await socket.ReadAdbResponseAsync();
149+
AdbResponse response = await socket.ReadAdbResponseAsync(TestContext.Current.CancellationToken);
147150
Assert.True(response.IOSuccess);
148151
Assert.Equal(string.Empty, response.Message);
149152
Assert.True(response.Okay);
@@ -168,7 +171,7 @@ public async Task ReadAdbFailResponseAsyncTest()
168171

169172
tcpSocket.InputStream.Position = 0;
170173

171-
_ = await Assert.ThrowsAsync<AdbException>(() => socket.ReadAdbResponseAsync());
174+
_ = await Assert.ThrowsAsync<AdbException>(() => socket.ReadAdbResponseAsync(TestContext.Current.CancellationToken));
172175
}
173176

174177
/// <summary>
@@ -187,13 +190,13 @@ public async Task ReadAsyncTest()
187190
data[i] = (byte)i;
188191
}
189192

190-
await tcpSocket.InputStream.WriteAsync(data);
193+
await tcpSocket.InputStream.WriteAsync(data, TestContext.Current.CancellationToken);
191194
tcpSocket.InputStream.Position = 0;
192195

193196
// Buffer has a capacity of 101, but we'll only want to read 100 bytes
194197
byte[] received = new byte[101];
195198

196-
await socket.ReadAsync(received, 100);
199+
await socket.ReadAsync(received, 100, TestContext.Current.CancellationToken);
197200

198201
for (int i = 0; i < 100; i++)
199202
{
@@ -219,13 +222,13 @@ public async Task ReadAsyncMemoryTest()
219222
data[i] = (byte)i;
220223
}
221224

222-
await tcpSocket.InputStream.WriteAsync(data);
225+
await tcpSocket.InputStream.WriteAsync(data, TestContext.Current.CancellationToken);
223226
tcpSocket.InputStream.Position = 0;
224227

225228
// Buffer has a capacity of 101, but we'll only want to read 100 bytes
226229
byte[] received = new byte[101];
227230

228-
await socket.ReadAsync(received.AsMemory(0, 100));
231+
await socket.ReadAsync(received.AsMemory(0, 100), TestContext.Current.CancellationToken);
229232

230233
for (int i = 0; i < 100; i++)
231234
{
@@ -241,16 +244,17 @@ public async Task ReadAsyncMemoryTest()
241244
[Fact]
242245
public async Task SendAdbRequestAsyncTest() =>
243246
await RunTestAsync(
244-
socket => socket.SendAdbRequestAsync("Test", default),
245-
"0004Test"u8.ToArray());
247+
(socket, ctx) => socket.SendAdbRequestAsync("Test", ctx),
248+
"0004Test"u8.ToArray(),
249+
TestContext.Current.CancellationToken);
246250

247-
private static async Task RunTestAsync(Func<IAdbSocket, Task> test, byte[] expectedDataSent)
251+
private static async Task RunTestAsync(Func<IAdbSocket, CancellationToken, Task> test, byte[] expectedDataSent, CancellationToken cancellationToken = default)
248252
{
249253
using DummyTcpSocket tcpSocket = new();
250254
using AdbSocket socket = new(tcpSocket);
251255

252256
// Run the test.
253-
await test(socket);
257+
await test(socket, cancellationToken);
254258

255259
// Validate the data that was sent over the wire.
256260
Assert.Equal(expectedDataSent, tcpSocket.GetBytesSent());

AdvancedSharpAdbClient.Tests/AdvancedSharpAdbClient.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
</PackageReference>
2626
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
2727
<PackageReference Include="NSubstitute" Version="5.3.0" />
28-
<PackageReference Include="xunit" Version="2.9.3" />
2928
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" PrivateAssets="all">
3029
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3130
</PackageReference>
31+
<PackageReference Include="xunit.v3" Version="3.2.1" />
3232
</ItemGroup>
3333

3434
<ItemGroup>

0 commit comments

Comments
 (0)