From 7e607bbf7230c923e37f947a2b8c49488a123bc3 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 19 Mar 2023 19:50:54 +0800 Subject: [PATCH] Add Framework which provides a test runner with resources from the test project. --- .../AutomatedVisualTestGame.cs | 2 +- .../Visual/BackgroundGridTestScene.cs | 3 +-- .../Visual/FrameworkTestScene.cs | 23 +++++++++++++++++++ .../FrameworkTestSceneTestRunner.cs} | 11 ++++----- .../Sprites/TestSceneKaraokeSpriteText.cs | 3 +-- .../Sprites/TestSceneLyricSpriteText.cs | 4 ++-- osu.Framework.Font.Tests/VisualTestGame.cs | 2 +- 7 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 osu.Framework.Font.Tests/Visual/FrameworkTestScene.cs rename osu.Framework.Font.Tests/{TestGame.cs => Visual/FrameworkTestSceneTestRunner.cs} (84%) diff --git a/osu.Framework.Font.Tests/AutomatedVisualTestGame.cs b/osu.Framework.Font.Tests/AutomatedVisualTestGame.cs index 41a79bb..20aebb1 100644 --- a/osu.Framework.Font.Tests/AutomatedVisualTestGame.cs +++ b/osu.Framework.Font.Tests/AutomatedVisualTestGame.cs @@ -5,7 +5,7 @@ namespace osu.Framework.Font.Tests; -internal partial class AutomatedVisualTestGame : TestGame +internal partial class AutomatedVisualTestGame : Game { public AutomatedVisualTestGame() { diff --git a/osu.Framework.Font.Tests/Visual/BackgroundGridTestScene.cs b/osu.Framework.Font.Tests/Visual/BackgroundGridTestScene.cs index 70c375f..f92c12d 100644 --- a/osu.Framework.Font.Tests/Visual/BackgroundGridTestScene.cs +++ b/osu.Framework.Font.Tests/Visual/BackgroundGridTestScene.cs @@ -11,13 +11,12 @@ using osu.Framework.Graphics.Shaders; using osu.Framework.Graphics.Shapes; using osu.Framework.Input.Events; -using osu.Framework.Testing; using osuTK; using osuTK.Graphics; namespace osu.Framework.Font.Tests.Visual; -public abstract partial class BackgroundGridTestScene : TestScene +public abstract partial class BackgroundGridTestScene : FrameworkTestScene { protected const int GRID_SIZE = 30; diff --git a/osu.Framework.Font.Tests/Visual/FrameworkTestScene.cs b/osu.Framework.Font.Tests/Visual/FrameworkTestScene.cs new file mode 100644 index 0000000..32aa063 --- /dev/null +++ b/osu.Framework.Font.Tests/Visual/FrameworkTestScene.cs @@ -0,0 +1,23 @@ +// Copyright (c) karaoke.dev . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Framework.IO.Stores; +using osu.Framework.Testing; + +namespace osu.Framework.Font.Tests.Visual; + +/// +/// All the test scene with resource should inherit this class. +/// +public abstract partial class FrameworkTestScene : TestScene +{ + protected override ITestSceneTestRunner CreateRunner() => new FrameworkTestSceneTestRunner(); + + [BackgroundDependencyLoader] + private void load(Game game) + { + // add store from main project + game.Resources.AddStore(new NamespacedResourceStore(new ShaderResourceStore(), "Resources")); + } +} diff --git a/osu.Framework.Font.Tests/TestGame.cs b/osu.Framework.Font.Tests/Visual/FrameworkTestSceneTestRunner.cs similarity index 84% rename from osu.Framework.Font.Tests/TestGame.cs rename to osu.Framework.Font.Tests/Visual/FrameworkTestSceneTestRunner.cs index f25eb59..0033ef2 100644 --- a/osu.Framework.Font.Tests/TestGame.cs +++ b/osu.Framework.Font.Tests/Visual/FrameworkTestSceneTestRunner.cs @@ -1,13 +1,13 @@ // Copyright (c) karaoke.dev . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Reflection; using osu.Framework.Allocation; using osu.Framework.IO.Stores; +using osu.Framework.Testing; -namespace osu.Framework.Font.Tests; +namespace osu.Framework.Font.Tests.Visual; -internal partial class TestGame : Game +public partial class FrameworkTestSceneTestRunner : TestSceneTestRunner { [BackgroundDependencyLoader] private void load() @@ -15,11 +15,8 @@ private void load() // add store from osu.game.resources Resources.AddStore(new DllResourceStore(@"osu.Game.Resources.dll")); - // add store from main project - Resources.AddStore(new NamespacedResourceStore(new ShaderResourceStore(), "Resources")); - // add store from test project - Resources.AddStore(new NamespacedResourceStore(new DllResourceStore(Assembly.GetExecutingAssembly().Location), "Resources")); + Resources.AddStore(new NamespacedResourceStore(new DllResourceStore(typeof(FrameworkTestScene).Assembly), "Resources")); // Add font resource AddFont(Resources, @"Fonts/osuFont"); diff --git a/osu.Framework.Font.Tests/Visual/Sprites/TestSceneKaraokeSpriteText.cs b/osu.Framework.Font.Tests/Visual/Sprites/TestSceneKaraokeSpriteText.cs index 9d07fd9..02fc918 100644 --- a/osu.Framework.Font.Tests/Visual/Sprites/TestSceneKaraokeSpriteText.cs +++ b/osu.Framework.Font.Tests/Visual/Sprites/TestSceneKaraokeSpriteText.cs @@ -13,13 +13,12 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Shaders; using osu.Framework.Graphics.Sprites; -using osu.Framework.Testing; using osuTK; using osuTK.Graphics; namespace osu.Framework.Font.Tests.Visual.Sprites; -public partial class TestSceneKaraokeSpriteText : TestScene +public partial class TestSceneKaraokeSpriteText : FrameworkTestScene { private readonly TestKaraokeSpriteText karaokeSpriteText; private readonly SpriteText transformAmountSpriteText; diff --git a/osu.Framework.Font.Tests/Visual/Sprites/TestSceneLyricSpriteText.cs b/osu.Framework.Font.Tests/Visual/Sprites/TestSceneLyricSpriteText.cs index e393875..bc700d6 100644 --- a/osu.Framework.Font.Tests/Visual/Sprites/TestSceneLyricSpriteText.cs +++ b/osu.Framework.Font.Tests/Visual/Sprites/TestSceneLyricSpriteText.cs @@ -6,12 +6,11 @@ using osu.Framework.Font.Tests.Helper; using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; -using osu.Framework.Testing; using osuTK; namespace osu.Framework.Font.Tests.Visual.Sprites; -public partial class TestSceneLyricSpriteText : TestScene +public partial class TestSceneLyricSpriteText : FrameworkTestScene { [TestCase("karaoke", null, null)] [TestCase("カラオケ", new[] { "[0,1]:か", "[1,2]:ら", "[2,3]:お", "[3,4]:け" }, null)] @@ -235,6 +234,7 @@ internal partial class DefaultLyricSpriteText : LyricSpriteText public DefaultLyricSpriteText(bool ruby = true, bool romaji = true) { Text = "カラオケ"; + Font = FontUsage.Default; if (ruby) { diff --git a/osu.Framework.Font.Tests/VisualTestGame.cs b/osu.Framework.Font.Tests/VisualTestGame.cs index 2e068e7..0d02124 100644 --- a/osu.Framework.Font.Tests/VisualTestGame.cs +++ b/osu.Framework.Font.Tests/VisualTestGame.cs @@ -10,7 +10,7 @@ namespace osu.Framework.Font.Tests; -internal partial class VisualTestGame : TestGame +internal partial class VisualTestGame : Game { [BackgroundDependencyLoader] private void load()