A game framework written with osu! in mind.
at master 67 lines 2.2 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using System; 5using NUnit.Framework; 6 7namespace osu.Framework.Tests.Audio 8{ 9 /// <remarks> 10 /// This unit will ALWAYS SKIP if the system does not have a physical audio device!!! 11 /// A physical audio device is required to simulate the "loss" of it during playback. 12 /// </remarks> 13 [TestFixture] 14 public class DeviceLosingAudioTest : AudioThreadTest 15 { 16 public override void SetUp() 17 { 18 base.SetUp(); 19 20 // wait for any device to be initialized 21 Manager.WaitForDeviceChange(-1); 22 23 // if the initialized device is "No sound", it indicates that no other physical devices are available, so this unit should be ignored 24 if (Manager.CurrentDevice == 0) 25 Assert.Ignore("Physical audio devices are required for this unit."); 26 27 // we don't want music playing in unit tests :) 28 Manager.Volume.Value = 0; 29 } 30 31 [Test] 32 public void TestPlaybackWithDeviceLoss() => testPlayback(Manager.SimulateDeviceRestore, Manager.SimulateDeviceLoss); 33 34 [Test] 35 public void TestPlaybackWithDeviceRestore() => testPlayback(Manager.SimulateDeviceLoss, Manager.SimulateDeviceRestore); 36 37 private void testPlayback(Action preparation, Action simulate) 38 { 39 preparation(); 40 41 var track = Manager.Tracks.Get("Tracks.sample-track.mp3"); 42 43 // start track 44 track.Restart(); 45 46 WaitForOrAssert(() => track.IsRunning, "Track did not start running"); 47 48 WaitForOrAssert(() => track.CurrentTime > 0, "Track did not start running"); 49 50 // simulate change (loss/restore) 51 simulate(); 52 53 CheckTrackIsProgressing(track); 54 55 // stop track 56 track.Stop(); 57 58 WaitForOrAssert(() => !track.IsRunning, "Track did not stop", 1000); 59 60 // seek track 61 track.Seek(0); 62 63 Assert.IsFalse(track.IsRunning); 64 WaitForOrAssert(() => track.CurrentTime == 0, "Track did not seek correctly", 1000); 65 } 66 } 67}