Skip to content

Commit

Permalink
Add failing test coverage of legacy fallback lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Oct 1, 2024
1 parent 3fca80e commit 189a790
Showing 1 changed file with 55 additions and 4 deletions.
59 changes: 55 additions & 4 deletions osu.Game.Tests/Skins/TestSceneSkinProvidingContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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[]

Check failure on line 35 in osu.Game.Tests/Skins/TestSceneSkinProvidingContainer.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Redundant array creation expression in osu.Game.Tests\Skins\TestSceneSkinProvidingContainer.cs on line 35
{
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.
Expand Down Expand Up @@ -59,6 +92,20 @@ public void TestPriorityPreservation()
});
}

#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;
Expand All @@ -82,12 +129,16 @@ private class TestSkin : ISkin

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)
{
Expand All @@ -97,9 +148,9 @@ public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wra
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();
}
}
}

0 comments on commit 189a790

Please sign in to comment.