1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-31 07:49:52 +08:00

Add failing test coverage of legacy fallback lookups

This commit is contained in:
Dean Herbert
2024-10-01 14:44:20 +09:00
Unverified
parent 3fca80ec85
commit 189a790841
@@ -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),
};
/// <summary>
/// A <see cref="SkinProvidingContainer"/> should always have fallbacks for skin resource lookups.
/// This is to allow placeable components from various skin iterations to resolve their resources.
/// </summary>
[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);
}
/// <summary>
/// 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<byte[]> Files => null!;
public new IResourceStore<byte[]> Resources => base.Resources;
public IResourceStore<TextureUpload> CreateTextureLoaderStore(IResourceStore<byte[]> underlyingStore) => host.CreateTextureLoaderStore(underlyingStore);
RealmAccess IStorageResourceProvider.RealmAccess => null!;
#endregion
private partial class TestSkinProvidingContainer : SkinProvidingContainer
{
private readonly IEnumerable<ISkin> 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<TValue> GetConfig<TLookup, TValue>(TLookup lookup) => throw new System.NotImplementedException();
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) => throw new NotImplementedException();
}
}
}