2020-05-04 08:01:05 +00: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.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Platform;
|
|
|
|
using osu.Game.Configuration;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.NonVisual
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public class CustomDataDirectoryTest
|
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void TestDefaultDirectory()
|
|
|
|
{
|
|
|
|
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(TestDefaultDirectory)))
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var osu = loadOsu(host);
|
|
|
|
var storage = osu.Dependencies.Get<Storage>();
|
|
|
|
|
2020-05-07 09:12:11 +00:00
|
|
|
string defaultStorageLocation = Path.Combine(Environment.CurrentDirectory, $"headless", nameof(TestDefaultDirectory));
|
2020-05-04 08:01:05 +00:00
|
|
|
|
|
|
|
Assert.That(storage.GetFullPath("."), Is.EqualTo(defaultStorageLocation));
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
host.Exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestCustomDirectory()
|
|
|
|
{
|
|
|
|
using (var host = new HeadlessGameHost(nameof(TestCustomDirectory)))
|
|
|
|
{
|
2020-05-07 09:12:11 +00:00
|
|
|
string headlessPrefix = Path.Combine("headless", nameof(TestCustomDirectory));
|
2020-05-04 08:01:05 +00:00
|
|
|
|
|
|
|
// need access before the game has constructed its own storage yet.
|
|
|
|
Storage storage = new DesktopStorage(headlessPrefix, host);
|
|
|
|
// manual cleaning so we can prepare a config file.
|
|
|
|
storage.DeleteDirectory(string.Empty);
|
|
|
|
|
|
|
|
using (var storageConfig = new StorageConfigManager(storage))
|
|
|
|
storageConfig.Set(StorageConfig.FullPath, Path.Combine(Environment.CurrentDirectory, "custom-path"));
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var osu = loadOsu(host);
|
|
|
|
|
|
|
|
// switch to DI'd storage
|
|
|
|
storage = osu.Dependencies.Get<Storage>();
|
|
|
|
|
|
|
|
Assert.That(storage.GetFullPath("."), Is.EqualTo(Path.Combine(Environment.CurrentDirectory, "custom-path")));
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
host.Exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private OsuGameBase loadOsu(GameHost host)
|
|
|
|
{
|
|
|
|
var osu = new OsuGameBase();
|
|
|
|
Task.Run(() => host.Run(osu));
|
|
|
|
waitForOrAssert(() => osu.IsLoaded, @"osu! failed to start in a reasonable amount of time");
|
|
|
|
return osu;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void waitForOrAssert(Func<bool> result, string failureMessage, int timeout = 60000)
|
|
|
|
{
|
|
|
|
Task task = Task.Run(() =>
|
|
|
|
{
|
|
|
|
while (!result()) Thread.Sleep(200);
|
|
|
|
});
|
|
|
|
|
|
|
|
Assert.IsTrue(task.Wait(timeout), failureMessage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|