Skip to content

Commit ba24d53

Browse files
committed
Add IsProcessing to SyncService
1 parent b9b5260 commit ba24d53

File tree

9 files changed

+178
-28
lines changed

9 files changed

+178
-28
lines changed

AdvancedSharpAdbClient.Tests/SyncServiceTests.Async.cs

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ public async void StatAsyncTest()
2525
async () =>
2626
{
2727
using SyncService service = new(Socket, Device);
28-
return await service.StatAsync("/fstab.donatello");
28+
FileStatistics value = await service.StatAsync("/fstab.donatello");
29+
Assert.False(service.IsProcessing);
30+
Assert.False(service.IsOutdate);
31+
return value;
2932
});
3033

3134
Assert.Equal(UnixFileStatus.Regular, value.FileMode.GetFileType());
@@ -56,7 +59,10 @@ public async void GetListingAsyncTest()
5659
async () =>
5760
{
5861
using SyncService service = new(Socket, Device);
59-
return await service.GetDirectoryListingAsync("/storage");
62+
List<FileStatistics> value = await service.GetDirectoryListingAsync("/storage");
63+
Assert.False(service.IsProcessing);
64+
Assert.True(service.IsOutdate);
65+
return value;
6066
});
6167

6268
Assert.Equal(4, value.Count);
@@ -110,7 +116,10 @@ public async void GetAsyncListingTest()
110116
async () =>
111117
{
112118
using SyncService service = new(Socket, Device);
113-
return await service.GetDirectoryAsyncListing("/storage").ToListAsync();
119+
List<FileStatistics> value = await service.GetDirectoryAsyncListing("/storage").ToListAsync();
120+
Assert.False(service.IsProcessing);
121+
Assert.True(service.IsOutdate);
122+
return value;
114123
});
115124

116125
Assert.Equal(4, value.Count);
@@ -171,6 +180,8 @@ await RunTestAsync(
171180
{
172181
using SyncService service = new(Socket, Device);
173182
await service.PullAsync("/fstab.donatello", stream, null);
183+
Assert.False(service.IsProcessing);
184+
Assert.True(service.IsOutdate);
174185
});
175186

176187
// Make sure the data that has been sent to the stream is the expected data
@@ -207,6 +218,48 @@ await RunTestAsync(
207218
{
208219
using SyncService service = new(Socket, Device);
209220
await service.PushAsync(stream, "/sdcard/test", UnixFileStatus.StickyBit | UnixFileStatus.UserWrite | UnixFileStatus.OtherRead, new DateTime(2015, 11, 2, 23, 0, 0, DateTimeKind.Utc), null);
221+
Assert.False(service.IsProcessing);
222+
Assert.True(service.IsOutdate);
223+
});
224+
}
225+
226+
/// <summary>
227+
/// Tests the <see cref="SyncService.IsProcessing"/> field.
228+
/// </summary>
229+
[Fact]
230+
public async void IsProcessingAsyncTest()
231+
{
232+
await RunTestAsync(
233+
OkResponses(2),
234+
[".", "..", "sdcard0", "emulated"],
235+
["host:transport:169.254.109.177:5555", "sync:"],
236+
[(SyncCommand.LIST, "/storage")],
237+
[SyncCommand.DENT, SyncCommand.DENT, SyncCommand.DENT, SyncCommand.DENT, SyncCommand.DONE],
238+
[
239+
[233, 65, 0, 0, 0, 0, 0, 0, 152, 130, 56, 86],
240+
[237, 65, 0, 0, 0, 0, 0, 0, 152, 130, 56, 86],
241+
[255, 161, 0, 0, 24, 0, 0, 0, 152, 130, 56, 86],
242+
[109, 65, 0, 0, 0, 0, 0, 0, 152, 130, 56, 86]
243+
],
244+
null,
245+
async () =>
246+
{
247+
using SyncService service = new(Socket, Device);
248+
await foreach (FileStatistics stat in service.GetDirectoryAsyncListing("/storage"))
249+
{
250+
Assert.False(service.IsOutdate);
251+
Assert.True(service.IsProcessing);
252+
_ = await Assert.ThrowsAsync<InvalidOperationException>(() => service.PushAsync((Stream)null, null, default, default));
253+
_ = await Assert.ThrowsAsync<InvalidOperationException>(() => service.PullAsync(null, (Stream)null));
254+
#if WINDOWS10_0_17763_0_OR_GREATER
255+
_ = await Assert.ThrowsAsync<InvalidOperationException>(() => service.PushAsync((IInputStream)null, null, default, default));
256+
_ = await Assert.ThrowsAsync<InvalidOperationException>(() => service.PullAsync(null, (IOutputStream)null));
257+
#endif
258+
_ = await Assert.ThrowsAsync<InvalidOperationException>(() => service.GetDirectoryListingAsync(null));
259+
_ = await Assert.ThrowsAsync<InvalidOperationException>(() => service.GetDirectoryAsyncListing(null).ToListAsync().AsTask());
260+
}
261+
Assert.False(service.IsProcessing);
262+
Assert.True(service.IsOutdate);
210263
});
211264
}
212265

