Exemplo n.º 1
0
        public void TestExitLoop()
        {
            //////////////////////////////////////////////////////////////////////////////////
            // 1. Check that ExitLoop an Disposed instance throw the 'ObjectDisposedException'
            var dispInst = SoundMusic.Load(defaultEngine, OpenDataBaseStream("EffectToneA"));

            dispInst.Dispose();
            Assert.Throws <ObjectDisposedException>(dispInst.ExitLoop, "SoundMusic.ExitLoop did not throw the 'ObjectDisposedException' when called from a disposed object.");

            //////////////////////////////////////////////////////////////////////////////
            // 2. Check that ExitLoop does not crash when the sound is not started/stopped
            Assert.DoesNotThrow(monoInstance.ExitLoop, "Call to SoundMusic.ExitLoop crashed throwing an exception with a stopped sound.");

            /////////////////////////////////////////////////////////////////////////////////////////////////////
            // 3. Check that ExitLoop does not crash and has the correct effect when called during looped playing
            var loopedInst = SoundMusic.Load(defaultEngine, OpenDataBaseStream("EffectBip"));

            loopedInst.IsLooped = true;
            loopedInst.Play();
            ActiveAudioEngineUpdate(1000); // Play need to be commited
            Assert.DoesNotThrow(loopedInst.ExitLoop, "Call to SoundMusic.ExitLoop crashed throwing an exception.");
            ActiveAudioEngineUpdate(1500);
            Assert.AreEqual(SoundPlayState.Stopped, loopedInst.PlayState, "SoundMusic.ExitLoop has not properly stopped the looping proccess");

            ////////////////////////////////////////////////////////////////////////////////
            // 4. Check that a call to ExitLoop does not crash when the sound is not looping
            monoInstance.Play();
            ActiveAudioEngineUpdate(100); // Play need to be commited
            Assert.DoesNotThrow(monoInstance.ExitLoop, "Call to SoundMusic.ExitLoop with a non-looping sound crashed throwing an exception.");
            ActiveAudioEngineUpdate(1250);

            ////////////////////////////////////////////////////////////////
            // 5. Check that 2 consecutive calls to ExitLoop does not crash
            loopedInst.Play();
            ActiveAudioEngineUpdate(100); // Play need to be commited
            loopedInst.ExitLoop();
            Assert.DoesNotThrow(loopedInst.ExitLoop, "A consecutive second call to SoundEffectInstance.ExitLoop crashed throwing an exception.");
            ActiveAudioEngineUpdate(1500);

            ////////////////////////////////////////////////////////////////
            // 6. Check that ExitLoop does not modify the value of IsLooped
            Assert.AreEqual(true, loopedInst.IsLooped, "SoundMusic.ExitLoop modified the value of IsLooped.");

            ///////////////////////////////////////////////////////////////////////////////////////////
            // 7. Check that a call to ExitLoop from another instance do not affect current instance.
            loopedInst.Play();
            ActiveAudioEngineUpdate(100); // Play need to be commited
            monoInstance.ExitLoop();
            ActiveAudioEngineUpdate(2000);
            Assert.AreEqual(SoundPlayState.Playing, loopedInst.PlayState, "Call to ExitLoop from another instance influenced current playing instance.");
            loopedInst.ExitLoop();
            ActiveAudioEngineUpdate(1500);
        }