2020-09-24 13:46:28 +08: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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2020-09-24 13:46:28 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
2021-12-23 17:33:17 +08:00
|
|
|
using System.Threading;
|
2020-09-24 13:46:28 +08:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Audio.Sample;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-07-30 00:29:11 +08:00
|
|
|
using osu.Framework.Graphics.Rendering;
|
2021-06-21 04:11:10 +08:00
|
|
|
using osu.Framework.Graphics.Shaders;
|
2020-09-24 13:46:28 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2021-06-22 18:17:34 +08:00
|
|
|
using osu.Framework.IO.Stores;
|
2022-07-30 00:29:11 +08:00
|
|
|
using osu.Framework.Platform;
|
2020-09-25 11:43:41 +08:00
|
|
|
using osu.Framework.Testing;
|
2020-09-24 13:46:28 +08:00
|
|
|
using osu.Game.Rulesets.Osu;
|
|
|
|
using osu.Game.Rulesets.UI;
|
|
|
|
using osu.Game.Tests.Visual;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Rulesets
|
|
|
|
{
|
2020-09-25 11:43:41 +08:00
|
|
|
[HeadlessTest]
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class TestSceneDrawableRulesetDependencies : OsuTestScene
|
2020-09-24 13:46:28 +08:00
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void TestDisposalDoesNotDisposeParentStores()
|
|
|
|
{
|
|
|
|
DrawableWithDependencies drawable = null;
|
|
|
|
TestTextureStore textureStore = null;
|
|
|
|
TestSampleStore sampleStore = null;
|
2021-06-21 04:11:10 +08:00
|
|
|
TestShaderManager shaderManager = null;
|
2020-09-24 13:46:28 +08:00
|
|
|
|
|
|
|
AddStep("add dependencies", () =>
|
|
|
|
{
|
|
|
|
Child = drawable = new DrawableWithDependencies();
|
|
|
|
textureStore = drawable.ParentTextureStore;
|
|
|
|
sampleStore = drawable.ParentSampleStore;
|
2021-06-21 04:11:10 +08:00
|
|
|
shaderManager = drawable.ParentShaderManager;
|
2020-09-24 13:46:28 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("clear children", Clear);
|
|
|
|
AddUntilStep("wait for disposal", () => drawable.IsDisposed);
|
|
|
|
|
|
|
|
AddStep("GC", () =>
|
|
|
|
{
|
|
|
|
drawable = null;
|
|
|
|
|
|
|
|
GC.Collect();
|
|
|
|
GC.WaitForPendingFinalizers();
|
|
|
|
});
|
|
|
|
|
|
|
|
AddAssert("parent texture store not disposed", () => !textureStore.IsDisposed);
|
|
|
|
AddAssert("parent sample store not disposed", () => !sampleStore.IsDisposed);
|
2021-06-21 04:11:10 +08:00
|
|
|
AddAssert("parent shader manager not disposed", () => !shaderManager.IsDisposed);
|
2020-09-24 13:46:28 +08:00
|
|
|
}
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
private partial class DrawableWithDependencies : CompositeDrawable
|
2020-09-24 13:46:28 +08:00
|
|
|
{
|
|
|
|
public TestTextureStore ParentTextureStore { get; private set; }
|
|
|
|
public TestSampleStore ParentSampleStore { get; private set; }
|
2021-06-21 04:11:10 +08:00
|
|
|
public TestShaderManager ParentShaderManager { get; private set; }
|
2020-09-24 13:46:28 +08:00
|
|
|
|
|
|
|
public DrawableWithDependencies()
|
|
|
|
{
|
|
|
|
InternalChild = new Box { RelativeSizeAxes = Axes.Both };
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
|
|
|
{
|
|
|
|
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
|
|
|
|
2022-08-02 18:50:57 +08:00
|
|
|
dependencies.CacheAs<TextureStore>(ParentTextureStore = new TestTextureStore(parent.Get<GameHost>().Renderer));
|
2020-09-24 13:46:28 +08:00
|
|
|
dependencies.CacheAs<ISampleStore>(ParentSampleStore = new TestSampleStore());
|
2023-03-14 19:37:50 +08:00
|
|
|
dependencies.CacheAs<ShaderManager>(ParentShaderManager = new TestShaderManager(parent.Get<GameHost>().Renderer, parent.Get<ShaderManager>()));
|
2020-09-24 13:46:28 +08:00
|
|
|
|
|
|
|
return new DrawableRulesetDependencies(new OsuRuleset(), dependencies);
|
|
|
|
}
|
|
|
|
|
|
|
|
public new bool IsDisposed { get; private set; }
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
IsDisposed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class TestTextureStore : TextureStore
|
|
|
|
{
|
2022-08-02 18:50:57 +08:00
|
|
|
public TestTextureStore(IRenderer renderer)
|
|
|
|
: base(renderer)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-09-24 13:46:28 +08:00
|
|
|
public override Texture Get(string name, WrapMode wrapModeS, WrapMode wrapModeT) => null;
|
|
|
|
|
|
|
|
public bool IsDisposed { get; private set; }
|
|
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
{
|
|
|
|
base.Dispose(disposing);
|
|
|
|
IsDisposed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class TestSampleStore : ISampleStore
|
|
|
|
{
|
|
|
|
public bool IsDisposed { get; private set; }
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
IsDisposed = true;
|
|
|
|
}
|
|
|
|
|
2021-01-19 16:11:40 +08:00
|
|
|
public Sample Get(string name) => null;
|
2020-09-24 13:46:28 +08:00
|
|
|
|
2021-12-23 17:33:17 +08:00
|
|
|
public Task<Sample> GetAsync(string name, CancellationToken cancellationToken = default) => null;
|
2020-09-24 13:46:28 +08:00
|
|
|
|
|
|
|
public Stream GetStream(string name) => null;
|
|
|
|
|
|
|
|
public IEnumerable<string> GetAvailableResources() => throw new NotImplementedException();
|
|
|
|
|
|
|
|
public BindableNumber<double> Volume => throw new NotImplementedException();
|
|
|
|
public BindableNumber<double> Balance => throw new NotImplementedException();
|
|
|
|
public BindableNumber<double> Frequency => throw new NotImplementedException();
|
|
|
|
public BindableNumber<double> Tempo => throw new NotImplementedException();
|
|
|
|
|
2021-02-22 13:18:52 +08:00
|
|
|
public void BindAdjustments(IAggregateAudioAdjustment component) => throw new NotImplementedException();
|
|
|
|
|
|
|
|
public void UnbindAdjustments(IAggregateAudioAdjustment component) => throw new NotImplementedException();
|
|
|
|
|
2021-02-18 14:42:26 +08:00
|
|
|
public void AddAdjustment(AdjustableProperty type, IBindable<double> adjustBindable) => throw new NotImplementedException();
|
2020-09-24 13:46:28 +08:00
|
|
|
|
2021-02-18 14:42:26 +08:00
|
|
|
public void RemoveAdjustment(AdjustableProperty type, IBindable<double> adjustBindable) => throw new NotImplementedException();
|
2020-09-24 13:46:28 +08:00
|
|
|
|
|
|
|
public void RemoveAllAdjustments(AdjustableProperty type) => throw new NotImplementedException();
|
|
|
|
|
|
|
|
public IBindable<double> AggregateVolume => throw new NotImplementedException();
|
|
|
|
public IBindable<double> AggregateBalance => throw new NotImplementedException();
|
|
|
|
public IBindable<double> AggregateFrequency => throw new NotImplementedException();
|
|
|
|
public IBindable<double> AggregateTempo => throw new NotImplementedException();
|
|
|
|
|
|
|
|
public int PlaybackConcurrency { get; set; }
|
2023-01-29 04:16:22 +08:00
|
|
|
|
|
|
|
public void AddExtension(string extension) => throw new NotImplementedException();
|
2020-09-24 13:46:28 +08:00
|
|
|
}
|
2021-06-21 04:11:10 +08:00
|
|
|
|
|
|
|
private class TestShaderManager : ShaderManager
|
|
|
|
{
|
2023-03-14 19:37:50 +08:00
|
|
|
private readonly ShaderManager parentManager;
|
|
|
|
|
|
|
|
public TestShaderManager(IRenderer renderer, ShaderManager parentManager)
|
2022-07-30 00:29:11 +08:00
|
|
|
: base(renderer, new ResourceStore<byte[]>())
|
2021-06-22 18:17:34 +08:00
|
|
|
{
|
2023-03-14 19:37:50 +08:00
|
|
|
this.parentManager = parentManager;
|
2021-06-22 18:17:34 +08:00
|
|
|
}
|
|
|
|
|
2023-03-14 19:37:50 +08:00
|
|
|
public override byte[] LoadRaw(string name) => parentManager.LoadRaw(name);
|
2021-06-21 04:11:10 +08:00
|
|
|
|
|
|
|
public bool IsDisposed { get; private set; }
|
|
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
{
|
|
|
|
base.Dispose(disposing);
|
|
|
|
IsDisposed = true;
|
|
|
|
}
|
|
|
|
}
|
2020-09-24 13:46:28 +08:00
|
|
|
}
|
|
|
|
}
|