mirror of
https://github.com/ppy/osu.git
synced 2025-01-21 06:42:54 +08:00
Extract logic shared between tests
This commit is contained in:
parent
b17c5c0bb3
commit
aa1dfdd663
@ -23,36 +23,34 @@ namespace osu.Game.Tests.Visual
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestPauseResume()
|
public void TestPauseResume()
|
||||||
{
|
{
|
||||||
AddStep("pause", () => Player.Pause());
|
pauseAndConfirm();
|
||||||
AddAssert("clock stopped", () => !Player.GameplayClockContainer.GameplayClock.IsRunning);
|
resumeAndConfirm();
|
||||||
AddAssert("pause overlay shown", () => Player.PauseOverlayVisible);
|
|
||||||
|
|
||||||
AddStep("resume", () => Player.Resume());
|
|
||||||
AddAssert("pause overlay hidden", () => !Player.PauseOverlayVisible);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestPauseTooSoon()
|
public void TestPauseTooSoon()
|
||||||
{
|
{
|
||||||
AddStep("pause", () => Player.Pause());
|
pauseAndConfirm();
|
||||||
AddAssert("clock stopped", () => !Player.GameplayClockContainer.GameplayClock.IsRunning);
|
resumeAndConfirm();
|
||||||
AddStep("resume", () => Player.Resume());
|
|
||||||
AddAssert("clock started", () => Player.GameplayClockContainer.GameplayClock.IsRunning);
|
pause();
|
||||||
AddStep("pause too soon", () => Player.Pause());
|
|
||||||
AddAssert("clock not stopped", () => Player.GameplayClockContainer.GameplayClock.IsRunning);
|
confirmClockRunning(true);
|
||||||
AddAssert("pause overlay hidden", () => !Player.PauseOverlayVisible);
|
confirmPauseOverlayShown(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestExitTooSoon()
|
public void TestExitTooSoon()
|
||||||
{
|
{
|
||||||
AddStep("pause", () => Player.Pause());
|
pauseAndConfirm();
|
||||||
AddAssert("clock stopped", () => !Player.GameplayClockContainer.GameplayClock.IsRunning);
|
|
||||||
AddStep("resume", () => Player.Resume());
|
resume();
|
||||||
AddAssert("clock started", () => Player.GameplayClockContainer.GameplayClock.IsRunning);
|
|
||||||
AddStep("pause too soon", () => Player.Exit());
|
AddStep("exit too soon", () => Player.Exit());
|
||||||
AddAssert("clock not stopped", () => Player.GameplayClockContainer.GameplayClock.IsRunning);
|
|
||||||
AddAssert("pause overlay hidden", () => !Player.PauseOverlayVisible);
|
confirmClockRunning(true);
|
||||||
|
confirmPauseOverlayShown(false);
|
||||||
|
|
||||||
AddAssert("not exited", () => Player.IsCurrentScreen());
|
AddAssert("not exited", () => Player.IsCurrentScreen());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,42 +60,80 @@ namespace osu.Game.Tests.Visual
|
|||||||
AddUntilStep("wait for fail", () => Player.HasFailed);
|
AddUntilStep("wait for fail", () => Player.HasFailed);
|
||||||
AddAssert("fail overlay shown", () => Player.FailOverlayVisible);
|
AddAssert("fail overlay shown", () => Player.FailOverlayVisible);
|
||||||
|
|
||||||
AddStep("try to pause", () => Player.Pause());
|
confirmClockRunning(false);
|
||||||
|
|
||||||
|
pause();
|
||||||
|
|
||||||
|
confirmClockRunning(false);
|
||||||
|
confirmPauseOverlayShown(false);
|
||||||
|
|
||||||
AddAssert("pause overlay hidden", () => !Player.PauseOverlayVisible);
|
|
||||||
AddAssert("fail overlay still shown", () => Player.FailOverlayVisible);
|
AddAssert("fail overlay still shown", () => Player.FailOverlayVisible);
|
||||||
|
|
||||||
confirmExit();
|
exitAndConfirm();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestExitFromGameplay()
|
public void TestExitFromGameplay()
|
||||||
{
|
{
|
||||||
AddStep("exit", () => Player.Exit());
|
AddStep("exit", () => Player.Exit());
|
||||||
AddUntilStep("wait for pause", () => Player.PauseOverlayVisible);
|
|
||||||
|
|
||||||
confirmExit();
|
confirmPaused();
|
||||||
|
|
||||||
|
exitAndConfirm();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestExitFromPause()
|
public void TestExitFromPause()
|
||||||
{
|
{
|
||||||
AddUntilStep("keep trying to pause", () =>
|
pauseAndConfirm();
|
||||||
{
|
exitAndConfirm();
|
||||||
Player.Pause();
|
|
||||||
return Player.PauseOverlayVisible;
|
|
||||||
});
|
|
||||||
|
|
||||||
confirmExit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void confirmExit()
|
private void pauseAndConfirm()
|
||||||
|
{
|
||||||
|
pause();
|
||||||
|
confirmPaused();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resumeAndConfirm()
|
||||||
|
{
|
||||||
|
resume();
|
||||||
|
confirmResumed();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void exitAndConfirm()
|
||||||
{
|
{
|
||||||
AddUntilStep("player not exited", () => Player.IsCurrentScreen());
|
AddUntilStep("player not exited", () => Player.IsCurrentScreen());
|
||||||
AddStep("exit", () => Player.Exit());
|
AddStep("exit", () => Player.Exit());
|
||||||
|
confirmExited();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void confirmPaused()
|
||||||
|
{
|
||||||
|
confirmClockRunning(false);
|
||||||
|
AddAssert("pause overlay shown", () => Player.PauseOverlayVisible);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void confirmResumed()
|
||||||
|
{
|
||||||
|
confirmClockRunning(true);
|
||||||
|
confirmPauseOverlayShown(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void confirmExited()
|
||||||
|
{
|
||||||
AddUntilStep("player exited", () => !Player.IsCurrentScreen());
|
AddUntilStep("player exited", () => !Player.IsCurrentScreen());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
protected override bool AllowFail => true;
|
protected override bool AllowFail => true;
|
||||||
|
|
||||||
protected override Player CreatePlayer(Ruleset ruleset) => new PausePlayer();
|
protected override Player CreatePlayer(Ruleset ruleset) => new PausePlayer();
|
||||||
|
Loading…
Reference in New Issue
Block a user