A game framework written with osu! in mind.
at master 75 lines 2.6 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 NUnit.Framework; 5using osu.Framework.Allocation; 6using osu.Framework.Audio; 7using osu.Framework.Audio.Track; 8using osu.Framework.Bindables; 9using osu.Framework.Graphics; 10using osu.Framework.Graphics.Audio; 11using osu.Framework.Graphics.Containers; 12using osu.Framework.Testing; 13using osu.Framework.Tests.Visual; 14using osu.Framework.Utils; 15 16namespace osu.Framework.Tests.Audio 17{ 18 [HeadlessTest] 19 public class TestSceneDrawableTrack : FrameworkTestScene 20 { 21 [Resolved] 22 private ITrackStore trackStore { get; set; } 23 24 private DrawableTrack track; 25 26 [SetUp] 27 public void Setup() => Schedule(() => 28 { 29 Child = track = new DrawableTrack(trackStore.Get("sample-track")); 30 }); 31 32 [Test] 33 public void TestVolumeResetWhenReset() 34 { 35 AddStep("set volume to 0", () => track.Volume.Value = 0); 36 AddAssert("track volume is 0", () => Precision.AlmostEquals(0, track.AggregateVolume.Value)); 37 38 AddStep("reset", () => track.Reset()); 39 AddAssert("track volume is 1", () => Precision.AlmostEquals(1, track.AggregateVolume.Value)); 40 } 41 42 [Test] 43 public void TestAdjustmentsRemovedWhenReset() 44 { 45 // ReSharper disable once NotAccessedVariable 46 // Bindable - need to store the reference. 47 BindableDouble volumeAdjustment = null; 48 49 AddStep("add adjustment", () => track.AddAdjustment(AdjustableProperty.Volume, volumeAdjustment = new BindableDouble { Value = 0.5 })); 50 AddAssert("track volume is 0.5", () => Precision.AlmostEquals(0.5, track.AggregateVolume.Value)); 51 52 AddStep("reset", () => track.Reset()); 53 AddAssert("track volume is 1", () => Precision.AlmostEquals(1, track.Volume.Value)); 54 } 55 56 [Test] 57 public void TestTrackingParentAdjustmentChangedWhenMovedParents() 58 { 59 AddStep("set volume 1", () => track.Volume.Value = 1); 60 61 AddStep("move track a container with 0 volume", () => 62 { 63 Remove(track); 64 Child = new AudioContainer 65 { 66 RelativeSizeAxes = Axes.Both, 67 Volume = { Value = 0 }, 68 Child = track 69 }; 70 }); 71 72 AddAssert("track has 0 volume", () => track.AggregateVolume.Value == 0); 73 } 74 } 75}