1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 10:12:54 +08:00

Add test coverage of certification flow

This commit is contained in:
Dean Herbert 2022-06-07 23:02:15 +09:00
parent c1ef59ab03
commit 058760253a
2 changed files with 46 additions and 7 deletions

View File

@ -3,17 +3,55 @@
#nullable enable #nullable enable
using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Testing;
using osu.Game.Graphics.UserInterface;
using osu.Game.Screens; using osu.Game.Screens;
using osuTK.Input;
namespace osu.Game.Tests.Visual.Settings namespace osu.Game.Tests.Visual.Settings
{ {
public class TestSceneLatencyComparer : ScreenTestScene public class TestSceneLatencyComparer : ScreenTestScene
{ {
[Test] private LatencyComparerScreen latencyComparer = null!;
public void TestBasic()
public override void SetUpSteps()
{ {
AddStep("Load screen", () => LoadScreen(new LatencyComparerScreen())); base.SetUpSteps();
AddStep("Load screen", () => LoadScreen(latencyComparer = new LatencyComparerScreen()));
}
[Test]
public void TestCertification()
{
for (int i = 0; i < 4; i++)
{
clickCorrectUntilResults();
AddAssert("check at results", () => !latencyComparer.ChildrenOfType<LatencyComparerScreen.LatencyArea>().Any());
AddStep("hit c to continue", () => InputManager.Key(Key.C));
}
AddAssert("check at results", () => !latencyComparer.ChildrenOfType<LatencyComparerScreen.LatencyArea>().Any());
AddAssert("check no buttons", () => !latencyComparer.ChildrenOfType<OsuButton>().Any());
}
private void clickCorrectUntilResults()
{
AddUntilStep("click correct button until results", () =>
{
var latencyArea = latencyComparer
.ChildrenOfType<LatencyComparerScreen.LatencyArea>()
.SingleOrDefault(a => a.TargetFrameRate == 0);
// reached results
if (latencyArea == null)
return true;
latencyArea.ChildrenOfType<OsuButton>().Single().TriggerClick();
return false;
});
} }
} }
} }

View File

@ -358,7 +358,7 @@ Do whatever you need to try and perceive the difference in latency, then choose
Origin = Anchor.Centre, Origin = Anchor.Centre,
Action = () => changeDifficulty(Math.Max(difficultyLevel - 1, 1)), Action = () => changeDifficulty(Math.Max(difficultyLevel - 1, 1)),
}, },
new Button(Key.R) new Button(Key.C)
{ {
Text = $"Continue towards certification at this level ({certificationRemaining} more)", Text = $"Continue towards certification at this level ({certificationRemaining} more)",
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
@ -438,14 +438,15 @@ Do whatever you need to try and perceive the difference in latency, then choose
private Drawable? background; private Drawable? background;
private readonly Key key; private readonly Key key;
private readonly int targetFrameRate;
public readonly int TargetFrameRate;
public readonly BindableBool IsActiveArea = new BindableBool(); public readonly BindableBool IsActiveArea = new BindableBool();
public LatencyArea(Key key, int targetFrameRate) public LatencyArea(Key key, int targetFrameRate)
{ {
this.key = key; this.key = key;
this.targetFrameRate = targetFrameRate; TargetFrameRate = targetFrameRate;
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;
Masking = true; Masking = true;
@ -505,7 +506,7 @@ Do whatever you need to try and perceive the difference in latency, then choose
public override bool UpdateSubTree() public override bool UpdateSubTree()
{ {
double elapsed = Clock.CurrentTime - lastFrameTime; double elapsed = Clock.CurrentTime - lastFrameTime;
if (targetFrameRate > 0 && elapsed < 1000.0 / targetFrameRate) if (TargetFrameRate > 0 && elapsed < 1000.0 / TargetFrameRate)
return false; return false;
lastFrameTime = Clock.CurrentTime; lastFrameTime = Clock.CurrentTime;