Merge branch 'master' into un-nest-overlined-display

This commit is contained in:
Dan Balasescu
2020-07-10 14:41:31 +09:00
committed by GitHub
16 changed files with 267 additions and 139 deletions

View File

@ -19,24 +19,18 @@ namespace osu.Game.Tests.NonVisual
[TestFixture]
public class CustomDataDirectoryTest
{
[SetUp]
public void SetUp()
{
if (Directory.Exists(customPath))
Directory.Delete(customPath, true);
}
[Test]
public void TestDefaultDirectory()
{
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(TestDefaultDirectory)))
using (HeadlessGameHost host = new CustomTestHeadlessGameHost(nameof(TestDefaultDirectory)))
{
try
{
string defaultStorageLocation = getDefaultLocationFor(nameof(TestDefaultDirectory));
var osu = loadOsu(host);
var storage = osu.Dependencies.Get<Storage>();
string defaultStorageLocation = Path.Combine(RuntimeInfo.StartupDirectory, "headless", nameof(TestDefaultDirectory));
Assert.That(storage.GetFullPath("."), Is.EqualTo(defaultStorageLocation));
}
finally
@ -46,21 +40,14 @@ namespace osu.Game.Tests.NonVisual
}
}
private string customPath => Path.Combine(RuntimeInfo.StartupDirectory, "custom-path");
[Test]
public void TestCustomDirectory()
{
using (var host = new HeadlessGameHost(nameof(TestCustomDirectory)))
string customPath = prepareCustomPath();
using (var host = new CustomTestHeadlessGameHost(nameof(TestCustomDirectory)))
{
string defaultStorageLocation = Path.Combine(RuntimeInfo.StartupDirectory, "headless", nameof(TestCustomDirectory));
// need access before the game has constructed its own storage yet.
Storage storage = new DesktopStorage(defaultStorageLocation, host);
// manual cleaning so we can prepare a config file.
storage.DeleteDirectory(string.Empty);
using (var storageConfig = new StorageConfigManager(storage))
using (var storageConfig = new StorageConfigManager(host.InitialStorage))
storageConfig.Set(StorageConfig.FullPath, customPath);
try
@ -68,7 +55,7 @@ namespace osu.Game.Tests.NonVisual
var osu = loadOsu(host);
// switch to DI'd storage
storage = osu.Dependencies.Get<Storage>();
var storage = osu.Dependencies.Get<Storage>();
Assert.That(storage.GetFullPath("."), Is.EqualTo(customPath));
}
@ -82,16 +69,11 @@ namespace osu.Game.Tests.NonVisual
[Test]
public void TestSubDirectoryLookup()
{
using (var host = new HeadlessGameHost(nameof(TestSubDirectoryLookup)))
string customPath = prepareCustomPath();
using (var host = new CustomTestHeadlessGameHost(nameof(TestSubDirectoryLookup)))
{
string defaultStorageLocation = Path.Combine(RuntimeInfo.StartupDirectory, "headless", nameof(TestSubDirectoryLookup));
// need access before the game has constructed its own storage yet.
Storage storage = new DesktopStorage(defaultStorageLocation, host);
// manual cleaning so we can prepare a config file.
storage.DeleteDirectory(string.Empty);
using (var storageConfig = new StorageConfigManager(storage))
using (var storageConfig = new StorageConfigManager(host.InitialStorage))
storageConfig.Set(StorageConfig.FullPath, customPath);
try
@ -99,7 +81,7 @@ namespace osu.Game.Tests.NonVisual
var osu = loadOsu(host);
// switch to DI'd storage
storage = osu.Dependencies.Get<Storage>();
var storage = osu.Dependencies.Get<Storage>();
string actualTestFile = Path.Combine(customPath, "rulesets", "test");
@ -120,10 +102,14 @@ namespace osu.Game.Tests.NonVisual
[Test]
public void TestMigration()
{
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(TestMigration)))
string customPath = prepareCustomPath();
using (HeadlessGameHost host = new CustomTestHeadlessGameHost(nameof(TestMigration)))
{
try
{
string defaultStorageLocation = getDefaultLocationFor(nameof(TestMigration));
var osu = loadOsu(host);
var storage = osu.Dependencies.Get<Storage>();
@ -139,8 +125,6 @@ namespace osu.Game.Tests.NonVisual
// for testing nested files are not ignored (only top level)
host.Storage.GetStorageForDirectory("test-nested").GetStorageForDirectory("cache");
string defaultStorageLocation = Path.Combine(RuntimeInfo.StartupDirectory, "headless", nameof(TestMigration));
Assert.That(storage.GetFullPath("."), Is.EqualTo(defaultStorageLocation));
osu.Migrate(customPath);
@ -178,14 +162,15 @@ namespace osu.Game.Tests.NonVisual
[Test]
public void TestMigrationBetweenTwoTargets()
{
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(TestMigrationBetweenTwoTargets)))
string customPath = prepareCustomPath();
string customPath2 = prepareCustomPath("-2");
using (HeadlessGameHost host = new CustomTestHeadlessGameHost(nameof(TestMigrationBetweenTwoTargets)))
{
try
{
var osu = loadOsu(host);
string customPath2 = $"{customPath}-2";
const string database_filename = "client.db";
Assert.DoesNotThrow(() => osu.Migrate(customPath));
@ -207,7 +192,9 @@ namespace osu.Game.Tests.NonVisual
[Test]
public void TestMigrationToSameTargetFails()
{
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(TestMigrationToSameTargetFails)))
string customPath = prepareCustomPath();
using (HeadlessGameHost host = new CustomTestHeadlessGameHost(nameof(TestMigrationToSameTargetFails)))
{
try
{
@ -226,7 +213,9 @@ namespace osu.Game.Tests.NonVisual
[Test]
public void TestMigrationToNestedTargetFails()
{
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(TestMigrationToNestedTargetFails)))
string customPath = prepareCustomPath();
using (HeadlessGameHost host = new CustomTestHeadlessGameHost(nameof(TestMigrationToNestedTargetFails)))
{
try
{
@ -253,7 +242,9 @@ namespace osu.Game.Tests.NonVisual
[Test]
public void TestMigrationToSeeminglyNestedTarget()
{
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(TestMigrationToSeeminglyNestedTarget)))
string customPath = prepareCustomPath();
using (HeadlessGameHost host = new CustomTestHeadlessGameHost(nameof(TestMigrationToSeeminglyNestedTarget)))
{
try
{
@ -282,6 +273,7 @@ namespace osu.Game.Tests.NonVisual
var osu = new OsuGameBase();
Task.Run(() => host.Run(osu));
waitForOrAssert(() => osu.IsLoaded, @"osu! failed to start in a reasonable amount of time");
return osu;
}
@ -294,5 +286,39 @@ namespace osu.Game.Tests.NonVisual
Assert.IsTrue(task.Wait(timeout), failureMessage);
}
private static string getDefaultLocationFor(string testTypeName)
{
string path = Path.Combine(RuntimeInfo.StartupDirectory, "headless", testTypeName);
if (Directory.Exists(path))
Directory.Delete(path, true);
return path;
}
private string prepareCustomPath(string suffix = "")
{
string path = Path.Combine(RuntimeInfo.StartupDirectory, $"custom-path{suffix}");
if (Directory.Exists(path))
Directory.Delete(path, true);
return path;
}
public class CustomTestHeadlessGameHost : HeadlessGameHost
{
public Storage InitialStorage { get; }
public CustomTestHeadlessGameHost(string name)
: base(name)
{
string defaultStorageLocation = getDefaultLocationFor(name);
InitialStorage = new DesktopStorage(defaultStorageLocation, this);
InitialStorage.DeleteDirectory(string.Empty);
}
}
}
}

View File

@ -0,0 +1,60 @@
// 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.
using System;
using osu.Framework.Allocation;
using osu.Game.Beatmaps;
using osu.Game.Online.Multiplayer;
using osu.Game.Rulesets;
using osu.Game.Screens.Multi;
using osu.Game.Users;
namespace osu.Game.Tests.Visual.Multiplayer
{
public abstract class RoomManagerTestScene : MultiplayerTestScene
{
[Cached(Type = typeof(IRoomManager))]
protected TestRoomManager RoomManager { get; } = new TestRoomManager();
public override void SetUpSteps()
{
base.SetUpSteps();
AddStep("clear rooms", () => RoomManager.Rooms.Clear());
}
protected void AddRooms(int count, RulesetInfo ruleset = null)
{
AddStep("add rooms", () =>
{
for (int i = 0; i < count; i++)
{
var room = new Room
{
RoomID = { Value = i },
Name = { Value = $"Room {i}" },
Host = { Value = new User { Username = "Host" } },
EndDate = { Value = DateTimeOffset.Now + TimeSpan.FromSeconds(10) }
};
if (ruleset != null)
{
room.Playlist.Add(new PlaylistItem
{
Ruleset = { Value = ruleset },
Beatmap =
{
Value = new BeatmapInfo
{
Metadata = new BeatmapMetadata()
}
}
});
}
RoomManager.Rooms.Add(room);
}
});
}
}
}

View File

@ -0,0 +1,35 @@
// 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.
using System;
using osu.Framework.Bindables;
using osu.Game.Online.Multiplayer;
using osu.Game.Screens.Multi;
namespace osu.Game.Tests.Visual.Multiplayer
{
public class TestRoomManager : IRoomManager
{
public event Action RoomsUpdated
{
add { }
remove { }
}
public readonly BindableList<Room> Rooms = new BindableList<Room>();
public Bindable<bool> InitialRoomsReceived { get; } = new Bindable<bool>(true);
IBindableList<Room> IRoomManager.Rooms => Rooms;
public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null) => Rooms.Add(room);
public void JoinRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
{
}
public void PartRoom()
{
}
}
}

View File

@ -16,7 +16,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
[SetUp]
public void Setup() => Schedule(() =>
{
Room.CopyFrom(new Room());
Room = new Room();
Child = new RoomInfo
{

View File

@ -1,30 +1,21 @@
// 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.
using System;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Online.Multiplayer;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Catch;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Multi;
using osu.Game.Screens.Multi.Lounge.Components;
using osu.Game.Users;
using osuTK.Graphics;
namespace osu.Game.Tests.Visual.Multiplayer
{
public class TestSceneLoungeRoomsContainer : MultiplayerTestScene
public class TestSceneLoungeRoomsContainer : RoomManagerTestScene
{
[Cached(Type = typeof(IRoomManager))]
private TestRoomManager roomManager = new TestRoomManager();
private RoomsContainer container;
[BackgroundDependencyLoader]
@ -39,34 +30,27 @@ namespace osu.Game.Tests.Visual.Multiplayer
};
}
public override void SetUpSteps()
{
base.SetUpSteps();
AddStep("clear rooms", () => roomManager.Rooms.Clear());
}
[Test]
public void TestBasicListChanges()
{
addRooms(3);
AddRooms(3);
AddAssert("has 3 rooms", () => container.Rooms.Count == 3);
AddStep("remove first room", () => roomManager.Rooms.Remove(roomManager.Rooms.FirstOrDefault()));
AddStep("remove first room", () => RoomManager.Rooms.Remove(RoomManager.Rooms.FirstOrDefault()));
AddAssert("has 2 rooms", () => container.Rooms.Count == 2);
AddAssert("first room removed", () => container.Rooms.All(r => r.Room.RoomID.Value != 0));
AddStep("select first room", () => container.Rooms.First().Action?.Invoke());
AddAssert("first room selected", () => Room == roomManager.Rooms.First());
AddAssert("first room selected", () => Room == RoomManager.Rooms.First());
AddStep("join first room", () => container.Rooms.First().Action?.Invoke());
AddAssert("first room joined", () => roomManager.Rooms.First().Status.Value is JoinedRoomStatus);
AddAssert("first room joined", () => RoomManager.Rooms.First().Status.Value is JoinedRoomStatus);
}
[Test]
public void TestStringFiltering()
{
addRooms(4);
AddRooms(4);
AddUntilStep("4 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 4);
@ -82,8 +66,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
[Test]
public void TestRulesetFiltering()
{
addRooms(2, new OsuRuleset().RulesetInfo);
addRooms(3, new CatchRuleset().RulesetInfo);
AddRooms(2, new OsuRuleset().RulesetInfo);
AddRooms(3, new CatchRuleset().RulesetInfo);
AddUntilStep("5 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 5);
@ -96,67 +80,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddUntilStep("3 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 3);
}
private void addRooms(int count, RulesetInfo ruleset = null)
{
AddStep("add rooms", () =>
{
for (int i = 0; i < count; i++)
{
var room = new Room
{
RoomID = { Value = i },
Name = { Value = $"Room {i}" },
Host = { Value = new User { Username = "Host" } },
EndDate = { Value = DateTimeOffset.Now + TimeSpan.FromSeconds(10) }
};
if (ruleset != null)
{
room.Playlist.Add(new PlaylistItem
{
Ruleset = { Value = ruleset },
Beatmap =
{
Value = new BeatmapInfo
{
Metadata = new BeatmapMetadata()
}
}
});
}
roomManager.Rooms.Add(room);
}
});
}
private void joinRequested(Room room) => room.Status.Value = new JoinedRoomStatus();
private class TestRoomManager : IRoomManager
{
public event Action RoomsUpdated
{
add { }
remove { }
}
public readonly BindableList<Room> Rooms = new BindableList<Room>();
public Bindable<bool> InitialRoomsReceived { get; } = new Bindable<bool>(true);
IBindableList<Room> IRoomManager.Rooms => Rooms;
public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null) => Rooms.Add(room);
public void JoinRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
{
}
public void PartRoom()
{
}
}
private class JoinedRoomStatus : RoomStatus
{
public override string Message => "Joined";

View File

@ -0,0 +1,58 @@
// 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.
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Game.Graphics.Containers;
using osu.Game.Screens.Multi.Lounge;
using osu.Game.Screens.Multi.Lounge.Components;
namespace osu.Game.Tests.Visual.Multiplayer
{
public class TestSceneLoungeSubScreen : RoomManagerTestScene
{
private LoungeSubScreen loungeScreen;
[BackgroundDependencyLoader]
private void load()
{
}
public override void SetUpSteps()
{
base.SetUpSteps();
AddStep("push screen", () => LoadScreen(loungeScreen = new LoungeSubScreen
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Width = 0.5f,
}));
AddUntilStep("wait for present", () => loungeScreen.IsCurrentScreen());
}
private RoomsContainer roomsContainer => loungeScreen.ChildrenOfType<RoomsContainer>().First();
[Test]
public void TestScrollSelectedIntoView()
{
AddRooms(30);
AddUntilStep("first room is not masked", () => checkRoomVisible(roomsContainer.Rooms.First()));
AddStep("select last room", () => roomsContainer.Rooms.Last().Action?.Invoke());
AddUntilStep("first room is masked", () => !checkRoomVisible(roomsContainer.Rooms.First()));
AddUntilStep("last room is not masked", () => checkRoomVisible(roomsContainer.Rooms.Last()));
}
private bool checkRoomVisible(DrawableRoom room) =>
loungeScreen.ChildrenOfType<OsuScrollContainer>().First().ScreenSpaceDrawQuad
.Contains(room.ScreenSpaceDrawQuad.Centre);
}
}

View File

@ -26,7 +26,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
[SetUp]
public void Setup() => Schedule(() =>
{
Room.Playlist.Clear();
Room = new Room();
Child = new MatchBeatmapDetailArea
{

View File

@ -14,6 +14,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
public TestSceneMatchHeader()
{
Room = new Room();
Room.Playlist.Add(new PlaylistItem
{
Beatmap =

View File

@ -6,6 +6,7 @@ using Newtonsoft.Json;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Online.API;
using osu.Game.Online.Multiplayer;
using osu.Game.Screens.Multi.Match.Components;
using osu.Game.Users;
using osuTK;
@ -18,7 +19,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
public TestSceneMatchLeaderboard()
{
Room.RoomID.Value = 3;
Room = new Room { RoomID = { Value = 3 } };
Add(new MatchLeaderboard
{

View File

@ -14,6 +14,7 @@ using osu.Framework.Platform;
using osu.Framework.Screens;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Online.Multiplayer;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Multi.Components;
@ -95,7 +96,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
[SetUp]
public void Setup() => Schedule(() =>
{
Room.Playlist.Clear();
Room = new Room();
});
[Test]

View File

@ -48,7 +48,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
[SetUp]
public void Setup() => Schedule(() =>
{
Room.CopyFrom(new Room());
Room = new Room();
});
[SetUpSteps]

View File

@ -3,6 +3,7 @@
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Game.Online.Multiplayer;
using osu.Game.Screens.Multi.Components;
using osuTK;
@ -12,10 +13,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
protected override bool UseOnlineAPI => true;
public TestSceneOverlinedParticipants()
[SetUp]
public void Setup() => Schedule(() =>
{
Room.RoomID.Value = 7;
}
Room = new Room { RoomID = { Value = 7 } };
});
[Test]
public void TestHorizontalLayout()

View File

@ -16,6 +16,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
public TestSceneOverlinedPlaylist()
{
Room = new Room { RoomID = { Value = 7 } };
for (int i = 0; i < 10; i++)
{
Room.Playlist.Add(new PlaylistItem

View File

@ -1,7 +1,9 @@
// 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.
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Game.Online.Multiplayer;
using osu.Game.Screens.Multi.Components;
namespace osu.Game.Tests.Visual.Multiplayer
@ -10,10 +12,14 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
protected override bool UseOnlineAPI => true;
[SetUp]
public void Setup() => Schedule(() =>
{
Room = new Room { RoomID = { Value = 7 } };
});
public TestSceneParticipantsList()
{
Room.RoomID.Value = 7;
Add(new ParticipantsList { RelativeSizeAxes = Axes.Both });
}
}

View File

@ -1,6 +1,7 @@
// 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.
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@ -20,21 +21,23 @@ namespace osu.Game.Screens.Multi.Lounge
{
public override string Title => "Lounge";
protected readonly FilterControl Filter;
protected FilterControl Filter;
private readonly Bindable<bool> initialRoomsReceived = new Bindable<bool>();
private readonly Container content;
private readonly LoadingLayer loadingLayer;
private Container content;
private LoadingLayer loadingLayer;
[Resolved]
private Bindable<Room> selectedRoom { get; set; }
private bool joiningRoom;
public LoungeSubScreen()
[BackgroundDependencyLoader]
private void load()
{
RoomsContainer roomsContainer;
OsuScrollContainer scrollContainer;
InternalChildren = new Drawable[]
{
@ -50,7 +53,7 @@ namespace osu.Game.Screens.Multi.Lounge
Width = 0.55f,
Children = new Drawable[]
{
new OsuScrollContainer
scrollContainer = new OsuScrollContainer
{
RelativeSizeAxes = Axes.Both,
ScrollbarOverlapsContent = false,
@ -70,6 +73,14 @@ namespace osu.Game.Screens.Multi.Lounge
},
},
};
// scroll selected room into view on selection.
selectedRoom.BindValueChanged(val =>
{
var drawable = roomsContainer.Rooms.FirstOrDefault(r => r.Room == val.NewValue);
if (drawable != null)
scrollContainer.ScrollIntoView(drawable);
});
}
protected override void LoadComplete()

View File

@ -10,7 +10,7 @@ namespace osu.Game.Tests.Visual
public abstract class MultiplayerTestScene : ScreenTestScene
{
[Cached]
private readonly Bindable<Room> currentRoom = new Bindable<Room>(new Room());
private readonly Bindable<Room> currentRoom = new Bindable<Room>();
protected Room Room
{