2021-03-29 21:27: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.
|
|
|
|
|
2021-03-29 21:03:10 +08:00
|
|
|
using System.IO;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Platform;
|
|
|
|
using osu.Game.Tournament.IO;
|
|
|
|
using osu.Game.Tournament.IPC;
|
|
|
|
|
|
|
|
namespace osu.Game.Tournament.Tests.NonVisual
|
|
|
|
{
|
|
|
|
[TestFixture]
|
2021-07-30 00:53:08 +08:00
|
|
|
public class IPCLocationTest : TournamentHostTest
|
2021-03-29 21:03:10 +08:00
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void CheckIPCLocation()
|
|
|
|
{
|
|
|
|
// don't use clean run because files are being written before osu! launches.
|
|
|
|
using (HeadlessGameHost host = new HeadlessGameHost(nameof(CheckIPCLocation)))
|
|
|
|
{
|
2021-11-23 13:38:37 +08:00
|
|
|
string basePath = CustomTourneyDirectoryTest.PrepareBasePath(nameof(CheckIPCLocation));
|
2021-03-29 21:03:10 +08:00
|
|
|
|
|
|
|
// Set up a fake IPC client for the IPC Storage to switch to.
|
2021-03-30 13:23:46 +08:00
|
|
|
string testStableInstallDirectory = Path.Combine(basePath, "stable-ce");
|
|
|
|
Directory.CreateDirectory(testStableInstallDirectory);
|
2021-03-29 21:03:10 +08:00
|
|
|
|
2021-03-30 13:23:46 +08:00
|
|
|
string ipcFile = Path.Combine(testStableInstallDirectory, "ipc.txt");
|
2021-03-29 21:03:10 +08:00
|
|
|
File.WriteAllText(ipcFile, string.Empty);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2021-07-30 00:53:08 +08:00
|
|
|
var osu = LoadTournament(host);
|
2021-03-29 21:03:10 +08:00
|
|
|
TournamentStorage storage = (TournamentStorage)osu.Dependencies.Get<Storage>();
|
2021-03-30 13:23:46 +08:00
|
|
|
FileBasedIPC ipc = null;
|
2021-03-29 21:03:10 +08:00
|
|
|
|
2021-07-30 00:53:08 +08:00
|
|
|
WaitForOrAssert(() => (ipc = osu.Dependencies.Get<MatchIPCInfo>() as FileBasedIPC) != null, @"ipc could not be populated in a reasonable amount of time");
|
2021-03-29 22:16:50 +08:00
|
|
|
|
2021-03-30 13:23:46 +08:00
|
|
|
Assert.True(ipc.SetIPCLocation(testStableInstallDirectory));
|
2021-03-29 21:03:10 +08:00
|
|
|
Assert.True(storage.AllTournaments.Exists("stable.json"));
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
host.Exit();
|
2021-11-23 13:38:37 +08:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (Directory.Exists(basePath))
|
|
|
|
Directory.Delete(basePath, true);
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
}
|
2021-03-29 21:03:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|