diff --git a/osu.Game.Tests/Skins/TestSceneSkinProvidingContainer.cs b/osu.Game.Tests/Skins/TestSceneSkinProvidingContainer.cs index df314b56a9..4938583345 100644 --- a/osu.Game.Tests/Skins/TestSceneSkinProvidingContainer.cs +++ b/osu.Game.Tests/Skins/TestSceneSkinProvidingContainer.cs @@ -3,28 +3,61 @@ #nullable disable +using System; using System.Collections.Generic; using System.Linq; +using JetBrains.Annotations; 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.Rendering; using osu.Framework.Graphics.Textures; +using osu.Framework.IO.Stores; +using osu.Framework.Platform; using osu.Framework.Testing; using osu.Game.Audio; +using osu.Game.Database; +using osu.Game.IO; using osu.Game.Skinning; using osu.Game.Tests.Visual; namespace osu.Game.Tests.Skins { [HeadlessTest] - public partial class TestSceneSkinProvidingContainer : OsuTestScene + public partial class TestSceneSkinProvidingContainer : OsuTestScene, IStorageResourceProvider { [Resolved] private IRenderer renderer { get; set; } + private static Type[] testSkinTypes = new[] + { + null, + typeof(DefaultLegacySkin), + typeof(TrianglesSkin), + typeof(ArgonSkin), + typeof(TestSkin), + }; + + /// + /// A should always have fallbacks for skin resource lookups. + /// This is to allow placeable components from various skin iterations to resolve their resources. + /// + [TestCaseSource(nameof(testSkinTypes))] + public void TestLegacyTextureFallbackLookups(Type skinType) + { + ISkin skin = (ISkin)(skinType == null ? null : Activator.CreateInstance(skinType, this)); + + SkinProvidingContainer provider = null; + + AddStep("setup sources", () => Child = provider = new SkinProvidingContainer(skin)); + + // This resource is used by `LegacyKeyCounterDisplay`. + AddAssert("test classic default lookup", () => provider.FindProvider(s => s.GetTexture(@"inputoverlay-background") != null) is DefaultLegacySkin); + } + /// /// Ensures that the first inserted skin after resetting (via source change) /// is always prioritised over others when providing the same resource. @@ -59,6 +92,20 @@ namespace osu.Game.Tests.Skins }); } + #region IResourceStorageProvider + + [Resolved] + private GameHost host { get; set; } + + public IRenderer Renderer => host.Renderer; + public AudioManager AudioManager => Audio; + public IResourceStore Files => null!; + public new IResourceStore Resources => base.Resources; + public IResourceStore CreateTextureLoaderStore(IResourceStore underlyingStore) => host.CreateTextureLoaderStore(underlyingStore); + RealmAccess IStorageResourceProvider.RealmAccess => null!; + + #endregion + private partial class TestSkinProvidingContainer : SkinProvidingContainer { private readonly IEnumerable sources; @@ -82,12 +129,16 @@ namespace osu.Game.Tests.Skins private readonly IRenderer renderer; + public TestSkin([CanBeNull] IStorageResourceProvider _) + { + } + public TestSkin(IRenderer renderer) { this.renderer = renderer; } - public Drawable GetDrawableComponent(ISkinComponentLookup lookup) => throw new System.NotImplementedException(); + public Drawable GetDrawableComponent(ISkinComponentLookup lookup) => throw new NotImplementedException(); public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) { @@ -97,9 +148,9 @@ namespace osu.Game.Tests.Skins return null; } - public ISample GetSample(ISampleInfo sampleInfo) => throw new System.NotImplementedException(); + public ISample GetSample(ISampleInfo sampleInfo) => throw new NotImplementedException(); - public IBindable GetConfig(TLookup lookup) => throw new System.NotImplementedException(); + public IBindable GetConfig(TLookup lookup) => throw new NotImplementedException(); } } }