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

[monotouch-test] Use TestRuntime.RunAsync instead of AppDelegate.RunAsync so that the system sound tests work on macOS as well. #11770

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
12 changes: 8 additions & 4 deletions src/AudioToolbox/SystemSound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class SystemSound : INativeObject, IDisposable {

Action completionRoutine;
GCHandle gc_handle;
static readonly Action<SystemSoundId, IntPtr> SoundCompletionCallback = SoundCompletionShared;
static readonly AddSystemSoundCompletionCallback SoundCompletionCallback = SoundCompletionShared;

internal SystemSound (uint soundId, bool ownsHandle)
{
Expand Down Expand Up @@ -180,9 +180,11 @@ public void PlaySystemSound ()
AudioServicesPlaySystemSound (soundId);
}

static unsafe readonly Action<IntPtr> static_action = TrampolineAction;
delegate void TrampolineCallback (IntPtr blockPtr);

[MonoPInvokeCallback (typeof (Action<IntPtr>))]
static unsafe readonly TrampolineCallback static_action = TrampolineAction;

[MonoPInvokeCallback (typeof (TrampolineCallback))]
static unsafe void TrampolineAction (IntPtr blockPtr)
{
var block = (BlockLiteral *) blockPtr;
Expand Down Expand Up @@ -295,8 +297,10 @@ public static SystemSound FromFile (string filename)
}
}

delegate void AddSystemSoundCompletionCallback (SystemSoundId id, IntPtr clientData);

[DllImport (Constants.AudioToolboxLibrary)]
static extern AudioServicesError AudioServicesAddSystemSoundCompletion (uint soundId, IntPtr runLoop, IntPtr runLoopMode, Action<SystemSoundId, IntPtr> completionRoutine, IntPtr clientData);
static extern AudioServicesError AudioServicesAddSystemSoundCompletion (uint soundId, IntPtr runLoop, IntPtr runLoopMode, AddSystemSoundCompletionCallback completionRoutine, IntPtr clientData);

[MonoPInvokeCallback (typeof (Action<SystemSoundId, IntPtr>))]
static void SoundCompletionShared (SystemSoundId id, IntPtr clientData)
Expand Down
10 changes: 3 additions & 7 deletions tests/monotouch-test/AudioToolbox/SystemSoundTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ namespace MonoTouchFixtures.AudioToolbox {
[Preserve (AllMembers = true)]
public class SystemSoundTest
{
#if !MONOMAC // Currently no AppDelegate in xammac_test
[Test]
public void FromFile ()
{
Expand All @@ -43,10 +42,9 @@ public void FromFile ()
}));

ss.PlaySystemSound ();
Assert.IsTrue (MonoTouchFixtures.AppDelegate.RunAsync (DateTime.Now.AddSeconds (timeout), async () => { }, () => completed), "PlaySystemSound");
Assert.IsTrue (TestRuntime.RunAsync (DateTime.Now.AddSeconds (timeout), async () => { }, () => completed), "PlaySystemSound");
}
}
#endif

[Test]
public void Properties ()
Expand All @@ -59,7 +57,6 @@ public void Properties ()
}
}

#if !MONOMAC // Currently no AppDelegate in xammac_test
[Test]
public void TestCallbackPlaySystem ()
{
Expand All @@ -73,7 +70,7 @@ public void TestCallbackPlaySystem ()
const int timeout = 10;

completed = false;
Assert.IsTrue (MonoTouchFixtures.AppDelegate.RunAsync (DateTime.Now.AddSeconds (timeout), async () =>
Assert.IsTrue (TestRuntime.RunAsync (DateTime.Now.AddSeconds (timeout), async () =>
ss.PlaySystemSound (() => { completed = true; }
), () => completed), "TestCallbackPlaySystem");
}
Expand All @@ -92,12 +89,11 @@ public void TestCallbackPlayAlert ()
const int timeout = 10;

completed = false;
Assert.IsTrue (MonoTouchFixtures.AppDelegate.RunAsync (DateTime.Now.AddSeconds (timeout), async () =>
Assert.IsTrue (TestRuntime.RunAsync (DateTime.Now.AddSeconds (timeout), async () =>
ss.PlayAlertSound (() => { completed = true; }
), () => completed), "TestCallbackPlayAlert");
}
}
#endif

[Test]
public void DisposeTest ()
Expand Down