From 6b69a59e421b969d026940880a812cc759e57525 Mon Sep 17 00:00:00 2001 From: wherewhere Date: Wed, 5 Jun 2024 19:11:20 +0800 Subject: [PATCH] Add platform check on test --- .../AdbClientTests.Async.cs | 20 ++++++++++--------- .../AdbClientTests.cs | 2 ++ .../AdvancedSharpAdbClient.Tests.csproj | 2 +- .../DeviceCommands/DeviceClientTexts.Async.cs | 2 ++ .../DeviceCommands/DeviceClientTexts.cs | 2 ++ .../Models/FramebufferHeaderTests.cs | 4 ++++ .../Models/FramebufferTests.cs | 4 ++++ .../SyncServiceTests.Async.cs | 4 ++++ 8 files changed, 30 insertions(+), 10 deletions(-) diff --git a/AdvancedSharpAdbClient.Tests/AdbClientTests.Async.cs b/AdvancedSharpAdbClient.Tests/AdbClientTests.Async.cs index 667fada..01d5065 100644 --- a/AdvancedSharpAdbClient.Tests/AdbClientTests.Async.cs +++ b/AdvancedSharpAdbClient.Tests/AdbClientTests.Async.cs @@ -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); @@ -900,14 +902,6 @@ public async Task InstallWriteAsyncTest() byte[] response = AdbClient.Encoding.GetBytes($"Success: streamed {stream.Length} bytes\n"); - double temp = 0; - Progress progress = new(); - progress.ProgressChanged += (sender, args) => - { - Assert.True(temp <= args, $"{nameof(args)}: {args} is less than {temp}."); - temp = args; - }; - await RunTestAsync( OkResponses(2), NoResponseMessages, @@ -916,7 +910,7 @@ await RunTestAsync( NoSyncResponses, [response], applicationDataChunks, - () => TestClient.InstallWriteAsync(Device, stream, "base", "936013062", progress)); + () => TestClient.InstallWriteAsync(Device, stream, "base", "936013062", new InstallProgress())); } } @@ -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 applicationDataChunks = []; @@ -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 applicationDataChunks = []; @@ -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 applicationDataChunks = []; @@ -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 applicationDataChunks = []; diff --git a/AdvancedSharpAdbClient.Tests/AdbClientTests.cs b/AdvancedSharpAdbClient.Tests/AdbClientTests.cs index 61942a2..b8401f5 100644 --- a/AdvancedSharpAdbClient.Tests/AdbClientTests.cs +++ b/AdvancedSharpAdbClient.Tests/AdbClientTests.cs @@ -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); diff --git a/AdvancedSharpAdbClient.Tests/AdvancedSharpAdbClient.Tests.csproj b/AdvancedSharpAdbClient.Tests/AdvancedSharpAdbClient.Tests.csproj index 854b146..15be074 100644 --- a/AdvancedSharpAdbClient.Tests/AdvancedSharpAdbClient.Tests.csproj +++ b/AdvancedSharpAdbClient.Tests/AdvancedSharpAdbClient.Tests.csproj @@ -2,7 +2,7 @@ latest - CS1591 + $(NoWarn);CS1591 diff --git a/AdvancedSharpAdbClient.Tests/DeviceCommands/DeviceClientTexts.Async.cs b/AdvancedSharpAdbClient.Tests/DeviceCommands/DeviceClientTexts.Async.cs index 931e43b..1685a27 100644 --- a/AdvancedSharpAdbClient.Tests/DeviceCommands/DeviceClientTexts.Async.cs +++ b/AdvancedSharpAdbClient.Tests/DeviceCommands/DeviceClientTexts.Async.cs @@ -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"); diff --git a/AdvancedSharpAdbClient.Tests/DeviceCommands/DeviceClientTexts.cs b/AdvancedSharpAdbClient.Tests/DeviceCommands/DeviceClientTexts.cs index 96e7f11..953ae08 100644 --- a/AdvancedSharpAdbClient.Tests/DeviceCommands/DeviceClientTexts.cs +++ b/AdvancedSharpAdbClient.Tests/DeviceCommands/DeviceClientTexts.cs @@ -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"); diff --git a/AdvancedSharpAdbClient.Tests/Models/FramebufferHeaderTests.cs b/AdvancedSharpAdbClient.Tests/Models/FramebufferHeaderTests.cs index 10a0dfb..e6fb001 100644 --- a/AdvancedSharpAdbClient.Tests/Models/FramebufferHeaderTests.cs +++ b/AdvancedSharpAdbClient.Tests/Models/FramebufferHeaderTests.cs @@ -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"); @@ -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); diff --git a/AdvancedSharpAdbClient.Tests/Models/FramebufferTests.cs b/AdvancedSharpAdbClient.Tests/Models/FramebufferTests.cs index f6e07c9..93d453a 100644 --- a/AdvancedSharpAdbClient.Tests/Models/FramebufferTests.cs +++ b/AdvancedSharpAdbClient.Tests/Models/FramebufferTests.cs @@ -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); @@ -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); diff --git a/AdvancedSharpAdbClient.Tests/SyncServiceTests.Async.cs b/AdvancedSharpAdbClient.Tests/SyncServiceTests.Async.cs index 7693ef0..b92b5a4 100644 --- a/AdvancedSharpAdbClient.Tests/SyncServiceTests.Async.cs +++ b/AdvancedSharpAdbClient.Tests/SyncServiceTests.Async.cs @@ -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); @@ -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");