mirror of
https://github.com/ppy/osu
synced 2025-01-25 07:13:22 +00:00
Add test coverage for API-incompatible rulesets wrt mods
This commit is contained in:
parent
6e5e506fb4
commit
665ef5fdcc
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#nullable enable
|
#nullable enable
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
@ -12,6 +13,7 @@ using osu.Game.Beatmaps;
|
|||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Rulesets.Difficulty;
|
using osu.Game.Rulesets.Difficulty;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
|
using osu.Game.Rulesets.Osu;
|
||||||
using osu.Game.Rulesets.UI;
|
using osu.Game.Rulesets.UI;
|
||||||
using osu.Game.Tests.Visual;
|
using osu.Game.Tests.Visual;
|
||||||
|
|
||||||
@ -23,6 +25,12 @@ namespace osu.Game.Tests.Rulesets
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private OsuGameBase gameBase { get; set; } = null!;
|
private OsuGameBase gameBase { get; set; } = null!;
|
||||||
|
|
||||||
|
[SetUpSteps]
|
||||||
|
public void SetUpSteps()
|
||||||
|
{
|
||||||
|
AddStep("reset ruleset", () => Ruleset.Value = new OsuRuleset().RulesetInfo);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestNullModsReturnedByRulesetAreIgnored()
|
public void TestNullModsReturnedByRulesetAreIgnored()
|
||||||
{
|
{
|
||||||
@ -30,6 +38,17 @@ namespace osu.Game.Tests.Rulesets
|
|||||||
AddAssert("no null mods in available mods", () => gameBase.AvailableMods.Value.SelectMany(kvp => kvp.Value).All(mod => mod != null));
|
AddAssert("no null mods in available mods", () => gameBase.AvailableMods.Value.SelectMany(kvp => kvp.Value).All(mod => mod != null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestRulesetRevertedIfModsCannotBeRetrieved()
|
||||||
|
{
|
||||||
|
RulesetInfo ruleset = null!;
|
||||||
|
|
||||||
|
AddStep("store current ruleset", () => ruleset = Ruleset.Value);
|
||||||
|
|
||||||
|
AddStep("set API incompatible ruleset", () => Ruleset.Value = new TestAPIIncompatibleRuleset().RulesetInfo);
|
||||||
|
AddAssert("ruleset not changed", () => Ruleset.Value.Equals(ruleset));
|
||||||
|
}
|
||||||
|
|
||||||
#nullable disable // purposefully disabling nullability to simulate broken or unannotated API user code.
|
#nullable disable // purposefully disabling nullability to simulate broken or unannotated API user code.
|
||||||
|
|
||||||
private class TestRulesetWithNullMods : Ruleset
|
private class TestRulesetWithNullMods : Ruleset
|
||||||
@ -44,6 +63,19 @@ namespace osu.Game.Tests.Rulesets
|
|||||||
public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => null;
|
public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class TestAPIIncompatibleRuleset : Ruleset
|
||||||
|
{
|
||||||
|
public override string ShortName => "incompatible";
|
||||||
|
public override string Description => "incompatible";
|
||||||
|
|
||||||
|
// simulate API incompatibility by throwing similar exceptions.
|
||||||
|
public override IEnumerable<Mod> GetModsFor(ModType type) => throw new MissingMethodException();
|
||||||
|
|
||||||
|
public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList<Mod> mods = null) => null;
|
||||||
|
public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => null;
|
||||||
|
public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => null;
|
||||||
|
}
|
||||||
|
|
||||||
#nullable enable
|
#nullable enable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user