Skip to content

Commit

Permalink
[tests] Add TestRuntime.RunAsync.cs to the bindings-test project.
Browse files Browse the repository at this point in the history
And fix a few compiler warnings.

This is required for the newly added test.
  • Loading branch information
rolfbjarne committed May 21, 2024
1 parent 699e94b commit 6fd7705
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 5 additions & 0 deletions tests/bindings-test/dotnet/shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<!-- We're warning-free, so let's make sure we stay that way -->
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors>Nullable</WarningsAsErrors>

<DefineConstants>$(DefineConstants);BINDINGS_TEST</DefineConstants>
</PropertyGroup>

<Import Project="$(RootTestsDirectory)/common/shared-dotnet.csproj" />
Expand Down Expand Up @@ -57,6 +59,9 @@
<Compile Include="$(RootTestsDirectory)\common\TestRuntime.cs">
<Link>TestRuntime.cs</Link>
</Compile>
<Compile Include="$(RootTestsDirectory)\common\TestRuntime.RunAsync.cs">
<Link>TestRuntime.RunAsync.cs</Link>
</Compile>
<Compile Include="$(RootTestsDirectory)\..\tools\common\ApplePlatform.cs">
<Link>ApplePlatform.cs</Link>
</Compile>
Expand Down
16 changes: 11 additions & 5 deletions tests/common/TestRuntime.RunAsync.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#if !__WATCHOS__
#if !__WATCHOS__ && !BINDINGS_TEST
#define CAN_SHOW_ASYNC_UI
#endif

using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -157,8 +158,13 @@ public void Show (XImage? imageToShow)
var vc = new AsyncController (imageToShow);

#if HAS_UIKIT
window = UIApplication.SharedApplication.KeyWindow;
initialRootViewController = window.RootViewController;
// UIApplication.KeyWindow is deprecated, so we have to do this monstruosity instead (https://stackoverflow.com/a/58031897/183422):
window = UIApplication
.SharedApplication
.ConnectedScenes
.SelectMany<UIScene, UIWindow> (v => (v as UIWindowScene)?.Windows ?? Array.Empty<UIWindow> ())
.Last (v => v.IsKeyWindow);
initialRootViewController = window.RootViewController!;
navigation = initialRootViewController as UINavigationController;

// Pushing something to a navigation controller doesn't seem to work on phones
Expand Down Expand Up @@ -237,7 +243,7 @@ public override void ViewDidLoad ()
}

#if HAS_UIKIT
View.BackgroundColor = backgroundColor;
View!.BackgroundColor = backgroundColor;
#else
View.WantsLayer = true;
View.Layer.BackgroundColor = backgroundColor.CGColor;
Expand All @@ -257,7 +263,7 @@ public override void ViewDidLoad ()
}

namespace Foundation {
public static class NSRunLoop_Extensions {
static class NSRunLoop_Extensions {
// Returns true if task completed before the timeout,
// otherwise returns false
public static bool RunUntil (this NSRunLoop self, Task task, TimeSpan timeout)
Expand Down

0 comments on commit 6fd7705

Please sign in to comment.