2018-04-13 17:19:50 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Reflection;
|
2018-05-23 16:37:39 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2018-05-23 17:52:09 +08:00
|
|
|
|
using osu.Framework.Audio;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Testing;
|
2018-05-23 16:37:39 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
|
{
|
|
|
|
|
public abstract class OsuTestCase : TestCase
|
|
|
|
|
{
|
2018-05-23 17:52:09 +08:00
|
|
|
|
protected GameBeatmap Beatmap { get; private set; }
|
2018-05-23 16:37:39 +08:00
|
|
|
|
|
|
|
|
|
private DependencyContainer dependencies;
|
|
|
|
|
|
|
|
|
|
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent)
|
|
|
|
|
{
|
2018-05-23 17:52:09 +08:00
|
|
|
|
// The beatmap is constructed here rather than load() because our children get dependencies injected before our load() runs
|
|
|
|
|
Beatmap = new GameBeatmap(new DummyWorkingBeatmap(), parent.Get<AudioManager>());
|
|
|
|
|
|
|
|
|
|
dependencies = new DependencyContainer(parent);
|
|
|
|
|
|
2018-05-23 16:37:39 +08:00
|
|
|
|
dependencies.CacheAs<IGameBeatmap>(Beatmap);
|
|
|
|
|
dependencies.Cache(Beatmap);
|
2018-05-23 17:52:09 +08:00
|
|
|
|
|
|
|
|
|
return dependencies;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Cleanup()
|
|
|
|
|
{
|
|
|
|
|
base.Cleanup();
|
|
|
|
|
|
|
|
|
|
if (Beatmap != null)
|
|
|
|
|
{
|
|
|
|
|
Beatmap.Disabled = true;
|
|
|
|
|
Beatmap.Value.Track.Stop();
|
|
|
|
|
}
|
2018-05-23 16:37:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-18 14:12:48 +08:00
|
|
|
|
protected override ITestCaseTestRunner CreateRunner() => new OsuTestCaseTestRunner();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-04-18 14:12:48 +08:00
|
|
|
|
public class OsuTestCaseTestRunner : OsuGameBase, ITestCaseTestRunner
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
protected override string MainResourceFile => File.Exists(base.MainResourceFile) ? base.MainResourceFile : Assembly.GetExecutingAssembly().Location;
|
|
|
|
|
|
2018-04-22 03:10:06 +08:00
|
|
|
|
private TestCaseTestRunner.TestRunner runner;
|
2018-04-18 14:12:48 +08:00
|
|
|
|
|
2018-04-22 03:10:06 +08:00
|
|
|
|
protected override void LoadAsyncComplete()
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-04-22 03:10:06 +08:00
|
|
|
|
// this has to be run here rather than LoadComplete because
|
|
|
|
|
// TestCase.cs is checking the IsLoaded state (on another thread) and expects
|
|
|
|
|
// the runner to be loaded at that point.
|
2018-04-21 17:15:27 +08:00
|
|
|
|
Add(runner = new TestCaseTestRunner.TestRunner());
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2018-04-18 14:12:48 +08:00
|
|
|
|
|
|
|
|
|
public void RunTestBlocking(TestCase test) => runner.RunTestBlocking(test);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|