1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 14:17:26 +08:00

Centralise screen exit logic to ScreenTestScene

This commit is contained in:
Dean Herbert 2020-01-31 13:54:26 +09:00
parent d5b9df049b
commit 5f48affcba
11 changed files with 76 additions and 47 deletions

View File

@ -2,30 +2,52 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.Linq; using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Catch;
using osu.Game.Rulesets.Mania;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Taiko;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
namespace osu.Game.Tests.Visual namespace osu.Game.Tests.Visual.Gameplay
{ {
/// <summary> /// <summary>
/// A base class which runs <see cref="Player"/> test for all available rulesets. /// A base class which runs <see cref="Player"/> test for all available rulesets.
/// Steps to be run for each ruleset should be added via <see cref="AddCheckSteps"/>. /// Steps to be run for each ruleset should be added via <see cref="AddCheckSteps"/>.
/// </summary> /// </summary>
public abstract class AllPlayersTestScene : RateAdjustedBeatmapTestScene public abstract class TestSceneAllRulesetPlayers : RateAdjustedBeatmapTestScene
{ {
protected Player Player; protected Player Player;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(RulesetStore rulesets) private void load(RulesetStore rulesets)
{ {
foreach (var r in rulesets.AvailableRulesets) OsuConfigManager manager;
Dependencies.Cache(manager = new OsuConfigManager(LocalStorage));
manager.GetBindable<double>(OsuSetting.DimLevel).Value = 1.0;
}
[Test]
public void TestOsu() => runForRuleset(new OsuRuleset().RulesetInfo);
[Test]
public void TestTaiko() => runForRuleset(new TaikoRuleset().RulesetInfo);
[Test]
public void TestCatch() => runForRuleset(new CatchRuleset().RulesetInfo);
[Test]
public void TestMania() => runForRuleset(new ManiaRuleset().RulesetInfo);
private void runForRuleset(RulesetInfo ruleset)
{ {
Player p = null; Player p = null;
AddStep(r.Name, () => p = loadPlayerFor(r)); AddStep($"load {ruleset.Name} player", () => p = loadPlayerFor(ruleset));
AddUntilStep("player loaded", () => AddUntilStep("player loaded", () =>
{ {
if (p?.IsLoaded == true) if (p?.IsLoaded == true)
@ -40,11 +62,6 @@ namespace osu.Game.Tests.Visual
AddCheckSteps(); AddCheckSteps();
} }
OsuConfigManager manager;
Dependencies.Cache(manager = new OsuConfigManager(LocalStorage));
manager.GetBindable<double>(OsuSetting.DimLevel).Value = 1.0;
}
protected abstract void AddCheckSteps(); protected abstract void AddCheckSteps();
private Player loadPlayerFor(RulesetInfo rulesetInfo) private Player loadPlayerFor(RulesetInfo rulesetInfo)

View File

@ -12,7 +12,7 @@ using osu.Game.Storyboards;
namespace osu.Game.Tests.Visual.Gameplay namespace osu.Game.Tests.Visual.Gameplay
{ {
[Description("Player instantiated with an autoplay mod.")] [Description("Player instantiated with an autoplay mod.")]
public class TestSceneAutoplay : AllPlayersTestScene public class TestSceneAutoplay : TestSceneAllRulesetPlayers
{ {
private ClockBackedTestWorkingBeatmap.TrackVirtualManual track; private ClockBackedTestWorkingBeatmap.TrackVirtualManual track;

View File

@ -10,7 +10,7 @@ using osu.Game.Screens.Play;
namespace osu.Game.Tests.Visual.Gameplay namespace osu.Game.Tests.Visual.Gameplay
{ {
public class TestSceneFailAnimation : AllPlayersTestScene public class TestSceneFailAnimation : TestSceneAllRulesetPlayers
{ {
protected override Player CreatePlayer(Ruleset ruleset) protected override Player CreatePlayer(Ruleset ruleset)
{ {
@ -20,7 +20,7 @@ namespace osu.Game.Tests.Visual.Gameplay
public override IReadOnlyList<Type> RequiredTypes => new[] public override IReadOnlyList<Type> RequiredTypes => new[]
{ {
typeof(AllPlayersTestScene), typeof(TestSceneAllRulesetPlayers),
typeof(TestPlayer), typeof(TestPlayer),
typeof(Player), typeof(Player),
}; };

View File

@ -10,7 +10,7 @@ using osu.Game.Screens.Play;
namespace osu.Game.Tests.Visual.Gameplay namespace osu.Game.Tests.Visual.Gameplay
{ {
public class TestSceneFailJudgement : AllPlayersTestScene public class TestSceneFailJudgement : TestSceneAllRulesetPlayers
{ {
protected override Player CreatePlayer(Ruleset ruleset) protected override Player CreatePlayer(Ruleset ruleset)
{ {

View File

@ -36,6 +36,7 @@ namespace osu.Game.Tests.Visual.Gameplay
public override void SetUpSteps() public override void SetUpSteps()
{ {
base.SetUpSteps(); base.SetUpSteps();
AddStep("resume player", () => Player.GameplayClockContainer.Start()); AddStep("resume player", () => Player.GameplayClockContainer.Start());
confirmClockRunning(true); confirmClockRunning(true);
} }

View File

@ -10,7 +10,7 @@ using osu.Game.Storyboards;
namespace osu.Game.Tests.Visual.Gameplay namespace osu.Game.Tests.Visual.Gameplay
{ {
public class TestScenePlayerReferenceLeaking : AllPlayersTestScene public class TestScenePlayerReferenceLeaking : TestSceneAllRulesetPlayers
{ {
private readonly WeakList<WorkingBeatmap> workingWeakReferences = new WeakList<WorkingBeatmap>(); private readonly WeakList<WorkingBeatmap> workingWeakReferences = new WeakList<WorkingBeatmap>();

View File

@ -13,7 +13,7 @@ using osu.Game.Screens.Play;
namespace osu.Game.Tests.Visual.Gameplay namespace osu.Game.Tests.Visual.Gameplay
{ {
[Description("Player instantiated with a replay.")] [Description("Player instantiated with a replay.")]
public class TestSceneReplay : AllPlayersTestScene public class TestSceneReplay : TestSceneAllRulesetPlayers
{ {
protected override Player CreatePlayer(Ruleset ruleset) protected override Player CreatePlayer(Ruleset ruleset)
{ {

View File

@ -79,12 +79,17 @@ namespace osu.Game.Tests.Visual.SongSelect
private OsuConfigManager config; private OsuConfigManager config;
[SetUp] [SetUpSteps]
public virtual void SetUp() => Schedule(() => public override void SetUpSteps()
{
base.SetUpSteps();
AddStep("delete all beatmaps", () =>
{ {
Ruleset.Value = new OsuRuleset().RulesetInfo; Ruleset.Value = new OsuRuleset().RulesetInfo;
manager?.Delete(manager.GetAllUsableBeatmapSets()); manager?.Delete(manager.GetAllUsableBeatmapSets());
}); });
}
[Test] [Test]
public void TestSingleFilterOnEnter() public void TestSingleFilterOnEnter()
@ -120,9 +125,6 @@ namespace osu.Game.Tests.Visual.SongSelect
AddUntilStep("wait for not current", () => !songSelect.IsCurrentScreen()); AddUntilStep("wait for not current", () => !songSelect.IsCurrentScreen());
AddAssert("ensure selection changed", () => selected != Beatmap.Value); AddAssert("ensure selection changed", () => selected != Beatmap.Value);
AddUntilStep("wait for return to song select", () => songSelect.IsCurrentScreen());
AddUntilStep("bindable lease returned", () => !Beatmap.Disabled);
} }
[Test] [Test]
@ -148,9 +150,6 @@ namespace osu.Game.Tests.Visual.SongSelect
AddUntilStep("wait for not current", () => !songSelect.IsCurrentScreen()); AddUntilStep("wait for not current", () => !songSelect.IsCurrentScreen());
AddAssert("ensure selection didn't change", () => selected == Beatmap.Value); AddAssert("ensure selection didn't change", () => selected == Beatmap.Value);
AddUntilStep("wait for return to song select", () => songSelect.IsCurrentScreen());
AddUntilStep("bindable lease returned", () => !Beatmap.Disabled);
} }
[Test] [Test]
@ -180,9 +179,6 @@ namespace osu.Game.Tests.Visual.SongSelect
AddUntilStep("wait for not current", () => !songSelect.IsCurrentScreen()); AddUntilStep("wait for not current", () => !songSelect.IsCurrentScreen());
AddAssert("ensure selection changed", () => selected != Beatmap.Value); AddAssert("ensure selection changed", () => selected != Beatmap.Value);
AddUntilStep("wait for return to song select", () => songSelect.IsCurrentScreen());
AddUntilStep("bindable lease returned", () => !Beatmap.Disabled);
} }
[Test] [Test]
@ -213,9 +209,6 @@ namespace osu.Game.Tests.Visual.SongSelect
AddUntilStep("wait for not current", () => !songSelect.IsCurrentScreen()); AddUntilStep("wait for not current", () => !songSelect.IsCurrentScreen());
AddAssert("ensure selection didn't change", () => selected == Beatmap.Value); AddAssert("ensure selection didn't change", () => selected == Beatmap.Value);
AddUntilStep("wait for return to song select", () => songSelect.IsCurrentScreen());
AddUntilStep("bindable lease returned", () => !Beatmap.Disabled);
} }
[Test] [Test]

View File

@ -39,6 +39,8 @@ namespace osu.Game.Screens.Play
public override float BackgroundParallaxAmount => 0.1f; public override float BackgroundParallaxAmount => 0.1f;
public override bool DisallowExternalBeatmapRulesetChanges => true;
public override bool HideOverlaysOnEnter => true; public override bool HideOverlaysOnEnter => true;
public override OverlayActivation InitialOverlayActivationMode => OverlayActivation.UserTriggered; public override OverlayActivation InitialOverlayActivationMode => OverlayActivation.UserTriggered;

View File

@ -33,8 +33,10 @@ namespace osu.Game.Tests.Visual
} }
[SetUpSteps] [SetUpSteps]
public virtual void SetUpSteps() public override void SetUpSteps()
{ {
base.SetUpSteps();
AddStep(ruleset.RulesetInfo.Name, loadPlayer); AddStep(ruleset.RulesetInfo.Name, loadPlayer);
AddUntilStep("player loaded", () => Player.IsLoaded && Player.Alpha == 1); AddUntilStep("player loaded", () => Player.IsLoaded && Player.Alpha == 1);
} }

View File

@ -3,6 +3,7 @@
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Game.Screens; using osu.Game.Screens;
namespace osu.Game.Tests.Visual namespace osu.Game.Tests.Visual
@ -27,11 +28,24 @@ namespace osu.Game.Tests.Visual
}); });
} }
protected void LoadScreen(OsuScreen screen) protected void LoadScreen(OsuScreen screen) => Stack.Push(screen);
[SetUpSteps]
public virtual void SetUpSteps() => addExitAllScreensStep();
// pending framework update.
//[TearDownSteps]
//public void TearDownSteps() => addExitAllScreensStep();
private void addExitAllScreensStep()
{ {
if (Stack.CurrentScreen != null) AddUntilStep("exit all screens", () =>
{
if (Stack.CurrentScreen == null) return true;
Stack.Exit(); Stack.Exit();
Stack.Push(screen); return false;
});
} }
} }
} }