Setup tests to run headless, add basic pass support

This commit is contained in:
Dean Herbert 2020-10-26 21:45:37 +09:00
parent 67f6d52e35
commit 593b0a3ada

View File

@ -4,10 +4,13 @@
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Online.Spectator; using osu.Game.Online.Spectator;
using osu.Game.Replays.Legacy; using osu.Game.Replays.Legacy;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osu.Game.Tests.Beatmaps.IO;
using osu.Game.Users; using osu.Game.Users;
namespace osu.Game.Tests.Visual.Gameplay namespace osu.Game.Tests.Visual.Gameplay
@ -17,14 +20,28 @@ namespace osu.Game.Tests.Visual.Gameplay
[Cached(typeof(SpectatorStreamingClient))] [Cached(typeof(SpectatorStreamingClient))]
private TestSpectatorStreamingClient testSpectatorStreamingClient = new TestSpectatorStreamingClient(); private TestSpectatorStreamingClient testSpectatorStreamingClient = new TestSpectatorStreamingClient();
private Spectator spectatorScreen;
[Resolved] [Resolved]
private OsuGameBase game { get; set; } private OsuGameBase game { get; set; }
public override void SetUpSteps()
{
base.SetUpSteps();
AddStep("import beatmap", () => ImportBeatmapTest.LoadOszIntoOsu(game, virtualTrack: true).Wait());
AddStep("add streaming client", () =>
{
Remove(testSpectatorStreamingClient);
Add(testSpectatorStreamingClient);
});
}
[Test] [Test]
public void TestBasicSpectatingFlow() public void TestBasicSpectatingFlow()
{ {
AddStep("add streaming client", () => Add(testSpectatorStreamingClient)); beginSpectating();
AddStep("load screen", () => LoadScreen(new Spectator(testSpectatorStreamingClient.StreamingUser)));
AddStep("start play", () => testSpectatorStreamingClient.StartPlay()); AddStep("start play", () => testSpectatorStreamingClient.StartPlay());
AddStep("send frames", () => testSpectatorStreamingClient.SendFrames()); AddStep("send frames", () => testSpectatorStreamingClient.SendFrames());
} }
@ -32,27 +49,68 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test] [Test]
public void TestSpectatingDuringGameplay() public void TestSpectatingDuringGameplay()
{ {
AddStep("start play", () => testSpectatorStreamingClient.StartPlay());
AddStep("send frames", () => testSpectatorStreamingClient.SendFrames());
// should seek immediately to available frames // should seek immediately to available frames
beginSpectating();
} }
[Test] [Test]
public void TestHostStartsPlayingWhileAlreadyWatching() public void TestHostStartsPlayingWhileAlreadyWatching()
{ {
beginSpectating();
AddStep("start play", () => testSpectatorStreamingClient.StartPlay());
AddStep("send frames", () => testSpectatorStreamingClient.SendFrames());
AddStep("start play", () => testSpectatorStreamingClient.StartPlay());
AddStep("send frames", () => testSpectatorStreamingClient.SendFrames());
// should restart either immediately or after running out of frames // should restart either immediately or after running out of frames
} }
[Test] [Test]
public void TestHostFails() public void TestHostFails()
{ {
beginSpectating();
AddStep("start play", () => testSpectatorStreamingClient.StartPlay());
AddStep("send frames", () => testSpectatorStreamingClient.SendFrames());
// todo: send fail state
// should replay until running out of frames then fail // should replay until running out of frames then fail
} }
[Test] [Test]
public void TestStopWatchingDuringPlay() public void TestStopWatchingDuringPlay()
{ {
beginSpectating();
AddStep("start play", () => testSpectatorStreamingClient.StartPlay());
AddStep("send frames", () => testSpectatorStreamingClient.SendFrames());
AddUntilStep("wait for player", () => Stack.CurrentScreen is Player);
// should immediately exit and unbind from streaming client // should immediately exit and unbind from streaming client
AddStep("stop spectating", () => (Stack.CurrentScreen as Player)?.Exit());
AddUntilStep("spectating stopped", () => spectatorScreen.GetParentScreen() == null);
} }
[Test]
public void TestWatchingBeatmapThatDoesntExistLocally()
{
beginSpectating();
AddStep("start play", () => testSpectatorStreamingClient.StartPlay());
AddStep("send frames", () => testSpectatorStreamingClient.SendFrames());
// player should never arrive.
}
private void beginSpectating() =>
AddStep("load screen", () => LoadScreen(spectatorScreen = new Spectator(testSpectatorStreamingClient.StreamingUser)));
internal class TestSpectatorStreamingClient : SpectatorStreamingClient internal class TestSpectatorStreamingClient : SpectatorStreamingClient
{ {
[Resolved] [Resolved]
@ -64,7 +122,16 @@ namespace osu.Game.Tests.Visual.Gameplay
{ {
((ISpectatorClient)this).UserBeganPlaying((int)StreamingUser.Id, new SpectatorState ((ISpectatorClient)this).UserBeganPlaying((int)StreamingUser.Id, new SpectatorState
{ {
BeatmapID = beatmaps.GetAllUsableBeatmapSets().First().Beatmaps.First().OnlineBeatmapID, BeatmapID = beatmaps.GetAllUsableBeatmapSets().First().Beatmaps.First(b => b.RulesetID == 0).OnlineBeatmapID,
RulesetID = 0,
});
}
public void EndPlay()
{
((ISpectatorClient)this).UserFinishedPlaying((int)StreamingUser.Id, new SpectatorState
{
BeatmapID = beatmaps.GetAllUsableBeatmapSets().First().Beatmaps.First(b => b.RulesetID == 0).OnlineBeatmapID,
RulesetID = 0, RulesetID = 0,
}); });
} }