Skip to content

Commit

Permalink
Add platform check on test
Browse files Browse the repository at this point in the history
  • Loading branch information
wherewhere committed Jun 5, 2024
1 parent 894a91f commit 6b69a59
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 10 deletions.
20 changes: 11 additions & 9 deletions AdvancedSharpAdbClient.Tests/AdbClientTests.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ await File.ReadAllBytesAsync("Assets/Framebuffer.bin")
Assert.Equal(0u, header.ColorSpace);

#if WINDOWS
if (!OperatingSystem.IsWindows()) { return; }

using Bitmap image = framebuffer.ToImage();
Assert.NotNull(image);
Assert.Equal(PixelFormat.Format32bppArgb, image.PixelFormat);
Expand Down Expand Up @@ -900,14 +902,6 @@ public async Task InstallWriteAsyncTest()

byte[] response = AdbClient.Encoding.GetBytes($"Success: streamed {stream.Length} bytes\n");

double temp = 0;
Progress<double> progress = new();
progress.ProgressChanged += (sender, args) =>
{
Assert.True(temp <= args, $"{nameof(args)}: {args} is less than {temp}.");
temp = args;
};

await RunTestAsync(
OkResponses(2),
NoResponseMessages,
Expand All @@ -916,7 +910,7 @@ await RunTestAsync(
NoSyncResponses,
[response],
applicationDataChunks,
() => TestClient.InstallWriteAsync(Device, stream, "base", "936013062", progress));
() => TestClient.InstallWriteAsync(Device, stream, "base", "936013062", new InstallProgress()));
}
}

Expand Down Expand Up @@ -950,6 +944,8 @@ await RunTestAsync(
[Fact]
public async Task InstallWinRTAsyncTest()
{
if (!OperatingSystem.IsWindowsVersionAtLeast(10)) { return; }

// The app data is sent in chunks of 32 kb
List<byte[]> applicationDataChunks = [];

Expand Down Expand Up @@ -999,6 +995,8 @@ await RunTestAsync(
[Fact]
public async Task InstallMultipleWinRTAsyncTest()
{
if (!OperatingSystem.IsWindowsVersionAtLeast(10)) { return; }

// The app data is sent in chunks of 32 kb
List<byte[]> applicationDataChunks = [];

Expand Down Expand Up @@ -1059,6 +1057,8 @@ await RunTestAsync(
[Fact]
public async Task InstallMultipleWinRTWithBaseAsyncTest()
{
if (!OperatingSystem.IsWindowsVersionAtLeast(10)) { return; }

// The app data is sent in chunks of 32 kb
List<byte[]> applicationDataChunks = [];

Expand Down Expand Up @@ -1136,6 +1136,8 @@ await RunTestAsync(
[Fact]
public async Task InstallWriteWinRTAsyncTest()
{
if (!OperatingSystem.IsWindowsVersionAtLeast(10)) { return; }

// The app data is sent in chunks of 32 kb
List<byte[]> applicationDataChunks = [];

Expand Down
2 changes: 2 additions & 0 deletions AdvancedSharpAdbClient.Tests/AdbClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ public void GetFrameBufferTest()
Assert.Equal(0u, header.ColorSpace);

#if WINDOWS
if (!OperatingSystem.IsWindows()) { return; }

using Bitmap image = framebuffer.ToImage();
Assert.NotNull(image);
Assert.Equal(PixelFormat.Format32bppArgb, image.PixelFormat);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<LangVersion>latest</LangVersion>
<NoWarn>CS1591</NoWarn>
<NoWarn>$(NoWarn);CS1591</NoWarn>
</PropertyGroup>

<Choose>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public async Task DumpScreenAsyncTest()
[Fact]
public async Task DumpScreenWinRTAsyncTest()
{
if (!OperatingSystem.IsWindowsVersionAtLeast(10)) { return; }

DummyAdbClient client = new();
client.Commands["shell:uiautomator dump /dev/tty"] = await File.ReadAllTextAsync(@"Assets/DumpScreen.txt");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ public void DumpScreenTest()
[Fact]
public void DumpScreenWinRTTest()
{
if (!OperatingSystem.IsWindowsVersionAtLeast(10)) { return; }

DummyAdbClient client = new();
client.Commands["shell:uiautomator dump /dev/tty"] = File.ReadAllText(@"Assets/DumpScreen.txt");

Expand Down
4 changes: 4 additions & 0 deletions AdvancedSharpAdbClient.Tests/Models/FramebufferHeaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public void ReadFramebufferV2Test()
[Fact]
public void ToImageTest()
{
if (!OperatingSystem.IsWindows()) { return; }

byte[] data = File.ReadAllBytes("Assets/FramebufferHeader.bin");
FramebufferHeader header = FramebufferHeader.Read(data);
byte[] framebuffer = File.ReadAllBytes("Assets/Framebuffer.bin");
Expand All @@ -95,6 +97,8 @@ public void ToImageTest()
[Fact]
public void ToImageEmptyTest()
{
if (!OperatingSystem.IsWindows()) { return; }

byte[] data = File.ReadAllBytes("Assets/FramebufferHeader.Empty.bin");
FramebufferHeader header = FramebufferHeader.Read(data);

Expand Down
4 changes: 4 additions & 0 deletions AdvancedSharpAdbClient.Tests/Models/FramebufferTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public void RefreshTest()
Assert.Equal(0u, header.ColorSpace);

#if WINDOWS
if (!OperatingSystem.IsWindows()) { return; }

using Bitmap image = (Bitmap)framebuffer;
Assert.NotNull(image);
Assert.Equal(PixelFormat.Format32bppArgb, image.PixelFormat);
Expand Down Expand Up @@ -131,6 +133,8 @@ public async Task RefreshAsyncTest()
Assert.Equal(0u, header.ColorSpace);

#if WINDOWS
if (!OperatingSystem.IsWindows()) { return; }

using Bitmap image = (Bitmap)framebuffer;
Assert.NotNull(image);
Assert.Equal(PixelFormat.Format32bppArgb, image.PixelFormat);
Expand Down
4 changes: 4 additions & 0 deletions AdvancedSharpAdbClient.Tests/SyncServiceTests.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ await RunTestAsync(
[Fact]
public async Task PullWinRTAsyncTest()
{
if (!OperatingSystem.IsWindowsVersionAtLeast(10)) { return; }

using InMemoryRandomAccessStream stream = new();
byte[] content = await File.ReadAllBytesAsync("Assets/Fstab.bin");
byte[] contentLength = BitConverter.GetBytes(content.Length);
Expand Down Expand Up @@ -309,6 +311,8 @@ await RunTestAsync(
[Fact]
public async Task PushWinRTAsyncTest()
{
if (!OperatingSystem.IsWindowsVersionAtLeast(10)) { return; }

StorageFile storageFile = await StorageFile.GetFileFromPathAsync(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Assets\Fstab.bin"));
using IRandomAccessStreamWithContentType stream = await storageFile.OpenReadAsync();
byte[] content = await File.ReadAllBytesAsync("Assets/Fstab.bin");
Expand Down

0 comments on commit 6b69a59

Please sign in to comment.