@@ -240,6 +293,8 @@ await RunTestAsync(
240293
{
241294
using SyncService service = new(Socket, Device);
242295
await service.PullAsync("/fstab.donatello", stream, null);
296+
Assert.False(service.IsProcessing);
297+
Assert.True(service.IsOutdate);
243298
});
244299

245300
IBuffer buffer = await stream.GetInputStreamAt(0).ReadAsync(new byte[(int)stream.Size].AsBuffer(), (uint)stream.Size, InputStreamOptions.None);
@@ -278,6 +333,8 @@ await RunTestAsync(
278333
{
279334
using SyncService service = new(Socket, Device);
280335
await service.PushAsync(stream, "/sdcard/test", (UnixFileStatus)644, new DateTime(2015, 11, 2, 23, 0, 0, DateTimeKind.Utc), null);
336+
Assert.False(service.IsProcessing);
337+
Assert.True(service.IsOutdate);
281338
});
282339
}
283340
#endif

AdvancedSharpAdbClient.Tests/SyncServiceTests.cs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ public void StatTest()
3535
() =>
3636
{
3737
using SyncService service = new(Socket, Device);
38-
return service.Stat("/fstab.donatello");
38+
FileStatistics value = service.Stat("/fstab.donatello");
39+
Assert.False(service.IsProcessing);
40+
Assert.False(service.IsOutdate);
41+
return value;
3942
});
4043

4144
Assert.Equal(UnixFileStatus.Regular, value.FileMode.GetFileType());
@@ -66,7 +69,10 @@ public void GetListingTest()
6669
() =>
6770
{
6871
using SyncService service = new(Socket, Device);
69-
return service.GetDirectoryListing("/storage").ToArray();
72+
FileStatistics[] value = service.GetDirectoryListing("/storage").ToArray();
73+
Assert.False(service.IsProcessing);
74+
Assert.True(service.IsOutdate);
75+
return value;
7076
});
7177

7278
Assert.Equal(4, value.Length);
@@ -127,6 +133,8 @@ public void PullTest()
127133
{
128134
using SyncService service = new(Socket, Device);
129135
service.Pull("/fstab.donatello", stream);
136+
Assert.False(service.IsProcessing);
137+
Assert.True(service.IsOutdate);
130138
});
131139

132140
// Make sure the data that has been sent to the stream is the expected data
@@ -163,6 +171,43 @@ .. BitConverter.GetBytes(content.Length),
163171
{
164172
using SyncService service = new(Socket, Device);
165173
service.Push(stream, "/sdcard/test", (UnixFileStatus)644, new DateTime(2015, 11, 2, 23, 0, 0, DateTimeKind.Utc));
174+
Assert.False(service.IsProcessing);
175+
Assert.True(service.IsOutdate);
176+
});
177+
}
178+
179+
/// <summary>
180+
/// Tests the <see cref="SyncService.IsProcessing"/> field.
181+
/// </summary>
182+
[Fact]
183+
public void IsProcessingTest()
184+
{
185+
RunTest(
186+
OkResponses(2),
187+
[".", "..", "sdcard0", "emulated"],
188+
["host:transport:169.254.109.177:5555", "sync:"],
189+
[(SyncCommand.LIST, "/storage")],
190+
[SyncCommand.DENT, SyncCommand.DENT, SyncCommand.DENT, SyncCommand.DENT, SyncCommand.DONE],
191+
[
192+
[233, 65, 0, 0, 0, 0, 0, 0, 152, 130, 56, 86],
193+
[237, 65, 0, 0, 0, 0, 0, 0, 152, 130, 56, 86],
194+
[255, 161, 0, 0, 24, 0, 0, 0, 152, 130, 56, 86],
195+
[109, 65, 0, 0, 0, 0, 0, 0, 152, 130, 56, 86]
196+
],
197+
null,
198+
() =>
199+
{
200+
using SyncService service = new(Socket, Device);
201+
foreach (FileStatistics stat in service.GetDirectoryListing("/storage"))
202+
{
203+
Assert.False(service.IsOutdate);
204+
Assert.True(service.IsProcessing);
205+
_ = Assert.Throws<InvalidOperationException>(() => service.Push(null, null, default, default));
206+
_ = Assert.Throws<InvalidOperationException>(() => service.Pull(null, null));
207+
_ = Assert.Throws<InvalidOperationException>(() => service.GetDirectoryListing(null).FirstOrDefault());
208+
}
209+
Assert.False(service.IsProcessing);
210+
Assert.True(service.IsOutdate);
166211
});
167212
}
168213
}

