osu/osu.Game.Tests/Visual/Gameplay/TestCasePlayerLoader.cs

143 lines
4.5 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.
2019-04-09 06:05:03 +00:00
using System.Collections.Generic;
using System.Linq;
using System.Threading;
2019-04-09 04:50:54 +00:00
using NUnit.Framework;
using osu.Framework.Allocation;
2019-04-09 06:05:03 +00:00
using osu.Framework.Bindables;
2019-02-12 10:53:08 +00:00
using osu.Framework.Graphics;
2019-01-23 11:52:00 +00:00
using osu.Framework.Screens;
2019-04-09 06:05:03 +00:00
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens;
using osu.Game.Screens.Play;
2019-03-24 16:02:36 +00:00
namespace osu.Game.Tests.Visual.Gameplay
{
public class TestCasePlayerLoader : ManualInputManagerTestCase
{
private PlayerLoader loader;
2019-03-12 07:33:35 +00:00
private readonly OsuScreenStack stack;
public TestCasePlayerLoader()
{
2019-03-12 07:33:35 +00:00
InputManager.Add(stack = new OsuScreenStack { RelativeSizeAxes = Axes.Both });
}
2019-04-09 04:50:54 +00:00
[Test]
public void TestLoadContinuation()
{
AddStep("load dummy beatmap", () => stack.Push(loader = new PlayerLoader(() => new Player(false, false))));
2019-03-19 08:24:26 +00:00
AddUntilStep("wait for current", () => loader.IsCurrentScreen());
AddStep("mouse in centre", () => InputManager.MoveMouseTo(loader.ScreenSpaceDrawQuad.Centre));
2019-03-19 08:24:26 +00:00
AddUntilStep("wait for no longer current", () => !loader.IsCurrentScreen());
2019-02-12 10:53:08 +00:00
AddStep("exit loader", () => loader.Exit());
2019-03-19 08:24:26 +00:00
AddUntilStep("wait for no longer alive", () => !loader.IsAlive);
AddStep("load slow dummy beatmap", () =>
{
2018-12-26 13:16:35 +00:00
SlowLoadPlayer slow = null;
stack.Push(loader = new PlayerLoader(() => slow = new SlowLoadPlayer(false, false)));
Scheduler.AddDelayed(() => slow.Ready = true, 5000);
});
2019-03-19 08:24:26 +00:00
AddUntilStep("wait for no longer current", () => !loader.IsCurrentScreen());
}
2019-04-09 06:05:03 +00:00
[Test]
public void TestModReinstantiation()
{
TestPlayer player = null;
TestMod gameMod = null;
TestMod playerMod1 = null;
TestMod playerMod2 = null;
AddStep("load player", () =>
{
2019-04-17 07:11:59 +00:00
Mods.Value = new[] { gameMod = new TestMod() };
2019-04-09 06:05:03 +00:00
InputManager.MoveMouseTo(loader.ScreenSpaceDrawQuad.Centre);
stack.Push(new PlayerLoader(() => player = new TestPlayer()));
});
AddUntilStep("wait for player to become current", () =>
{
if (player.IsCurrentScreen())
{
2019-04-17 07:11:59 +00:00
playerMod1 = (TestMod)player.Mods.Value.Single();
2019-04-09 06:05:03 +00:00
return true;
}
return false;
});
AddAssert("game mods not applied", () => gameMod.Applied == false);
AddAssert("player mods applied", () => playerMod1.Applied);
AddStep("restart player", () =>
{
player = null;
player.Restart();
});
AddUntilStep("wait for player to become current", () =>
{
if (player.IsCurrentScreen())
{
2019-04-17 07:11:59 +00:00
playerMod2 = (TestMod)player.Mods.Value.Single();
2019-04-09 06:05:03 +00:00
return true;
}
return false;
});
AddAssert("game mods not applied", () => gameMod.Applied == false);
AddAssert("player has different mods", () => playerMod1 != playerMod2);
AddAssert("player mods applied", () => playerMod2.Applied);
}
private class TestMod : Mod, IApplicableToScoreProcessor
{
public override string Name => string.Empty;
public override string Acronym => string.Empty;
public override double ScoreMultiplier => 1;
public bool Applied { get; private set; }
public void ApplyToScoreProcessor(ScoreProcessor scoreProcessor)
{
Applied = true;
}
}
private class TestPlayer : Player
{
2019-04-17 07:11:59 +00:00
public new Bindable<IReadOnlyList<Mod>> Mods => base.Mods;
2019-04-09 06:05:03 +00:00
public TestPlayer()
: base(false, false)
{
}
}
protected class SlowLoadPlayer : Player
{
public bool Ready;
public SlowLoadPlayer(bool allowPause = true, bool showResults = true)
: base(allowPause, showResults)
{
}
[BackgroundDependencyLoader]
private void load()
{
while (!Ready)
Thread.Sleep(1);
}
}
}
}