mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 11:20:04 +08:00
Add test coverage
This commit is contained in:
parent
c308eb75d9
commit
b28a0d5cd5
@ -49,7 +49,7 @@ namespace osu.Game.Tests.Visual.Navigation
|
||||
}
|
||||
|
||||
[SetUpSteps]
|
||||
public void SetUpSteps()
|
||||
public virtual void SetUpSteps()
|
||||
{
|
||||
AddStep("Create new game instance", () =>
|
||||
{
|
||||
|
@ -2,23 +2,33 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Screens;
|
||||
using osu.Game.Screens.Menu;
|
||||
using osu.Game.Screens.Play;
|
||||
using osu.Game.Screens.Select;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Navigation
|
||||
{
|
||||
public class TestScenePerformFromScreen : OsuGameTestScene
|
||||
{
|
||||
private bool actionPerformed;
|
||||
|
||||
public override void SetUpSteps()
|
||||
{
|
||||
AddStep("reset status", () => actionPerformed = false);
|
||||
|
||||
base.SetUpSteps();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPerformAtMenu()
|
||||
{
|
||||
AddAssert("could perform immediately", () =>
|
||||
{
|
||||
bool actionPerformed = false;
|
||||
Game.PerformFromScreen(_ => actionPerformed = true);
|
||||
return actionPerformed;
|
||||
});
|
||||
AddStep("perform immediately", () => Game.PerformFromScreen(_ => actionPerformed = true));
|
||||
AddAssert("did perform", () => actionPerformed);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -26,12 +36,9 @@ namespace osu.Game.Tests.Visual.Navigation
|
||||
{
|
||||
PushAndConfirm(() => new PlaySongSelect());
|
||||
|
||||
AddAssert("could perform immediately", () =>
|
||||
{
|
||||
bool actionPerformed = false;
|
||||
Game.PerformFromScreen(_ => actionPerformed = true, new[] { typeof(PlaySongSelect) });
|
||||
return actionPerformed;
|
||||
});
|
||||
AddStep("perform immediately", () => Game.PerformFromScreen(_ => actionPerformed = true, new[] { typeof(PlaySongSelect) }));
|
||||
AddAssert("did perform", () => actionPerformed);
|
||||
AddAssert("screen didn't change", () => Game.ScreenStack.CurrentScreen is PlaySongSelect);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -39,7 +46,6 @@ namespace osu.Game.Tests.Visual.Navigation
|
||||
{
|
||||
PushAndConfirm(() => new PlaySongSelect());
|
||||
|
||||
bool actionPerformed = false;
|
||||
AddStep("try to perform", () => Game.PerformFromScreen(_ => actionPerformed = true));
|
||||
AddUntilStep("returned to menu", () => Game.ScreenStack.CurrentScreen is MainMenu);
|
||||
AddAssert("did perform", () => actionPerformed);
|
||||
@ -51,7 +57,6 @@ namespace osu.Game.Tests.Visual.Navigation
|
||||
PushAndConfirm(() => new PlaySongSelect());
|
||||
PushAndConfirm(() => new PlayerLoader(() => new Player()));
|
||||
|
||||
bool actionPerformed = false;
|
||||
AddStep("try to perform", () => Game.PerformFromScreen(_ => actionPerformed = true, new[] { typeof(PlaySongSelect) }));
|
||||
AddUntilStep("returned to song select", () => Game.ScreenStack.CurrentScreen is PlaySongSelect);
|
||||
AddAssert("did perform", () => actionPerformed);
|
||||
@ -63,10 +68,105 @@ namespace osu.Game.Tests.Visual.Navigation
|
||||
PushAndConfirm(() => new PlaySongSelect());
|
||||
PushAndConfirm(() => new PlayerLoader(() => new Player()));
|
||||
|
||||
bool actionPerformed = false;
|
||||
AddStep("try to perform", () => Game.PerformFromScreen(_ => actionPerformed = true));
|
||||
AddUntilStep("returned to song select", () => Game.ScreenStack.CurrentScreen is MainMenu);
|
||||
AddAssert("did perform", () => actionPerformed);
|
||||
}
|
||||
|
||||
[TestCase(true)]
|
||||
[TestCase(false)]
|
||||
public void TestPerformBlockedByDialog(bool confirmed)
|
||||
{
|
||||
DialogBlockingScreen blocker = null;
|
||||
|
||||
PushAndConfirm(() => blocker = new DialogBlockingScreen());
|
||||
AddStep("try to perform", () => Game.PerformFromScreen(_ => actionPerformed = true));
|
||||
|
||||
AddWaitStep("wait a bit", 10);
|
||||
|
||||
AddAssert("screen didn't change", () => Game.ScreenStack.CurrentScreen is DialogBlockingScreen);
|
||||
AddAssert("did not perform", () => !actionPerformed);
|
||||
AddAssert("only one exit attempt", () => blocker.ExitAttempts == 1);
|
||||
|
||||
AddUntilStep("wait for dialog display", () => Game.Dependencies.Get<DialogOverlay>().IsLoaded);
|
||||
|
||||
if (confirmed)
|
||||
{
|
||||
AddStep("accept dialog", () => InputManager.Key(Key.Number1));
|
||||
AddUntilStep("wait for dialog dismissed", () => Game.Dependencies.Get<DialogOverlay>().CurrentDialog == null);
|
||||
AddUntilStep("did perform", () => actionPerformed);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddStep("cancel dialog", () => InputManager.Key(Key.Number2));
|
||||
AddAssert("screen didn't change", () => Game.ScreenStack.CurrentScreen is DialogBlockingScreen);
|
||||
AddAssert("did not perform", () => !actionPerformed);
|
||||
}
|
||||
}
|
||||
|
||||
[TestCase(true)]
|
||||
[TestCase(false)]
|
||||
public void TestPerformBlockedByDialogNested(bool confirmSecond)
|
||||
{
|
||||
DialogBlockingScreen blocker = null;
|
||||
DialogBlockingScreen blocker2 = null;
|
||||
|
||||
PushAndConfirm(() => blocker = new DialogBlockingScreen());
|
||||
PushAndConfirm(() => blocker2 = new DialogBlockingScreen());
|
||||
|
||||
AddStep("try to perform", () => Game.PerformFromScreen(_ => actionPerformed = true));
|
||||
|
||||
AddUntilStep("wait for dialog", () => blocker2.ExitAttempts == 1);
|
||||
|
||||
AddWaitStep("wait a bit", 10);
|
||||
|
||||
AddUntilStep("wait for dialog display", () => Game.Dependencies.Get<DialogOverlay>().IsLoaded);
|
||||
|
||||
AddAssert("screen didn't change", () => Game.ScreenStack.CurrentScreen == blocker2);
|
||||
AddAssert("did not perform", () => !actionPerformed);
|
||||
AddAssert("only one exit attempt", () => blocker2.ExitAttempts == 1);
|
||||
|
||||
AddStep("accept dialog", () => InputManager.Key(Key.Number1));
|
||||
AddUntilStep("screen changed", () => Game.ScreenStack.CurrentScreen == blocker);
|
||||
|
||||
AddUntilStep("wait for second dialog", () => blocker.ExitAttempts == 1);
|
||||
AddAssert("did not perform", () => !actionPerformed);
|
||||
AddAssert("only one exit attempt", () => blocker.ExitAttempts == 1);
|
||||
|
||||
if (confirmSecond)
|
||||
{
|
||||
AddStep("accept dialog", () => InputManager.Key(Key.Number1));
|
||||
AddUntilStep("did perform", () => actionPerformed);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddStep("cancel dialog", () => InputManager.Key(Key.Number2));
|
||||
AddAssert("screen didn't change", () => Game.ScreenStack.CurrentScreen == blocker);
|
||||
AddAssert("did not perform", () => !actionPerformed);
|
||||
}
|
||||
}
|
||||
|
||||
public class DialogBlockingScreen : OsuScreen
|
||||
{
|
||||
[Resolved]
|
||||
private DialogOverlay dialogOverlay { get; set; }
|
||||
|
||||
private int dialogDisplayCount;
|
||||
|
||||
public int ExitAttempts { get; private set; }
|
||||
|
||||
public override bool OnExiting(IScreen next)
|
||||
{
|
||||
ExitAttempts++;
|
||||
|
||||
if (dialogDisplayCount++ < 1)
|
||||
{
|
||||
dialogOverlay.Push(new ConfirmExitDialog(this.Exit, () => { }));
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.OnExiting(next);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user