2019-03-17 23:46:15 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2019-03-18 18:44:21 +08:00
|
|
|
using NUnit.Framework;
|
2019-03-18 10:48:11 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-03-18 13:57:06 +08:00
|
|
|
using osu.Framework.Screens;
|
2019-03-17 23:46:15 +08:00
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Rulesets.Osu;
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
|
|
|
using osu.Game.Screens.Play;
|
|
|
|
|
2019-03-25 00:02:36 +08:00
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
2019-03-17 23:46:15 +08:00
|
|
|
{
|
2019-03-18 18:44:21 +08:00
|
|
|
public class TestCasePause : PlayerTestCase
|
2019-03-17 23:46:15 +08:00
|
|
|
{
|
2019-03-18 18:44:21 +08:00
|
|
|
protected new PausePlayer Player => (PausePlayer)base.Player;
|
|
|
|
|
2019-03-17 23:46:15 +08:00
|
|
|
public TestCasePause()
|
|
|
|
: base(new OsuRuleset())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-03-18 18:44:21 +08:00
|
|
|
[Test]
|
|
|
|
public void TestPauseResume()
|
2019-03-17 23:46:15 +08:00
|
|
|
{
|
2019-03-21 15:33:34 +08:00
|
|
|
pauseAndConfirm();
|
|
|
|
resumeAndConfirm();
|
2019-03-18 18:44:21 +08:00
|
|
|
}
|
2019-03-18 10:48:11 +08:00
|
|
|
|
2019-03-18 18:44:21 +08:00
|
|
|
[Test]
|
|
|
|
public void TestPauseTooSoon()
|
|
|
|
{
|
2019-03-21 15:33:34 +08:00
|
|
|
pauseAndConfirm();
|
|
|
|
resumeAndConfirm();
|
|
|
|
|
|
|
|
pause();
|
|
|
|
|
|
|
|
confirmClockRunning(true);
|
|
|
|
confirmPauseOverlayShown(false);
|
2019-03-18 18:44:21 +08:00
|
|
|
}
|
2019-03-18 10:48:11 +08:00
|
|
|
|
2019-03-21 15:11:44 +08:00
|
|
|
[Test]
|
|
|
|
public void TestExitTooSoon()
|
|
|
|
{
|
2019-03-21 15:33:34 +08:00
|
|
|
pauseAndConfirm();
|
|
|
|
|
|
|
|
resume();
|
|
|
|
|
|
|
|
AddStep("exit too soon", () => Player.Exit());
|
|
|
|
|
|
|
|
confirmClockRunning(true);
|
|
|
|
confirmPauseOverlayShown(false);
|
|
|
|
|
2019-03-21 15:11:44 +08:00
|
|
|
AddAssert("not exited", () => Player.IsCurrentScreen());
|
|
|
|
}
|
|
|
|
|
2019-03-18 18:44:21 +08:00
|
|
|
[Test]
|
|
|
|
public void TestPauseAfterFail()
|
|
|
|
{
|
2019-03-20 09:30:17 +08:00
|
|
|
AddUntilStep("wait for fail", () => Player.HasFailed);
|
2019-03-18 18:44:21 +08:00
|
|
|
AddAssert("fail overlay shown", () => Player.FailOverlayVisible);
|
2019-03-18 10:48:11 +08:00
|
|
|
|
2019-03-21 15:33:34 +08:00
|
|
|
confirmClockRunning(false);
|
|
|
|
|
|
|
|
pause();
|
|
|
|
|
|
|
|
confirmClockRunning(false);
|
|
|
|
confirmPauseOverlayShown(false);
|
2019-03-18 13:57:06 +08:00
|
|
|
|
2019-03-18 18:44:21 +08:00
|
|
|
AddAssert("fail overlay still shown", () => Player.FailOverlayVisible);
|
2019-03-21 15:11:44 +08:00
|
|
|
|
2019-03-21 15:33:34 +08:00
|
|
|
exitAndConfirm();
|
2019-03-21 15:11:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestExitFromGameplay()
|
|
|
|
{
|
|
|
|
AddStep("exit", () => Player.Exit());
|
|
|
|
|
2019-03-21 15:33:34 +08:00
|
|
|
confirmPaused();
|
|
|
|
|
|
|
|
exitAndConfirm();
|
2019-03-18 18:44:21 +08:00
|
|
|
}
|
2019-03-18 13:57:06 +08:00
|
|
|
|
2019-03-18 18:44:21 +08:00
|
|
|
[Test]
|
|
|
|
public void TestExitFromPause()
|
|
|
|
{
|
2019-03-21 15:33:34 +08:00
|
|
|
pauseAndConfirm();
|
|
|
|
exitAndConfirm();
|
|
|
|
}
|
2019-03-18 13:57:06 +08:00
|
|
|
|
2019-03-21 15:33:34 +08:00
|
|
|
private void pauseAndConfirm()
|
|
|
|
{
|
|
|
|
pause();
|
|
|
|
confirmPaused();
|
2019-03-21 15:11:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-21 15:33:34 +08:00
|
|
|
private void resumeAndConfirm()
|
|
|
|
{
|
|
|
|
resume();
|
|
|
|
confirmResumed();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void exitAndConfirm()
|
2019-03-21 15:11:44 +08:00
|
|
|
{
|
|
|
|
AddUntilStep("player not exited", () => Player.IsCurrentScreen());
|
2019-03-18 18:44:21 +08:00
|
|
|
AddStep("exit", () => Player.Exit());
|
2019-03-21 15:33:34 +08:00
|
|
|
confirmExited();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void confirmPaused()
|
|
|
|
{
|
|
|
|
confirmClockRunning(false);
|
|
|
|
AddAssert("pause overlay shown", () => Player.PauseOverlayVisible);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void confirmResumed()
|
|
|
|
{
|
|
|
|
confirmClockRunning(true);
|
|
|
|
confirmPauseOverlayShown(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void confirmExited()
|
|
|
|
{
|
2019-03-20 09:30:17 +08:00
|
|
|
AddUntilStep("player exited", () => !Player.IsCurrentScreen());
|
2019-03-17 23:46:15 +08:00
|
|
|
}
|
|
|
|
|
2019-03-21 15:33:34 +08:00
|
|
|
private void pause() => AddStep("pause", () => Player.Pause());
|
|
|
|
private void resume() => AddStep("resume", () => Player.Resume());
|
|
|
|
|
|
|
|
private void confirmPauseOverlayShown(bool isShown) =>
|
|
|
|
AddAssert("pause overlay " + (isShown ? "shown" : "hidden"), () => Player.PauseOverlayVisible == isShown);
|
|
|
|
|
|
|
|
private void confirmClockRunning(bool isRunning) =>
|
|
|
|
AddAssert("clock " + (isRunning ? "running" : "stopped"), () => Player.GameplayClockContainer.GameplayClock.IsRunning == isRunning);
|
|
|
|
|
2019-03-18 18:44:21 +08:00
|
|
|
protected override bool AllowFail => true;
|
|
|
|
|
|
|
|
protected override Player CreatePlayer(Ruleset ruleset) => new PausePlayer();
|
|
|
|
|
|
|
|
protected class PausePlayer : Player
|
2019-03-17 23:46:15 +08:00
|
|
|
{
|
|
|
|
public new GameplayClockContainer GameplayClockContainer => base.GameplayClockContainer;
|
|
|
|
|
|
|
|
public new ScoreProcessor ScoreProcessor => base.ScoreProcessor;
|
2019-03-18 10:48:11 +08:00
|
|
|
|
|
|
|
public bool FailOverlayVisible => FailOverlay.State == Visibility.Visible;
|
|
|
|
|
|
|
|
public bool PauseOverlayVisible => PauseOverlay.State == Visibility.Visible;
|
2019-03-17 23:46:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|