osu/osu.Game.Tests/Visual/Menus/TestSceneLoader.cs

114 lines
3.6 KiB
C#
Raw Normal View History

// 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.
2018-05-31 08:29:59 +00:00
using System.Linq;
using System.Threading;
2018-05-31 08:29:59 +00:00
using NUnit.Framework;
2019-03-27 13:27:53 +00:00
using osu.Framework.Allocation;
2018-05-31 08:29:59 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
2019-01-23 11:52:00 +00:00
using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Game.Graphics.UserInterface;
2018-05-31 08:29:59 +00:00
using osu.Game.Screens;
using osu.Game.Screens.Menu;
2018-11-20 07:51:59 +00:00
using osuTK.Graphics;
2018-05-31 08:29:59 +00:00
2019-03-24 16:02:36 +00:00
namespace osu.Game.Tests.Visual.Menus
2018-05-31 08:29:59 +00:00
{
[TestFixture]
2020-03-10 17:49:20 +00:00
public class TestSceneLoader : ScreenTestScene
2018-05-31 08:29:59 +00:00
{
private TestLoader loader;
2019-03-27 13:27:53 +00:00
[Cached]
private OsuLogo logo;
2020-03-10 17:49:20 +00:00
public TestSceneLoader()
2019-03-27 13:27:53 +00:00
{
2019-04-19 03:44:57 +00:00
Child = logo = new OsuLogo
{
Alpha = 0,
Depth = float.MinValue
};
2019-03-27 13:27:53 +00:00
}
[Test]
public void TestInstantLoad()
2018-05-31 08:29:59 +00:00
{
AddStep("load immediately", () =>
{
loader = new TestLoader();
loader.AllowLoad.Set();
LoadScreen(loader);
});
spinnerNotPresentOrHidden();
AddUntilStep("loaded", () => loader.ScreenLoaded);
AddUntilStep("not current", () => !loader.IsCurrentScreen());
spinnerNotPresentOrHidden();
}
private void spinnerNotPresentOrHidden() =>
AddAssert("spinner did not display", () => loader.LoadingSpinner == null || loader.LoadingSpinner.Alpha == 0);
[Test]
2019-05-21 05:48:14 +00:00
public void TestDelayedLoad()
{
AddStep("begin loading", () => LoadScreen(loader = new TestLoader()));
AddUntilStep("wait for spinner visible", () => loader.LoadingSpinner?.Alpha > 0);
2019-05-21 05:48:14 +00:00
AddStep("finish loading", () => loader.AllowLoad.Set());
AddUntilStep("spinner gone", () => loader.LoadingSpinner?.Alpha == 0);
AddUntilStep("loaded", () => loader.ScreenLoaded);
AddUntilStep("not current", () => !loader.IsCurrentScreen());
2018-05-31 08:29:59 +00:00
}
private class TestLoader : Loader
{
public readonly ManualResetEventSlim AllowLoad = new ManualResetEventSlim();
2018-05-31 08:29:59 +00:00
2020-03-11 07:07:44 +00:00
public LoadingSpinner LoadingSpinner => this.ChildrenOfType<LoadingSpinner>().FirstOrDefault();
2018-05-31 11:07:55 +00:00
private TestScreen screen;
2018-05-31 08:29:59 +00:00
2019-01-23 11:52:00 +00:00
public bool ScreenLoaded => screen.IsCurrentScreen();
2018-05-31 11:07:55 +00:00
protected override OsuScreen CreateLoadableScreen() => screen = new TestScreen();
protected override ShaderPrecompiler CreateShaderPrecompiler() => new TestShaderPrecompiler(AllowLoad);
2018-05-31 08:29:59 +00:00
2018-05-31 11:07:55 +00:00
private class TestShaderPrecompiler : ShaderPrecompiler
2018-05-31 08:29:59 +00:00
{
private readonly ManualResetEventSlim allowLoad;
2018-05-31 11:07:55 +00:00
public TestShaderPrecompiler(ManualResetEventSlim allowLoad)
2018-05-31 11:07:55 +00:00
{
this.allowLoad = allowLoad;
2018-05-31 11:07:55 +00:00
}
2018-05-31 08:29:59 +00:00
protected override bool AllLoaded => allowLoad.IsSet;
2018-05-31 11:07:55 +00:00
}
private class TestScreen : OsuScreen
{
public TestScreen()
{
2019-01-23 11:52:00 +00:00
InternalChild = new Box
2018-05-31 08:29:59 +00:00
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.DarkSlateGray,
Alpha = 0,
};
}
protected override void LogoArriving(OsuLogo logo, bool resuming)
{
base.LogoArriving(logo, resuming);
2019-01-23 11:52:00 +00:00
InternalChild.FadeInFromZero(200);
2018-05-31 08:29:59 +00:00
}
}
}
}
}