1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-26 18:52:55 +08:00

Move AllowTrackAdjustments test to TestSceneOsuScreenStack

This commit is contained in:
AbstractQbit 2021-09-16 01:21:29 +03:00
parent 30c458c662
commit 3cd3e133ce
2 changed files with 80 additions and 56 deletions

View File

@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Database;
@ -80,57 +81,5 @@ namespace osu.Game.Tests.Visual.Menus
trackChangeQueue.Count == 1 &&
trackChangeQueue.Dequeue().changeDirection == TrackChangeDirection.Next);
}
[Test]
public void TestAllowTrackAdjustments()
{
AddStep("push allowing screen", () => Game.ScreenStack.Push(new AllowScreen()));
AddAssert("allows adjustments", () => Game.MusicController.AllowTrackAdjustments);
AddStep("push inheriting screen", () => Game.ScreenStack.Push(new InheritScreen()));
AddAssert("allows adjustments", () => Game.MusicController.AllowTrackAdjustments);
AddStep("push disallowing screen", () => Game.ScreenStack.Push(new DisallowScreen()));
AddAssert("disallows adjustments", () => !Game.MusicController.AllowTrackAdjustments);
AddStep("push inheriting screen", () => Game.ScreenStack.Push(new InheritScreen()));
AddAssert("disallows adjustments", () => !Game.MusicController.AllowTrackAdjustments);
AddStep("push inheriting screen", () => Game.ScreenStack.Push(new InheritScreen()));
AddAssert("disallows adjustments", () => !Game.MusicController.AllowTrackAdjustments);
AddStep("push allowing screen", () => Game.ScreenStack.Push(new AllowScreen()));
AddAssert("allows adjustments", () => Game.MusicController.AllowTrackAdjustments);
// Now start exiting from screens
AddStep("exit screen", () => Game.ScreenStack.Exit());
AddAssert("disallows adjustments", () => !Game.MusicController.AllowTrackAdjustments);
AddStep("exit screen", () => Game.ScreenStack.Exit());
AddAssert("disallows adjustments", () => !Game.MusicController.AllowTrackAdjustments);
AddStep("exit screen", () => Game.ScreenStack.Exit());
AddAssert("disallows adjustments", () => !Game.MusicController.AllowTrackAdjustments);
AddStep("exit screen", () => Game.ScreenStack.Exit());
AddAssert("allows adjustments", () => Game.MusicController.AllowTrackAdjustments);
AddStep("exit screen", () => Game.ScreenStack.Exit());
AddAssert("allows adjustments", () => Game.MusicController.AllowTrackAdjustments);
}
private class AllowScreen : OsuScreen
{
public override bool AllowTrackAdjustments => true;
}
private class DisallowScreen : OsuScreen
{
public override bool AllowTrackAdjustments => false;
}
private class InheritScreen : OsuScreen
{
}
}
}

View File

@ -5,8 +5,8 @@ using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Game.Graphics.Sprites;
using osu.Game.Overlays;
using osu.Game.Screens;
using osu.Game.Screens.Play;
using osuTK.Graphics;
@ -18,10 +18,20 @@ namespace osu.Game.Tests.Visual
{
private TestOsuScreenStack stack;
[SetUpSteps]
public void SetUpSteps()
[Cached]
private MusicController musicController = new MusicController();
[BackgroundDependencyLoader]
private void load()
{
AddStep("Create new screen stack", () => { Child = stack = new TestOsuScreenStack { RelativeSizeAxes = Axes.Both }; });
stack = new TestOsuScreenStack { RelativeSizeAxes = Axes.Both };
stack.ScreenPushed += screenChanged;
stack.ScreenExited += screenChanged;
Add(musicController);
Add(stack);
LoadComponent(stack);
}
[Test]
@ -42,6 +52,44 @@ namespace osu.Game.Tests.Visual
AddAssert("Parallax is off", () => stack.ParallaxAmount == 0);
}
[Test]
public void AllowTrackAdjustmentsTest()
{
AddStep("push allowing screen", () => stack.Push(loadNewScreen<AllowScreen>()));
AddAssert("allows adjustments 1", () => musicController.AllowTrackAdjustments);
AddStep("push inheriting screen", () => stack.Push(loadNewScreen<InheritScreen>()));
AddAssert("allows adjustments 2", () => musicController.AllowTrackAdjustments);
AddStep("push disallowing screen", () => stack.Push(loadNewScreen<DisallowScreen>()));
AddAssert("disallows adjustments 3", () => !musicController.AllowTrackAdjustments);
AddStep("push inheriting screen", () => stack.Push(loadNewScreen<InheritScreen>()));
AddAssert("disallows adjustments 4", () => !musicController.AllowTrackAdjustments);
AddStep("push inheriting screen", () => stack.Push(loadNewScreen<InheritScreen>()));
AddAssert("disallows adjustments 5", () => !musicController.AllowTrackAdjustments);
AddStep("push allowing screen", () => stack.Push(loadNewScreen<AllowScreen>()));
AddAssert("allows adjustments 6", () => musicController.AllowTrackAdjustments);
// Now start exiting from screens
AddStep("exit screen", () => stack.Exit());
AddAssert("disallows adjustments 7", () => !musicController.AllowTrackAdjustments);
AddStep("exit screen", () => stack.Exit());
AddAssert("disallows adjustments 8", () => !musicController.AllowTrackAdjustments);
AddStep("exit screen", () => stack.Exit());
AddAssert("disallows adjustments 9", () => !musicController.AllowTrackAdjustments);
AddStep("exit screen", () => stack.Exit());
AddAssert("allows adjustments 10", () => musicController.AllowTrackAdjustments);
AddStep("exit screen", () => stack.Exit());
AddAssert("allows adjustments 11", () => musicController.AllowTrackAdjustments);
}
public class TestScreen : ScreenWithBeatmapBackground
{
private readonly string screenText;
@ -78,5 +126,32 @@ namespace osu.Game.Tests.Visual
{
public new float ParallaxAmount => base.ParallaxAmount;
}
private class AllowScreen : OsuScreen
{
public override bool AllowTrackAdjustments => true;
}
public class DisallowScreen : OsuScreen
{
public override bool AllowTrackAdjustments => false;
}
private class InheritScreen : OsuScreen
{
}
private OsuScreen loadNewScreen<T>() where T : OsuScreen, new()
{
OsuScreen screen = new T();
LoadComponent(screen);
return screen;
}
private void screenChanged(IScreen current, IScreen newScreen)
{
if (newScreen is IOsuScreen newOsuScreen)
musicController.AllowTrackAdjustments = newOsuScreen.AllowTrackAdjustments;
}
}
}