Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests] Add check for bluetooth permission #6796

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/common/TestRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#if XAMCORE_2_0
using AVFoundation;
using CoreBluetooth;
using Foundation;
#if !__TVOS__
using Contacts;
Expand Down Expand Up @@ -646,6 +647,23 @@ public static bool IgnoreTestThatRequiresSystemPermissions ()
return !string.IsNullOrEmpty (Environment.GetEnvironmentVariable ("DISABLE_SYSTEM_PERMISSION_TESTS"));
}

public static void CheckBluetoothPermission (bool assert_granted = false)
{
// New in Xcode11
var centralManager = new CBCentralManager ();
switch (centralManager.Authorization) {
case CBManagerAuthorization.NotDetermined:
if (IgnoreTestThatRequiresSystemPermissions ())
NUnit.Framework.Assert.Ignore ("This test would show a dialog to ask for permission to use bluetooth.");
break;
case CBManagerAuthorization.Denied:
case CBManagerAuthorization.Restricted:
if (assert_granted)
NUnit.Framework.Assert.Fail ("This test requires permission to use bluetooth.");
break;
}
}

#if !MONOMAC && !__TVOS__ && !__WATCHOS__
public static void RequestCameraPermission (NSString mediaTypeToken, bool assert_granted = false)
{
Expand Down
3 changes: 3 additions & 0 deletions tests/monotouch-test/CoreBluetooth/CentralManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public override void DisconnectedPeripheral (CBCentralManager central, CBPeriphe
[SetUp]
public void SetUp ()
{
// iOS 13 and friends require bluetooth permission
if (TestRuntime.CheckXcodeVersion (11, 0))
TestRuntime.CheckBluetoothPermission ();
// Required API is available in macOS 10.8, but it doesn't work (hangs in 10.8-10.9, randomly crashes in 10.10) on the bots.
TestRuntime.AssertSystemVersion (PlatformName.MacOSX, 10, 11, throwIfOtherPlatform: false);
var e = new AutoResetEvent (false);
Expand Down