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
|
|
|
|
|
|
2018-06-26 17:24:34 +08:00
|
|
|
|
using System.Linq;
|
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-06-26 17:24:34 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
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-06-26 17:24:34 +08:00
|
|
|
|
using osu.Game.Rulesets;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
|
{
|
|
|
|
|
public abstract class OsuTestCase : TestCase
|
|
|
|
|
{
|
2018-05-28 16:55:41 +08:00
|
|
|
|
private readonly OsuTestBeatmap beatmap = new OsuTestBeatmap(new DummyWorkingBeatmap());
|
2018-06-06 19:16:20 +08:00
|
|
|
|
protected BindableBeatmap Beatmap => beatmap;
|
2018-05-23 16:37:39 +08:00
|
|
|
|
|
2018-06-26 17:59:13 +08:00
|
|
|
|
protected readonly Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
|
2018-06-26 17:24:34 +08:00
|
|
|
|
|
2018-06-06 19:25:40 +08:00
|
|
|
|
protected DependencyContainer Dependencies { get; private set; }
|
2018-05-23 16:37:39 +08:00
|
|
|
|
|
|
|
|
|
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent)
|
|
|
|
|
{
|
2018-06-06 19:25:40 +08:00
|
|
|
|
Dependencies = new DependencyContainer(base.CreateLocalDependencies(parent));
|
2018-05-23 17:52:09 +08:00
|
|
|
|
|
2018-06-06 19:25:40 +08:00
|
|
|
|
Dependencies.CacheAs<BindableBeatmap>(beatmap);
|
|
|
|
|
Dependencies.CacheAs<IBindableBeatmap>(beatmap);
|
2018-05-23 17:52:09 +08:00
|
|
|
|
|
2018-06-26 17:59:13 +08:00
|
|
|
|
Dependencies.CacheAs(Ruleset);
|
2018-07-02 14:07:13 +08:00
|
|
|
|
Dependencies.CacheAs<IBindable<RulesetInfo>>(Ruleset);
|
2018-06-26 17:24:34 +08:00
|
|
|
|
|
2018-06-06 19:25:40 +08:00
|
|
|
|
return Dependencies;
|
2018-05-23 17:52:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-28 16:55:41 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2018-06-26 17:24:34 +08:00
|
|
|
|
private void load(AudioManager audioManager, RulesetStore rulesets)
|
2018-05-28 16:55:41 +08:00
|
|
|
|
{
|
|
|
|
|
beatmap.SetAudioManager(audioManager);
|
2018-06-26 17:24:34 +08:00
|
|
|
|
|
2018-06-26 17:59:13 +08:00
|
|
|
|
Ruleset.Value = rulesets.AvailableRulesets.First();
|
2018-05-28 16:55:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-24 11:53:32 +08:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
2018-05-23 17:52:09 +08:00
|
|
|
|
{
|
2018-05-24 11:53:32 +08:00
|
|
|
|
base.Dispose(isDisposing);
|
2018-05-23 17:52:09 +08:00
|
|
|
|
|
2018-05-28 16:55:41 +08:00
|
|
|
|
if (beatmap != null)
|
2018-05-23 17:52:09 +08:00
|
|
|
|
{
|
2018-05-28 16:55:41 +08:00
|
|
|
|
beatmap.Disabled = true;
|
|
|
|
|
beatmap.Value.Track.Stop();
|
2018-05-23 17:52:09 +08:00
|
|
|
|
}
|
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
|
|
|
|
{
|
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
|
|
|
|
}
|
2018-05-28 16:55:41 +08:00
|
|
|
|
|
2018-06-06 19:16:20 +08:00
|
|
|
|
private class OsuTestBeatmap : BindableBeatmap
|
2018-05-28 16:55:41 +08:00
|
|
|
|
{
|
|
|
|
|
public OsuTestBeatmap(WorkingBeatmap defaultValue)
|
|
|
|
|
: base(defaultValue)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetAudioManager(AudioManager audioManager) => RegisterAudioManager(audioManager);
|
|
|
|
|
|
2018-06-06 19:16:20 +08:00
|
|
|
|
public override BindableBeatmap GetBoundCopy()
|
2018-05-28 16:55:41 +08:00
|
|
|
|
{
|
|
|
|
|
var copy = new OsuTestBeatmap(Default);
|
|
|
|
|
copy.BindTo(this);
|
|
|
|
|
return copy;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|