AdvancedSharpAdbClient/AdbClient.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace AdvancedSharpAdbClient
3232
[DebuggerDisplay($"{nameof(AdbClient)} \\{{ {nameof(EndPoint)} = {{{nameof(EndPoint)}}} }}")]
3333
public partial class AdbClient : IAdbClient, ICloneable<IAdbClient>, ICloneable
3434
#if WINDOWS_UWP || WINDOWS10_0_17763_0_OR_GREATER
35-
, IAdbClient.IWinRT
35+
, IAdbClient.IWinRT, ICloneable<IAdbClient.IWinRT>
3636
#endif
3737
{
3838
/// <summary>
@@ -1133,14 +1133,20 @@ public IEnumerable<string> GetFeatureSet(DeviceData device)
11331133
public override string ToString() => $"The {nameof(AdbClient)} communicate with adb server at {EndPoint}";
11341134

11351135
/// <summary>
1136-
/// Creates a new <see cref="AdbClient"/> object that is a copy of the current instance with new <see cref="EndPoint"/>.
1136+
/// Creates a new <see cref="IAdbClient"/> object that is a copy of the current instance with new <see cref="EndPoint"/>.
11371137
/// </summary>
11381138
/// <param name="endPoint">The new <see cref="EndPoint"/> to use.</param>
1139-
/// <returns>A new <see cref="AdbClient"/> object that is a copy of this instance with new <see cref="EndPoint"/>.</returns>
1140-
public AdbClient Clone(EndPoint endPoint) => new(endPoint, AdbSocketFactory);
1139+
/// <returns>A new <see cref="IAdbClient"/> object that is a copy of this instance with new <see cref="EndPoint"/>.</returns>
1140+
public virtual IAdbClient Clone(EndPoint endPoint) => new AdbClient(endPoint, AdbSocketFactory);
11411141

11421142
/// <inheritdoc/>
1143-
public IAdbClient Clone() => new AdbClient(EndPoint, AdbSocketFactory);
1143+
public IAdbClient Clone() => Clone(EndPoint);
1144+
1145+
#if WINDOWS_UWP || WINDOWS10_0_17763_0_OR_GREATER
1146+
/// <inheritdoc/>
1147+
IAdbClient.IWinRT ICloneable<IAdbClient.IWinRT>.Clone() => Clone(EndPoint) is IAdbClient.IWinRT client ? client
1148+
: throw new NotSupportedException($"The {nameof(Clone)} method does not return a {nameof(IAdbClient.IWinRT)} object.");
1149+
#endif
11441150

11451151
/// <inheritdoc/>
11461152
object ICloneable.Clone() => Clone();

AdvancedSharpAdbClient/AdbServer.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,16 +274,16 @@ public AdbServerStatus GetStatus()
274274
public override string ToString() => $"The {nameof(AdbServer)} communicate with adb at {EndPoint}";
275275

276276
/// <summary>
277-
/// Creates a new <see cref="AdbServer"/> object that is a copy of the current instance with new <see cref="EndPoint"/>.
277+
/// Creates a new <see cref="IAdbServer"/> object that is a copy of the current instance with new <see cref="EndPoint"/>.
278278
/// </summary>
279279
/// <param name="endPoint">The new <see cref="EndPoint"/> to use.</param>
280-
/// <returns>A new <see cref="AdbServer"/> object that is a copy of this instance with new <see cref="EndPoint"/>.</returns>
281-
public AdbServer Clone(EndPoint endPoint) => new(endPoint, AdbSocketFactory, AdbCommandLineClientFactory);
280+
/// <returns>A new <see cref="IAdbServer"/> object that is a copy of this instance with new <see cref="EndPoint"/>.</returns>
281+
public virtual IAdbServer Clone(EndPoint endPoint) => new AdbServer(endPoint, AdbSocketFactory, AdbCommandLineClientFactory);
282282

283283
/// <inheritdoc/>
284-
public IAdbServer Clone() => new AdbServer(EndPoint, AdbSocketFactory, AdbCommandLineClientFactory);
284+
public IAdbServer Clone() => Clone(EndPoint);
285285

286286
/// <inheritdoc/>
287-
object ICloneable.Clone() => Clone();
287+
object ICloneable.Clone() => Clone(EndPoint);
288288
}
289289
}

AdvancedSharpAdbClient/AdbSocket.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ public override string ToString() =>
560560
public void Close() => Socket.Dispose();
561561

562562
/// <inheritdoc/>
563-
public IAdbSocket Clone()
563+
public virtual IAdbSocket Clone()
564564
{
565565
if (Socket is not ICloneable<ITcpSocket> cloneable)
566566
{

AdvancedSharpAdbClient/DeviceMonitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ public override string ToString() =>
418418
.ToString();
419419

420420
/// <inheritdoc/>
421-
public IDeviceMonitor Clone() =>
421+
public virtual IDeviceMonitor Clone() =>
422422
Socket is not ICloneable<IAdbSocket> cloneable
423423
? throw new NotSupportedException($"{Socket.GetType()} does not support cloning.")
424424
: new DeviceMonitor(cloneable.Clone(), logger);

AdvancedSharpAdbClient/Extensions/UnixFileStatusExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public static string ToPermissionCode(this UnixFileStatus mode)
216216
#else
217217
char[] code = new char[10];
218218
#endif
219-
BitArray array = new([(int)mode]);
219+
BitArray array = new(new[] { (int)mode });
220220

221221
code[9] = array[0]
222222
? array[9] ? 't' : 'x'

0 commit comments

Comments
 (0)