mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 10:33:30 +08:00
Centralise import test helper methods
This commit is contained in:
parent
8e767729a2
commit
3cef93ee27
@ -28,7 +28,7 @@ using FileInfo = System.IO.FileInfo;
|
|||||||
namespace osu.Game.Tests.Beatmaps.IO
|
namespace osu.Game.Tests.Beatmaps.IO
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class ImportBeatmapTest
|
public class ImportBeatmapTest : ImportTest
|
||||||
{
|
{
|
||||||
[Test]
|
[Test]
|
||||||
public async Task TestImportWhenClosed()
|
public async Task TestImportWhenClosed()
|
||||||
@ -38,7 +38,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await LoadOszIntoOsu(loadOsu(host));
|
await LoadOszIntoOsu(LoadOsuIntoHost(host));
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@ -55,7 +55,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
|
|
||||||
var imported = await LoadOszIntoOsu(osu);
|
var imported = await LoadOszIntoOsu(osu);
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
|
|
||||||
var imported = await LoadOszIntoOsu(osu);
|
var imported = await LoadOszIntoOsu(osu);
|
||||||
var importedSecondTime = await LoadOszIntoOsu(osu);
|
var importedSecondTime = await LoadOszIntoOsu(osu);
|
||||||
@ -102,7 +102,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
|
|
||||||
var temp = TestResources.GetTestBeatmapForImport();
|
var temp = TestResources.GetTestBeatmapForImport();
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
|
|
||||||
var temp = TestResources.GetTestBeatmapForImport();
|
var temp = TestResources.GetTestBeatmapForImport();
|
||||||
|
|
||||||
@ -211,7 +211,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
|
|
||||||
var temp = TestResources.GetTestBeatmapForImport();
|
var temp = TestResources.GetTestBeatmapForImport();
|
||||||
|
|
||||||
@ -263,7 +263,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
|
|
||||||
var imported = await LoadOszIntoOsu(osu);
|
var imported = await LoadOszIntoOsu(osu);
|
||||||
|
|
||||||
@ -314,7 +314,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
Interlocked.Increment(ref loggedExceptionCount);
|
Interlocked.Increment(ref loggedExceptionCount);
|
||||||
};
|
};
|
||||||
|
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
var manager = osu.Dependencies.Get<BeatmapManager>();
|
var manager = osu.Dependencies.Get<BeatmapManager>();
|
||||||
|
|
||||||
// ReSharper disable once AccessToModifiedClosure
|
// ReSharper disable once AccessToModifiedClosure
|
||||||
@ -382,7 +382,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
|
|
||||||
var imported = await LoadOszIntoOsu(osu);
|
var imported = await LoadOszIntoOsu(osu);
|
||||||
|
|
||||||
@ -410,7 +410,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
|
|
||||||
var imported = await LoadOszIntoOsu(osu);
|
var imported = await LoadOszIntoOsu(osu);
|
||||||
|
|
||||||
@ -444,7 +444,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
|
|
||||||
var metadata = new BeatmapMetadata
|
var metadata = new BeatmapMetadata
|
||||||
{
|
{
|
||||||
@ -504,7 +504,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
Assert.IsTrue(host.IsPrimaryInstance);
|
Assert.IsTrue(host.IsPrimaryInstance);
|
||||||
Assert.IsFalse(client.IsPrimaryInstance);
|
Assert.IsFalse(client.IsPrimaryInstance);
|
||||||
|
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
|
|
||||||
var temp = TestResources.GetTestBeatmapForImport();
|
var temp = TestResources.GetTestBeatmapForImport();
|
||||||
|
|
||||||
@ -530,7 +530,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
var temp = TestResources.GetTestBeatmapForImport();
|
var temp = TestResources.GetTestBeatmapForImport();
|
||||||
using (File.OpenRead(temp))
|
using (File.OpenRead(temp))
|
||||||
await osu.Dependencies.Get<BeatmapManager>().Import(temp);
|
await osu.Dependencies.Get<BeatmapManager>().Import(temp);
|
||||||
@ -552,7 +552,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
|
|
||||||
var temp = TestResources.GetTestBeatmapForImport();
|
var temp = TestResources.GetTestBeatmapForImport();
|
||||||
|
|
||||||
@ -594,7 +594,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
|
|
||||||
var temp = TestResources.GetTestBeatmapForImport();
|
var temp = TestResources.GetTestBeatmapForImport();
|
||||||
|
|
||||||
@ -639,7 +639,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
|
|
||||||
var temp = TestResources.GetTestBeatmapForImport();
|
var temp = TestResources.GetTestBeatmapForImport();
|
||||||
|
|
||||||
@ -693,7 +693,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
var manager = osu.Dependencies.Get<BeatmapManager>();
|
var manager = osu.Dependencies.Get<BeatmapManager>();
|
||||||
|
|
||||||
var temp = TestResources.GetTestBeatmapForImport();
|
var temp = TestResources.GetTestBeatmapForImport();
|
||||||
@ -723,7 +723,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
var manager = osu.Dependencies.Get<BeatmapManager>();
|
var manager = osu.Dependencies.Get<BeatmapManager>();
|
||||||
|
|
||||||
var temp = TestResources.GetTestBeatmapForImport();
|
var temp = TestResources.GetTestBeatmapForImport();
|
||||||
@ -765,7 +765,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
var manager = osu.Dependencies.Get<BeatmapManager>();
|
var manager = osu.Dependencies.Get<BeatmapManager>();
|
||||||
|
|
||||||
var working = manager.CreateNew(new OsuRuleset().RulesetInfo, User.SYSTEM_USER);
|
var working = manager.CreateNew(new OsuRuleset().RulesetInfo, User.SYSTEM_USER);
|
||||||
@ -792,7 +792,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
var manager = osu.Dependencies.Get<BeatmapManager>();
|
var manager = osu.Dependencies.Get<BeatmapManager>();
|
||||||
|
|
||||||
var working = manager.CreateNew(new OsuRuleset().RulesetInfo, User.SYSTEM_USER);
|
var working = manager.CreateNew(new OsuRuleset().RulesetInfo, User.SYSTEM_USER);
|
||||||
@ -863,14 +863,6 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
Assert.AreEqual(expected, osu.Dependencies.Get<FileStore>().QueryFiles(f => f.ReferenceCount == 1).Count());
|
Assert.AreEqual(expected, osu.Dependencies.Get<FileStore>().QueryFiles(f => f.ReferenceCount == 1).Count());
|
||||||
}
|
}
|
||||||
|
|
||||||
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 ensureLoaded(OsuGameBase osu, int timeout = 60000)
|
private static void ensureLoaded(OsuGameBase osu, int timeout = 60000)
|
||||||
{
|
{
|
||||||
IEnumerable<BeatmapSetInfo> resultSets = null;
|
IEnumerable<BeatmapSetInfo> resultSets = null;
|
||||||
|
@ -4,18 +4,15 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game.Collections;
|
|
||||||
using osu.Game.Tests.Resources;
|
using osu.Game.Tests.Resources;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Collections.IO
|
namespace osu.Game.Tests.Collections.IO
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class ImportCollectionsTest
|
public class ImportCollectionsTest : ImportTest
|
||||||
{
|
{
|
||||||
[Test]
|
[Test]
|
||||||
public async Task TestImportEmptyDatabase()
|
public async Task TestImportEmptyDatabase()
|
||||||
@ -24,7 +21,7 @@ namespace osu.Game.Tests.Collections.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
|
|
||||||
await osu.CollectionManager.Import(new MemoryStream());
|
await osu.CollectionManager.Import(new MemoryStream());
|
||||||
|
|
||||||
@ -44,7 +41,7 @@ namespace osu.Game.Tests.Collections.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
|
|
||||||
await osu.CollectionManager.Import(TestResources.OpenResource("Collections/collections.db"));
|
await osu.CollectionManager.Import(TestResources.OpenResource("Collections/collections.db"));
|
||||||
|
|
||||||
@ -70,7 +67,7 @@ namespace osu.Game.Tests.Collections.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host, true);
|
var osu = LoadOsuIntoHost(host, true);
|
||||||
|
|
||||||
await osu.CollectionManager.Import(TestResources.OpenResource("Collections/collections.db"));
|
await osu.CollectionManager.Import(TestResources.OpenResource("Collections/collections.db"));
|
||||||
|
|
||||||
@ -101,7 +98,7 @@ namespace osu.Game.Tests.Collections.IO
|
|||||||
{
|
{
|
||||||
AppDomain.CurrentDomain.UnhandledException += setException;
|
AppDomain.CurrentDomain.UnhandledException += setException;
|
||||||
|
|
||||||
var osu = loadOsu(host, true);
|
var osu = LoadOsuIntoHost(host, true);
|
||||||
|
|
||||||
using (var ms = new MemoryStream())
|
using (var ms = new MemoryStream())
|
||||||
{
|
{
|
||||||
@ -135,7 +132,7 @@ namespace osu.Game.Tests.Collections.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host, true);
|
var osu = LoadOsuIntoHost(host, true);
|
||||||
|
|
||||||
await osu.CollectionManager.Import(TestResources.OpenResource("Collections/collections.db"));
|
await osu.CollectionManager.Import(TestResources.OpenResource("Collections/collections.db"));
|
||||||
|
|
||||||
@ -156,7 +153,7 @@ namespace osu.Game.Tests.Collections.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host, true);
|
var osu = LoadOsuIntoHost(host, true);
|
||||||
|
|
||||||
Assert.That(osu.CollectionManager.Collections.Count, Is.EqualTo(2));
|
Assert.That(osu.CollectionManager.Collections.Count, Is.EqualTo(2));
|
||||||
|
|
||||||
@ -172,50 +169,5 @@ namespace osu.Game.Tests.Collections.IO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private TestOsuGameBase loadOsu(GameHost host, bool withBeatmap = false)
|
|
||||||
{
|
|
||||||
var osu = new TestOsuGameBase(withBeatmap);
|
|
||||||
|
|
||||||
#pragma warning disable 4014
|
|
||||||
Task.Run(() => host.Run(osu));
|
|
||||||
#pragma warning restore 4014
|
|
||||||
|
|
||||||
waitForOrAssert(() => osu.IsLoaded, @"osu! failed to start in a reasonable amount of time");
|
|
||||||
|
|
||||||
return osu;
|
|
||||||
}
|
|
||||||
|
|
||||||
private 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 class TestOsuGameBase : OsuGameBase
|
|
||||||
{
|
|
||||||
public CollectionManager CollectionManager { get; private set; }
|
|
||||||
|
|
||||||
private readonly bool withBeatmap;
|
|
||||||
|
|
||||||
public TestOsuGameBase(bool withBeatmap)
|
|
||||||
{
|
|
||||||
this.withBeatmap = withBeatmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load()
|
|
||||||
{
|
|
||||||
// Beatmap must be imported before the collection manager is loaded.
|
|
||||||
if (withBeatmap)
|
|
||||||
BeatmapManager.Import(TestResources.GetTestBeatmapForImport()).Wait();
|
|
||||||
|
|
||||||
AddInternal(CollectionManager = new CollectionManager(Storage));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
66
osu.Game.Tests/ImportTest.cs
Normal file
66
osu.Game.Tests/ImportTest.cs
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
// 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.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Platform;
|
||||||
|
using osu.Game.Collections;
|
||||||
|
using osu.Game.Tests.Resources;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests
|
||||||
|
{
|
||||||
|
public abstract class ImportTest
|
||||||
|
{
|
||||||
|
protected virtual TestOsuGameBase LoadOsuIntoHost(GameHost host, bool withBeatmap = false)
|
||||||
|
{
|
||||||
|
var osu = new TestOsuGameBase(withBeatmap);
|
||||||
|
Task.Run(() => host.Run(osu));
|
||||||
|
|
||||||
|
waitForOrAssert(() => osu.IsLoaded, @"osu! failed to start in a reasonable amount of time");
|
||||||
|
|
||||||
|
bool ready = false;
|
||||||
|
// wait for two update frames to be executed. this ensures that all components have had a change to run LoadComplete and hopefully avoid
|
||||||
|
// database access (GlobalActionContainer is one to do this).
|
||||||
|
host.UpdateThread.Scheduler.Add(() => host.UpdateThread.Scheduler.Add(() => ready = true));
|
||||||
|
|
||||||
|
waitForOrAssert(() => ready, @"osu! failed to start in a reasonable amount of time");
|
||||||
|
|
||||||
|
return osu;
|
||||||
|
}
|
||||||
|
|
||||||
|
private 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TestOsuGameBase : OsuGameBase
|
||||||
|
{
|
||||||
|
public CollectionManager CollectionManager { get; private set; }
|
||||||
|
|
||||||
|
private readonly bool withBeatmap;
|
||||||
|
|
||||||
|
public TestOsuGameBase(bool withBeatmap)
|
||||||
|
{
|
||||||
|
this.withBeatmap = withBeatmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
// Beatmap must be imported before the collection manager is loaded.
|
||||||
|
if (withBeatmap)
|
||||||
|
BeatmapManager.Import(TestResources.GetTestBeatmapForImport()).Wait();
|
||||||
|
|
||||||
|
AddInternal(CollectionManager = new CollectionManager(Storage));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,8 +5,6 @@ using System;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework;
|
using osu.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
@ -18,7 +16,7 @@ using osu.Game.IO;
|
|||||||
namespace osu.Game.Tests.NonVisual
|
namespace osu.Game.Tests.NonVisual
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class CustomDataDirectoryTest
|
public class CustomDataDirectoryTest : ImportTest
|
||||||
{
|
{
|
||||||
[Test]
|
[Test]
|
||||||
public void TestDefaultDirectory()
|
public void TestDefaultDirectory()
|
||||||
@ -29,7 +27,7 @@ namespace osu.Game.Tests.NonVisual
|
|||||||
{
|
{
|
||||||
string defaultStorageLocation = getDefaultLocationFor(nameof(TestDefaultDirectory));
|
string defaultStorageLocation = getDefaultLocationFor(nameof(TestDefaultDirectory));
|
||||||
|
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
var storage = osu.Dependencies.Get<Storage>();
|
var storage = osu.Dependencies.Get<Storage>();
|
||||||
|
|
||||||
Assert.That(storage.GetFullPath("."), Is.EqualTo(defaultStorageLocation));
|
Assert.That(storage.GetFullPath("."), Is.EqualTo(defaultStorageLocation));
|
||||||
@ -53,7 +51,7 @@ namespace osu.Game.Tests.NonVisual
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
|
|
||||||
// switch to DI'd storage
|
// switch to DI'd storage
|
||||||
var storage = osu.Dependencies.Get<Storage>();
|
var storage = osu.Dependencies.Get<Storage>();
|
||||||
@ -79,7 +77,7 @@ namespace osu.Game.Tests.NonVisual
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
|
|
||||||
// switch to DI'd storage
|
// switch to DI'd storage
|
||||||
var storage = osu.Dependencies.Get<Storage>();
|
var storage = osu.Dependencies.Get<Storage>();
|
||||||
@ -111,7 +109,7 @@ namespace osu.Game.Tests.NonVisual
|
|||||||
{
|
{
|
||||||
string defaultStorageLocation = getDefaultLocationFor(nameof(TestMigration));
|
string defaultStorageLocation = getDefaultLocationFor(nameof(TestMigration));
|
||||||
|
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
var storage = osu.Dependencies.Get<Storage>();
|
var storage = osu.Dependencies.Get<Storage>();
|
||||||
|
|
||||||
// Store the current storage's path. We'll need to refer to this for assertions in the original directory after the migration completes.
|
// Store the current storage's path. We'll need to refer to this for assertions in the original directory after the migration completes.
|
||||||
@ -170,7 +168,7 @@ namespace osu.Game.Tests.NonVisual
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
|
|
||||||
const string database_filename = "client.db";
|
const string database_filename = "client.db";
|
||||||
|
|
||||||
@ -199,7 +197,7 @@ namespace osu.Game.Tests.NonVisual
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
|
|
||||||
Assert.DoesNotThrow(() => osu.Migrate(customPath));
|
Assert.DoesNotThrow(() => osu.Migrate(customPath));
|
||||||
Assert.Throws<ArgumentException>(() => osu.Migrate(customPath));
|
Assert.Throws<ArgumentException>(() => osu.Migrate(customPath));
|
||||||
@ -220,7 +218,7 @@ namespace osu.Game.Tests.NonVisual
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
|
|
||||||
Assert.DoesNotThrow(() => osu.Migrate(customPath));
|
Assert.DoesNotThrow(() => osu.Migrate(customPath));
|
||||||
|
|
||||||
@ -249,7 +247,7 @@ namespace osu.Game.Tests.NonVisual
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
|
|
||||||
Assert.DoesNotThrow(() => osu.Migrate(customPath));
|
Assert.DoesNotThrow(() => osu.Migrate(customPath));
|
||||||
|
|
||||||
@ -269,33 +267,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");
|
|
||||||
|
|
||||||
bool ready = false;
|
|
||||||
// wait for two update frames to be executed. this ensures that all components have had a change to run LoadComplete and hopefully avoid
|
|
||||||
// database access (GlobalActionContainer is one to do this).
|
|
||||||
host.UpdateThread.Scheduler.Add(() => host.UpdateThread.Scheduler.Add(() => ready = true));
|
|
||||||
|
|
||||||
waitForOrAssert(() => ready, @"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)
|
private static string getDefaultLocationFor(string testTypeName)
|
||||||
{
|
{
|
||||||
string path = Path.Combine(RuntimeInfo.StartupDirectory, "headless", testTypeName);
|
string path = Path.Combine(RuntimeInfo.StartupDirectory, "headless", testTypeName);
|
||||||
|
@ -5,7 +5,6 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
@ -17,12 +16,11 @@ using osu.Game.Rulesets.Osu;
|
|||||||
using osu.Game.Rulesets.Osu.Mods;
|
using osu.Game.Rulesets.Osu.Mods;
|
||||||
using osu.Game.Rulesets.Scoring;
|
using osu.Game.Rulesets.Scoring;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
using osu.Game.Tests.Resources;
|
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Scores.IO
|
namespace osu.Game.Tests.Scores.IO
|
||||||
{
|
{
|
||||||
public class ImportScoreTest
|
public class ImportScoreTest : ImportTest
|
||||||
{
|
{
|
||||||
[Test]
|
[Test]
|
||||||
public async Task TestBasicImport()
|
public async Task TestBasicImport()
|
||||||
@ -31,7 +29,7 @@ namespace osu.Game.Tests.Scores.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = await loadOsu(host);
|
var osu = LoadOsuIntoHost(host, true);
|
||||||
|
|
||||||
var toImport = new ScoreInfo
|
var toImport = new ScoreInfo
|
||||||
{
|
{
|
||||||
@ -45,7 +43,7 @@ namespace osu.Game.Tests.Scores.IO
|
|||||||
OnlineScoreID = 12345,
|
OnlineScoreID = 12345,
|
||||||
};
|
};
|
||||||
|
|
||||||
var imported = await loadIntoOsu(osu, toImport);
|
var imported = await loadScoreIntoOsu(osu, toImport);
|
||||||
|
|
||||||
Assert.AreEqual(toImport.Rank, imported.Rank);
|
Assert.AreEqual(toImport.Rank, imported.Rank);
|
||||||
Assert.AreEqual(toImport.TotalScore, imported.TotalScore);
|
Assert.AreEqual(toImport.TotalScore, imported.TotalScore);
|
||||||
@ -70,14 +68,14 @@ namespace osu.Game.Tests.Scores.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = await loadOsu(host);
|
var osu = LoadOsuIntoHost(host, true);
|
||||||
|
|
||||||
var toImport = new ScoreInfo
|
var toImport = new ScoreInfo
|
||||||
{
|
{
|
||||||
Mods = new Mod[] { new OsuModHardRock(), new OsuModDoubleTime() },
|
Mods = new Mod[] { new OsuModHardRock(), new OsuModDoubleTime() },
|
||||||
};
|
};
|
||||||
|
|
||||||
var imported = await loadIntoOsu(osu, toImport);
|
var imported = await loadScoreIntoOsu(osu, toImport);
|
||||||
|
|
||||||
Assert.IsTrue(imported.Mods.Any(m => m is OsuModHardRock));
|
Assert.IsTrue(imported.Mods.Any(m => m is OsuModHardRock));
|
||||||
Assert.IsTrue(imported.Mods.Any(m => m is OsuModDoubleTime));
|
Assert.IsTrue(imported.Mods.Any(m => m is OsuModDoubleTime));
|
||||||
@ -96,7 +94,7 @@ namespace osu.Game.Tests.Scores.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = await loadOsu(host);
|
var osu = LoadOsuIntoHost(host, true);
|
||||||
|
|
||||||
var toImport = new ScoreInfo
|
var toImport = new ScoreInfo
|
||||||
{
|
{
|
||||||
@ -107,7 +105,7 @@ namespace osu.Game.Tests.Scores.IO
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var imported = await loadIntoOsu(osu, toImport);
|
var imported = await loadScoreIntoOsu(osu, toImport);
|
||||||
|
|
||||||
Assert.AreEqual(toImport.Statistics[HitResult.Perfect], imported.Statistics[HitResult.Perfect]);
|
Assert.AreEqual(toImport.Statistics[HitResult.Perfect], imported.Statistics[HitResult.Perfect]);
|
||||||
Assert.AreEqual(toImport.Statistics[HitResult.Miss], imported.Statistics[HitResult.Miss]);
|
Assert.AreEqual(toImport.Statistics[HitResult.Miss], imported.Statistics[HitResult.Miss]);
|
||||||
@ -126,7 +124,7 @@ namespace osu.Game.Tests.Scores.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = await loadOsu(host);
|
var osu = LoadOsuIntoHost(host, true);
|
||||||
|
|
||||||
var toImport = new ScoreInfo
|
var toImport = new ScoreInfo
|
||||||
{
|
{
|
||||||
@ -138,7 +136,7 @@ namespace osu.Game.Tests.Scores.IO
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var imported = await loadIntoOsu(osu, toImport);
|
var imported = await loadScoreIntoOsu(osu, toImport);
|
||||||
|
|
||||||
var beatmapManager = osu.Dependencies.Get<BeatmapManager>();
|
var beatmapManager = osu.Dependencies.Get<BeatmapManager>();
|
||||||
var scoreManager = osu.Dependencies.Get<ScoreManager>();
|
var scoreManager = osu.Dependencies.Get<ScoreManager>();
|
||||||
@ -146,7 +144,7 @@ namespace osu.Game.Tests.Scores.IO
|
|||||||
beatmapManager.Delete(beatmapManager.QueryBeatmapSet(s => s.Beatmaps.Any(b => b.ID == imported.Beatmap.ID)));
|
beatmapManager.Delete(beatmapManager.QueryBeatmapSet(s => s.Beatmaps.Any(b => b.ID == imported.Beatmap.ID)));
|
||||||
Assert.That(scoreManager.Query(s => s.ID == imported.ID).DeletePending, Is.EqualTo(true));
|
Assert.That(scoreManager.Query(s => s.ID == imported.ID).DeletePending, Is.EqualTo(true));
|
||||||
|
|
||||||
var secondImport = await loadIntoOsu(osu, imported);
|
var secondImport = await loadScoreIntoOsu(osu, imported);
|
||||||
Assert.That(secondImport, Is.Null);
|
Assert.That(secondImport, Is.Null);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
@ -163,9 +161,9 @@ namespace osu.Game.Tests.Scores.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = await loadOsu(host);
|
var osu = LoadOsuIntoHost(host, true);
|
||||||
|
|
||||||
await loadIntoOsu(osu, new ScoreInfo { OnlineScoreID = 2 }, new TestArchiveReader());
|
await loadScoreIntoOsu(osu, new ScoreInfo { OnlineScoreID = 2 }, new TestArchiveReader());
|
||||||
|
|
||||||
var scoreManager = osu.Dependencies.Get<ScoreManager>();
|
var scoreManager = osu.Dependencies.Get<ScoreManager>();
|
||||||
|
|
||||||
@ -179,7 +177,7 @@ namespace osu.Game.Tests.Scores.IO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<ScoreInfo> loadIntoOsu(OsuGameBase osu, ScoreInfo score, ArchiveReader archive = null)
|
private async Task<ScoreInfo> loadScoreIntoOsu(OsuGameBase osu, ScoreInfo score, ArchiveReader archive = null)
|
||||||
{
|
{
|
||||||
var beatmapManager = osu.Dependencies.Get<BeatmapManager>();
|
var beatmapManager = osu.Dependencies.Get<BeatmapManager>();
|
||||||
|
|
||||||
@ -192,33 +190,6 @@ namespace osu.Game.Tests.Scores.IO
|
|||||||
return scoreManager.GetAllUsableScores().FirstOrDefault();
|
return scoreManager.GetAllUsableScores().FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<OsuGameBase> loadOsu(GameHost host)
|
|
||||||
{
|
|
||||||
var osu = new OsuGameBase();
|
|
||||||
|
|
||||||
#pragma warning disable 4014
|
|
||||||
Task.Run(() => host.Run(osu));
|
|
||||||
#pragma warning restore 4014
|
|
||||||
|
|
||||||
waitForOrAssert(() => osu.IsLoaded, @"osu! failed to start in a reasonable amount of time");
|
|
||||||
|
|
||||||
var beatmapFile = TestResources.GetTestBeatmapForImport();
|
|
||||||
var beatmapManager = osu.Dependencies.Get<BeatmapManager>();
|
|
||||||
await beatmapManager.Import(beatmapFile);
|
|
||||||
|
|
||||||
return osu;
|
|
||||||
}
|
|
||||||
|
|
||||||
private 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 class TestArchiveReader : ArchiveReader
|
private class TestArchiveReader : ArchiveReader
|
||||||
{
|
{
|
||||||
public TestArchiveReader()
|
public TestArchiveReader()
|
||||||
|
@ -4,20 +4,17 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game.Beatmaps;
|
|
||||||
using osu.Game.IO.Archives;
|
using osu.Game.IO.Archives;
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
using osu.Game.Tests.Resources;
|
|
||||||
using SharpCompress.Archives.Zip;
|
using SharpCompress.Archives.Zip;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Skins.IO
|
namespace osu.Game.Tests.Skins.IO
|
||||||
{
|
{
|
||||||
public class ImportSkinTest
|
public class ImportSkinTest : ImportTest
|
||||||
{
|
{
|
||||||
[Test]
|
[Test]
|
||||||
public async Task TestBasicImport()
|
public async Task TestBasicImport()
|
||||||
@ -26,9 +23,9 @@ namespace osu.Game.Tests.Skins.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = await loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
|
|
||||||
var imported = await loadIntoOsu(osu, new ZipArchiveReader(createOsk("test skin", "skinner"), "skin.osk"));
|
var imported = await loadSkinIntoOsu(osu, new ZipArchiveReader(createOsk("test skin", "skinner"), "skin.osk"));
|
||||||
|
|
||||||
Assert.That(imported.Name, Is.EqualTo("test skin"));
|
Assert.That(imported.Name, Is.EqualTo("test skin"));
|
||||||
Assert.That(imported.Creator, Is.EqualTo("skinner"));
|
Assert.That(imported.Creator, Is.EqualTo("skinner"));
|
||||||
@ -47,10 +44,10 @@ namespace osu.Game.Tests.Skins.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = await loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
|
|
||||||
var imported = await loadIntoOsu(osu, new ZipArchiveReader(createOsk("test skin", "skinner"), "skin.osk"));
|
var imported = await loadSkinIntoOsu(osu, new ZipArchiveReader(createOsk("test skin", "skinner"), "skin.osk"));
|
||||||
var imported2 = await loadIntoOsu(osu, new ZipArchiveReader(createOsk("test skin", "skinner"), "skin2.osk"));
|
var imported2 = await loadSkinIntoOsu(osu, new ZipArchiveReader(createOsk("test skin", "skinner"), "skin2.osk"));
|
||||||
|
|
||||||
Assert.That(imported2.ID, Is.Not.EqualTo(imported.ID));
|
Assert.That(imported2.ID, Is.Not.EqualTo(imported.ID));
|
||||||
Assert.That(osu.Dependencies.Get<SkinManager>().GetAllUserSkins().Count, Is.EqualTo(1));
|
Assert.That(osu.Dependencies.Get<SkinManager>().GetAllUserSkins().Count, Is.EqualTo(1));
|
||||||
@ -72,11 +69,11 @@ namespace osu.Game.Tests.Skins.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = await loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
|
|
||||||
// if a user downloads two skins that do have skin.ini files but don't have any creator metadata in the skin.ini, they should both import separately just for safety.
|
// if a user downloads two skins that do have skin.ini files but don't have any creator metadata in the skin.ini, they should both import separately just for safety.
|
||||||
var imported = await loadIntoOsu(osu, new ZipArchiveReader(createOsk(string.Empty, string.Empty), "download.osk"));
|
var imported = await loadSkinIntoOsu(osu, new ZipArchiveReader(createOsk(string.Empty, string.Empty), "download.osk"));
|
||||||
var imported2 = await loadIntoOsu(osu, new ZipArchiveReader(createOsk(string.Empty, string.Empty), "download.osk"));
|
var imported2 = await loadSkinIntoOsu(osu, new ZipArchiveReader(createOsk(string.Empty, string.Empty), "download.osk"));
|
||||||
|
|
||||||
Assert.That(imported2.ID, Is.Not.EqualTo(imported.ID));
|
Assert.That(imported2.ID, Is.Not.EqualTo(imported.ID));
|
||||||
Assert.That(osu.Dependencies.Get<SkinManager>().GetAllUserSkins().Count, Is.EqualTo(2));
|
Assert.That(osu.Dependencies.Get<SkinManager>().GetAllUserSkins().Count, Is.EqualTo(2));
|
||||||
@ -98,10 +95,10 @@ namespace osu.Game.Tests.Skins.IO
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var osu = await loadOsu(host);
|
var osu = LoadOsuIntoHost(host);
|
||||||
|
|
||||||
var imported = await loadIntoOsu(osu, new ZipArchiveReader(createOsk("test skin v2", "skinner"), "skin.osk"));
|
var imported = await loadSkinIntoOsu(osu, new ZipArchiveReader(createOsk("test skin v2", "skinner"), "skin.osk"));
|
||||||
var imported2 = await loadIntoOsu(osu, new ZipArchiveReader(createOsk("test skin v2.1", "skinner"), "skin2.osk"));
|
var imported2 = await loadSkinIntoOsu(osu, new ZipArchiveReader(createOsk("test skin v2.1", "skinner"), "skin2.osk"));
|
||||||
|
|
||||||
Assert.That(imported2.ID, Is.Not.EqualTo(imported.ID));
|
Assert.That(imported2.ID, Is.Not.EqualTo(imported.ID));
|
||||||
Assert.That(osu.Dependencies.Get<SkinManager>().GetAllUserSkins().Count, Is.EqualTo(2));
|
Assert.That(osu.Dependencies.Get<SkinManager>().GetAllUserSkins().Count, Is.EqualTo(2));
|
||||||
@ -141,37 +138,10 @@ namespace osu.Game.Tests.Skins.IO
|
|||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<SkinInfo> loadIntoOsu(OsuGameBase osu, ArchiveReader archive = null)
|
private async Task<SkinInfo> loadSkinIntoOsu(OsuGameBase osu, ArchiveReader archive = null)
|
||||||
{
|
{
|
||||||
var skinManager = osu.Dependencies.Get<SkinManager>();
|
var skinManager = osu.Dependencies.Get<SkinManager>();
|
||||||
return await skinManager.Import(archive);
|
return await skinManager.Import(archive);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<OsuGameBase> loadOsu(GameHost host)
|
|
||||||
{
|
|
||||||
var osu = new OsuGameBase();
|
|
||||||
|
|
||||||
#pragma warning disable 4014
|
|
||||||
Task.Run(() => host.Run(osu));
|
|
||||||
#pragma warning restore 4014
|
|
||||||
|
|
||||||
waitForOrAssert(() => osu.IsLoaded, @"osu! failed to start in a reasonable amount of time");
|
|
||||||
|
|
||||||
var beatmapFile = TestResources.GetTestBeatmapForImport();
|
|
||||||
var beatmapManager = osu.Dependencies.Get<BeatmapManager>();
|
|
||||||
await beatmapManager.Import(beatmapFile);
|
|
||||||
|
|
||||||
return osu;
|
|
||||||
}
|
|
||||||
|
|
||||||
private 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user