2021-07-30 00:53:25 +08:00
|
|
|
// 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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2022-03-31 17:31:18 +08:00
|
|
|
using System;
|
2021-07-30 00:53:25 +08:00
|
|
|
using System.IO;
|
2022-03-31 17:31:18 +08:00
|
|
|
using System.Threading.Tasks;
|
2022-07-26 13:56:41 +08:00
|
|
|
using JetBrains.Annotations;
|
2021-07-30 00:53:25 +08:00
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
2022-03-31 17:31:18 +08:00
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Extensions;
|
2021-07-30 00:53:25 +08:00
|
|
|
using osu.Framework.Platform;
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Tests;
|
|
|
|
|
|
|
|
namespace osu.Game.Tournament.Tests.NonVisual
|
|
|
|
{
|
|
|
|
public class DataLoadTest : TournamentHostTest
|
|
|
|
{
|
2022-03-31 17:31:18 +08:00
|
|
|
[Test]
|
|
|
|
public void TestRulesetGetsValidOnlineID()
|
|
|
|
{
|
|
|
|
using (HeadlessGameHost host = new CleanRunHeadlessGameHost())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var osu = new TestTournament(runOnLoadComplete: () =>
|
|
|
|
{
|
|
|
|
var storage = host.Storage.GetStorageForDirectory(Path.Combine("tournaments", "default"));
|
|
|
|
|
2022-05-16 17:03:53 +08:00
|
|
|
using (var stream = storage.CreateFileSafely("bracket.json"))
|
2022-03-31 17:31:18 +08:00
|
|
|
using (var writer = new StreamWriter(stream))
|
|
|
|
{
|
|
|
|
writer.Write(@"{
|
|
|
|
""Ruleset"": {
|
|
|
|
""ShortName"": ""taiko"",
|
|
|
|
""OnlineID"": -1,
|
|
|
|
""Name"": ""osu!taiko"",
|
|
|
|
""InstantiationInfo"": ""osu.Game.Rulesets.OsuTaiko.TaikoRuleset, osu.Game.Rulesets.Taiko"",
|
|
|
|
""Available"": true
|
|
|
|
} }");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
LoadTournament(host, osu);
|
|
|
|
|
|
|
|
osu.BracketLoadTask.WaitSafely();
|
|
|
|
|
|
|
|
Assert.That(osu.Dependencies.Get<IBindable<RulesetInfo>>().Value.OnlineID, Is.EqualTo(1));
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
host.Exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-30 00:53:25 +08:00
|
|
|
[Test]
|
|
|
|
public void TestUnavailableRuleset()
|
|
|
|
{
|
2021-12-24 19:17:20 +08:00
|
|
|
using (HeadlessGameHost host = new CleanRunHeadlessGameHost())
|
2021-07-30 00:53:25 +08:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2022-03-31 17:31:18 +08:00
|
|
|
var osu = new TestTournament(true);
|
2021-07-30 00:53:25 +08:00
|
|
|
|
|
|
|
LoadTournament(host, osu);
|
|
|
|
var storage = osu.Dependencies.Get<Storage>();
|
|
|
|
|
|
|
|
Assert.That(storage.GetFullPath("."), Is.EqualTo(Path.Combine(host.Storage.GetFullPath("."), "tournaments", "default")));
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
host.Exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class TestTournament : TournamentGameBase
|
|
|
|
{
|
2022-03-31 17:31:18 +08:00
|
|
|
private readonly bool resetRuleset;
|
|
|
|
private readonly Action runOnLoadComplete;
|
|
|
|
|
|
|
|
public new Task BracketLoadTask => base.BracketLoadTask;
|
|
|
|
|
2022-07-26 13:56:41 +08:00
|
|
|
public TestTournament(bool resetRuleset = false, [InstantHandle] Action runOnLoadComplete = null)
|
2022-03-31 17:31:18 +08:00
|
|
|
{
|
|
|
|
this.resetRuleset = resetRuleset;
|
|
|
|
this.runOnLoadComplete = runOnLoadComplete;
|
|
|
|
}
|
|
|
|
|
2022-01-18 11:24:42 +08:00
|
|
|
protected override void LoadComplete()
|
2021-07-30 00:53:25 +08:00
|
|
|
{
|
2022-03-31 17:31:18 +08:00
|
|
|
runOnLoadComplete?.Invoke();
|
2022-01-18 11:24:42 +08:00
|
|
|
base.LoadComplete();
|
2022-03-31 17:31:18 +08:00
|
|
|
if (resetRuleset)
|
|
|
|
Ruleset.Value = new RulesetInfo(); // not available
|
2021-07-30 00:53:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|