Merge branch 'master' into tourney-asset-refactor

This commit is contained in:
Dean Herbert
2020-10-07 21:34:07 +09:00
committed by GitHub
774 changed files with 17705 additions and 4787 deletions

View File

@ -4,8 +4,7 @@
using System;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
using NUnit.Framework;
using osu.Framework;
using osu.Framework.Allocation;
@ -17,18 +16,18 @@ using osu.Game.IO;
namespace osu.Game.Tests.NonVisual
{
[TestFixture]
public class CustomDataDirectoryTest
public class CustomDataDirectoryTest : ImportTest
{
[Test]
public void TestDefaultDirectory()
{
using (HeadlessGameHost host = new CustomTestHeadlessGameHost(nameof(TestDefaultDirectory)))
using (var host = new CustomTestHeadlessGameHost())
{
try
{
string defaultStorageLocation = getDefaultLocationFor(nameof(TestDefaultDirectory));
var osu = loadOsu(host);
var osu = LoadOsuIntoHost(host);
var storage = osu.Dependencies.Get<Storage>();
Assert.That(storage.GetFullPath("."), Is.EqualTo(defaultStorageLocation));
@ -45,14 +44,14 @@ namespace osu.Game.Tests.NonVisual
{
string customPath = prepareCustomPath();
using (var host = new CustomTestHeadlessGameHost(nameof(TestCustomDirectory)))
using (var host = new CustomTestHeadlessGameHost())
{
using (var storageConfig = new StorageConfigManager(host.InitialStorage))
storageConfig.Set(StorageConfig.FullPath, customPath);
try
{
var osu = loadOsu(host);
var osu = LoadOsuIntoHost(host);
// switch to DI'd storage
var storage = osu.Dependencies.Get<Storage>();
@ -71,14 +70,14 @@ namespace osu.Game.Tests.NonVisual
{
string customPath = prepareCustomPath();
using (var host = new CustomTestHeadlessGameHost(nameof(TestSubDirectoryLookup)))
using (var host = new CustomTestHeadlessGameHost())
{
using (var storageConfig = new StorageConfigManager(host.InitialStorage))
storageConfig.Set(StorageConfig.FullPath, customPath);
try
{
var osu = loadOsu(host);
var osu = LoadOsuIntoHost(host);
// switch to DI'd storage
var storage = osu.Dependencies.Get<Storage>();
@ -104,13 +103,13 @@ namespace osu.Game.Tests.NonVisual
{
string customPath = prepareCustomPath();
using (HeadlessGameHost host = new CustomTestHeadlessGameHost(nameof(TestMigration)))
using (var host = new CustomTestHeadlessGameHost())
{
try
{
string defaultStorageLocation = getDefaultLocationFor(nameof(TestMigration));
var osu = loadOsu(host);
var osu = LoadOsuIntoHost(host);
var storage = osu.Dependencies.Get<Storage>();
var osuStorage = storage as MigratableStorage;
@ -168,11 +167,11 @@ namespace osu.Game.Tests.NonVisual
string customPath = prepareCustomPath();
string customPath2 = prepareCustomPath("-2");
using (HeadlessGameHost host = new CustomTestHeadlessGameHost(nameof(TestMigrationBetweenTwoTargets)))
using (var host = new CustomTestHeadlessGameHost())
{
try
{
var osu = loadOsu(host);
var osu = LoadOsuIntoHost(host);
const string database_filename = "client.db";
@ -197,11 +196,11 @@ namespace osu.Game.Tests.NonVisual
{
string customPath = prepareCustomPath();
using (HeadlessGameHost host = new CustomTestHeadlessGameHost(nameof(TestMigrationToSameTargetFails)))
using (var host = new CustomTestHeadlessGameHost())
{
try
{
var osu = loadOsu(host);
var osu = LoadOsuIntoHost(host);
Assert.DoesNotThrow(() => osu.Migrate(customPath));
Assert.Throws<ArgumentException>(() => osu.Migrate(customPath));
@ -218,11 +217,11 @@ namespace osu.Game.Tests.NonVisual
{
string customPath = prepareCustomPath();
using (HeadlessGameHost host = new CustomTestHeadlessGameHost(nameof(TestMigrationToNestedTargetFails)))
using (var host = new CustomTestHeadlessGameHost())
{
try
{
var osu = loadOsu(host);
var osu = LoadOsuIntoHost(host);
Assert.DoesNotThrow(() => osu.Migrate(customPath));
@ -247,11 +246,11 @@ namespace osu.Game.Tests.NonVisual
{
string customPath = prepareCustomPath();
using (HeadlessGameHost host = new CustomTestHeadlessGameHost(nameof(TestMigrationToSeeminglyNestedTarget)))
using (var host = new CustomTestHeadlessGameHost())
{
try
{
var osu = loadOsu(host);
var osu = LoadOsuIntoHost(host);
Assert.DoesNotThrow(() => osu.Migrate(customPath));
@ -271,25 +270,6 @@ namespace osu.Game.Tests.NonVisual
}
}
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);
}
private static string getDefaultLocationFor(string testTypeName)
{
string path = Path.Combine(RuntimeInfo.StartupDirectory, "headless", testTypeName);
@ -310,14 +290,14 @@ namespace osu.Game.Tests.NonVisual
return path;
}
public class CustomTestHeadlessGameHost : HeadlessGameHost
public class CustomTestHeadlessGameHost : CleanRunHeadlessGameHost
{
public Storage InitialStorage { get; }
public CustomTestHeadlessGameHost(string name)
: base(name)
public CustomTestHeadlessGameHost([CallerMemberName] string callingMethodName = @"")
: base(callingMethodName: callingMethodName)
{
string defaultStorageLocation = getDefaultLocationFor(name);
string defaultStorageLocation = getDefaultLocationFor(callingMethodName);
InitialStorage = new DesktopStorage(defaultStorageLocation, this);
InitialStorage.DeleteDirectory(string.Empty);