Skip to content

Commit

Permalink
Handle disposal in TestDoesNotRestart and add TestChannelLifetime
Browse files Browse the repository at this point in the history
  • Loading branch information
hwsmm committed Nov 29, 2024
1 parent 34f3edf commit e4af349
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion osu.Framework.Tests/Visual/Audio/TestSceneSampleChannels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ public void TestDoesNotRestart()

AddStep("play channel 1 sample", () => channel = sample.Play());
AddUntilStep("wait for channel 1 to end", () => !channel.Playing);
AddStep("play channel 1 again", () => channel.Play());
AddStep("play channel 1 again", () =>
{
try
{
channel.Play();
}
catch (ObjectDisposedException)
{
}
});

int audioFrames = 0;
AddStep("begin tracking audio frames", () =>
Expand All @@ -61,6 +70,32 @@ public void TestDoesNotRestart()
AddAssert("channel 1 not playing", () => !channel.Playing);
}

[Test]
public void TestChannelLifetime()
{
SampleChannel channel = null;

AddStep("play channel 1 sample", () => channel = sample.Play());
AddUntilStep("wait for channel 1 to end", () => !channel.Playing);

int audioFrames = 0;
AddStep("begin tracking audio frames", () =>
{
audioFrames = 0;
ScheduledDelegate del = null;
del = host.AudioThread.Scheduler.AddDelayed(() =>
{
// ReSharper disable once AccessToModifiedClosure
if (++audioFrames >= 2)
del?.Cancel();
}, 0, true);
});

AddUntilStep("wait for two audio frames", () => audioFrames >= 2);
AddAssert("channel 1 disposed", () => channel.IsDisposed);
}

[Test]
public void TestPlayLoopingSample()
{
Expand Down

0 comments on commit e4af349

Please sign in to comment.