From 4dba96e189c2af01d3c947d43d66ddf17c066d34 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 27 Oct 2020 16:28:11 +0900 Subject: [PATCH] Add more useful frame sending logic to tests --- .../Visual/Gameplay/TestSceneSpectator.cs | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSpectator.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSpectator.cs index 8c03de8c13..f33a6876dd 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneSpectator.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSpectator.cs @@ -1,16 +1,19 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Collections.Generic; using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Screens; using osu.Framework.Testing; +using osu.Framework.Utils; using osu.Game.Beatmaps; using osu.Game.Online.Spectator; using osu.Game.Replays.Legacy; using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu.Replays; +using osu.Game.Rulesets.UI; using osu.Game.Screens.Play; using osu.Game.Tests.Beatmaps.IO; using osu.Game.Users; @@ -50,22 +53,25 @@ namespace osu.Game.Tests.Visual.Gameplay { beginSpectating(); AddStep("start play", () => testSpectatorStreamingClient.StartPlay()); - AddStep("send frames", () => testSpectatorStreamingClient.SendFrames()); - + sendFrames(); AddUntilStep("wait for player", () => Stack.CurrentScreen is Player); AddAssert("ensure frames arrived", () => replayHandler.HasFrames); AddUntilStep("wait for frame starvation", () => replayHandler.NextFrame == null); - AddAssert("game is paused", () => !player.ChildrenOfType().First().GameplayClock.IsRunning); + AddAssert("game is paused", () => player.ChildrenOfType().First().IsPaused.Value); + } + + private void sendFrames(int count = 10) + { + AddStep("send frames", () => testSpectatorStreamingClient.SendFrames(count)); } [Test] public void TestSpectatingDuringGameplay() { AddStep("start play", () => testSpectatorStreamingClient.StartPlay()); - AddStep("send frames", () => testSpectatorStreamingClient.SendFrames()); - + sendFrames(); // should seek immediately to available frames beginSpectating(); } @@ -76,11 +82,9 @@ namespace osu.Game.Tests.Visual.Gameplay beginSpectating(); AddStep("start play", () => testSpectatorStreamingClient.StartPlay()); - AddStep("send frames", () => testSpectatorStreamingClient.SendFrames()); - + sendFrames(); AddStep("start play", () => testSpectatorStreamingClient.StartPlay()); - AddStep("send frames", () => testSpectatorStreamingClient.SendFrames()); - // should restart either immediately or after running out of frames + sendFrames(); } [Test] @@ -89,8 +93,7 @@ namespace osu.Game.Tests.Visual.Gameplay beginSpectating(); AddStep("start play", () => testSpectatorStreamingClient.StartPlay()); - AddStep("send frames", () => testSpectatorStreamingClient.SendFrames()); - // todo: send fail state + sendFrames(); // should replay until running out of frames then fail } @@ -101,8 +104,7 @@ namespace osu.Game.Tests.Visual.Gameplay beginSpectating(); AddStep("start play", () => testSpectatorStreamingClient.StartPlay()); - AddStep("send frames", () => testSpectatorStreamingClient.SendFrames()); - + sendFrames(); AddUntilStep("wait for player", () => Stack.CurrentScreen is Player); // should immediately exit and unbind from streaming client @@ -117,8 +119,7 @@ namespace osu.Game.Tests.Visual.Gameplay beginSpectating(); AddStep("start play", () => testSpectatorStreamingClient.StartPlay()); - AddStep("send frames", () => testSpectatorStreamingClient.SendFrames()); - + sendFrames(); // player should never arrive. } @@ -143,13 +144,19 @@ namespace osu.Game.Tests.Visual.Gameplay }); } - public void SendFrames() + public void SendFrames(int count) { - ((ISpectatorClient)this).UserSentFrames((int)StreamingUser.Id, new FrameDataBundle(new[] + var frames = new List(); + + for (int i = 0; i < count; i++) { - // todo: populate more frames - new LegacyReplayFrame(0, 0, 0, ReplayButtonState.Left1) - })); + frames.Add(new LegacyReplayFrame(i * 100, RNG.Next(0, 512), RNG.Next(0, 512), ReplayButtonState.Left1)); + } + + frames.Add(new LegacyReplayFrame(count * 100, 0, 0, ReplayButtonState.None)); + + var bundle = new FrameDataBundle(frames); + ((ISpectatorClient)this).UserSentFrames((int)StreamingUser.Id, bundle); } public override void WatchUser(int userId)