1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 08:22:56 +08:00

Merge pull request #4554 from smoogipoo/fix-loaderanimation-testcase

Rework TestCaseLoaderAnimation to avoid timing issues

Co-authored-by: Dean Herbert <pe@ppy.sh>
This commit is contained in:
Dean Herbert 2019-03-29 15:02:51 +09:00 committed by GitHub
commit 315ff33d3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 41 deletions

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Threading;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -22,55 +23,76 @@ namespace osu.Game.Tests.Visual.Menus
public TestCaseLoaderAnimation() public TestCaseLoaderAnimation()
{ {
Add(logo = new OsuLogo { Depth = float.MinValue }); Child = logo = new OsuLogo { Depth = float.MinValue };
} }
protected override void LoadComplete() [Test]
public void TestInstantLoad()
{ {
base.LoadComplete();
bool logoVisible = false; bool logoVisible = false;
AddStep("almost instant display", () => LoadScreen(loader = new TestLoader(250)));
AddUntilStep("loaded", () =>
{
logoVisible = loader.Logo?.Alpha > 0;
return loader.Logo != null && loader.ScreenLoaded;
});
AddAssert("logo not visible", () => !logoVisible);
AddStep("short load", () => LoadScreen(loader = new TestLoader(800))); AddStep("begin loading", () =>
AddUntilStep("loaded", () => {
loader = new TestLoader();
loader.AllowLoad.Set();
LoadScreen(loader);
});
AddAssert("loaded", () =>
{ {
logoVisible = loader.Logo?.Alpha > 0; logoVisible = loader.Logo?.Alpha > 0;
return loader.Logo != null && loader.ScreenLoaded; return loader.Logo != null && loader.ScreenLoaded;
}); });
AddAssert("logo visible", () => logoVisible);
AddAssert("logo was not visible", () => !logoVisible);
}
[Test]
public void TestShortLoad()
{
bool logoVisible = false;
AddStep("begin loading", () => LoadScreen(loader = new TestLoader()));
AddWaitStep("wait", 2);
AddStep("finish loading", () =>
{
logoVisible = loader.Logo?.Alpha > 0;
loader.AllowLoad.Set();
});
AddAssert("loaded", () => loader.Logo != null && loader.ScreenLoaded);
AddAssert("logo was visible", () => logoVisible);
AddUntilStep("logo gone", () => loader.Logo?.Alpha == 0); AddUntilStep("logo gone", () => loader.Logo?.Alpha == 0);
}
AddStep("longer load", () => LoadScreen(loader = new TestLoader(1400))); [Test]
AddUntilStep("loaded", () => public void TestLongLoad()
{
bool logoVisible = false;
AddStep("begin loading", () => LoadScreen(loader = new TestLoader()));
AddWaitStep("wait", 10);
AddStep("finish loading", () =>
{ {
logoVisible = loader.Logo?.Alpha > 0; logoVisible = loader.Logo?.Alpha > 0;
return loader.Logo != null && loader.ScreenLoaded; loader.AllowLoad.Set();
}); });
AddAssert("logo visible", () => logoVisible);
AddAssert("loaded", () => loader.Logo != null && loader.ScreenLoaded);
AddAssert("logo was visible", () => logoVisible);
AddUntilStep("logo gone", () => loader.Logo?.Alpha == 0); AddUntilStep("logo gone", () => loader.Logo?.Alpha == 0);
} }
private class TestLoader : Loader private class TestLoader : Loader
{ {
private readonly double delay; public readonly ManualResetEventSlim AllowLoad = new ManualResetEventSlim();
public OsuLogo Logo; public OsuLogo Logo;
private TestScreen screen; private TestScreen screen;
public bool ScreenLoaded => screen.IsCurrentScreen(); public bool ScreenLoaded => screen.IsCurrentScreen();
public TestLoader(double delay)
{
this.delay = delay;
}
protected override void LogoArriving(OsuLogo logo, bool resuming) protected override void LogoArriving(OsuLogo logo, bool resuming)
{ {
Logo = logo; Logo = logo;
@ -78,25 +100,18 @@ namespace osu.Game.Tests.Visual.Menus
} }
protected override OsuScreen CreateLoadableScreen() => screen = new TestScreen(); protected override OsuScreen CreateLoadableScreen() => screen = new TestScreen();
protected override ShaderPrecompiler CreateShaderPrecompiler() => new TestShaderPrecompiler(delay); protected override ShaderPrecompiler CreateShaderPrecompiler() => new TestShaderPrecompiler(AllowLoad);
private class TestShaderPrecompiler : ShaderPrecompiler private class TestShaderPrecompiler : ShaderPrecompiler
{ {
private readonly double delay; private readonly ManualResetEventSlim allowLoad;
private double startTime;
public TestShaderPrecompiler(double delay) public TestShaderPrecompiler(ManualResetEventSlim allowLoad)
{ {
this.delay = delay; this.allowLoad = allowLoad;
} }
protected override void LoadComplete() protected override bool AllLoaded => allowLoad.IsSet;
{
base.LoadComplete();
startTime = Time.Current;
}
protected override bool AllLoaded => Time.Current > startTime + delay;
} }
private class TestScreen : OsuScreen private class TestScreen : OsuScreen

View File

@ -1,8 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Screens; using osu.Game.Screens;
namespace osu.Game.Tests.Visual namespace osu.Game.Tests.Visual
@ -12,12 +12,19 @@ namespace osu.Game.Tests.Visual
/// </summary> /// </summary>
public abstract class ScreenTestCase : ManualInputManagerTestCase public abstract class ScreenTestCase : ManualInputManagerTestCase
{ {
private OsuScreenStack stack; private readonly OsuScreenStack stack;
[BackgroundDependencyLoader] private readonly Container content;
private void load()
protected override Container<Drawable> Content => content;
protected ScreenTestCase()
{ {
Add(stack = new OsuScreenStack { RelativeSizeAxes = Axes.Both }); base.Content.AddRange(new Drawable[]
{
stack = new OsuScreenStack { RelativeSizeAxes = Axes.Both },
content = new Container { RelativeSizeAxes = Axes.Both }
});
} }
protected void LoadScreen(OsuScreen screen) protected void LoadScreen(OsuScreen screen)