2021-10-11 06:45:06 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2022-08-29 05:26:09 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2021-10-11 06:45:06 +00:00
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
2022-08-29 05:26:09 +00:00
|
|
|
using osu.Game.Beatmaps;
|
2021-11-19 10:07:21 +00:00
|
|
|
using osu.Game.Rulesets;
|
2022-08-29 05:26:09 +00:00
|
|
|
using osu.Game.Rulesets.Difficulty;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
using osu.Game.Rulesets.Osu;
|
|
|
|
using osu.Game.Rulesets.Osu.Beatmaps;
|
|
|
|
using osu.Game.Rulesets.Osu.Difficulty;
|
|
|
|
using osu.Game.Rulesets.Osu.UI;
|
|
|
|
using osu.Game.Rulesets.UI;
|
2021-10-11 06:45:06 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Database
|
|
|
|
{
|
|
|
|
public class RulesetStoreTests : RealmTest
|
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void TestCreateStore()
|
|
|
|
{
|
2022-01-24 10:59:58 +00:00
|
|
|
RunTestWithRealm((realm, storage) =>
|
2021-10-11 06:45:06 +00:00
|
|
|
{
|
2022-02-16 08:13:51 +00:00
|
|
|
var rulesets = new RealmRulesetStore(realm, storage);
|
2021-10-11 06:45:06 +00:00
|
|
|
|
|
|
|
Assert.AreEqual(4, rulesets.AvailableRulesets.Count());
|
2022-01-24 10:59:58 +00:00
|
|
|
Assert.AreEqual(4, realm.Realm.All<RulesetInfo>().Count());
|
2021-10-11 06:45:06 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestCreateStoreTwiceDoesntAddRulesetsAgain()
|
|
|
|
{
|
2022-01-24 10:59:58 +00:00
|
|
|
RunTestWithRealm((realm, storage) =>
|
2021-10-11 06:45:06 +00:00
|
|
|
{
|
2022-02-16 08:13:51 +00:00
|
|
|
var rulesets = new RealmRulesetStore(realm, storage);
|
|
|
|
var rulesets2 = new RealmRulesetStore(realm, storage);
|
2021-10-11 06:45:06 +00:00
|
|
|
|
|
|
|
Assert.AreEqual(4, rulesets.AvailableRulesets.Count());
|
|
|
|
Assert.AreEqual(4, rulesets2.AvailableRulesets.Count());
|
|
|
|
|
|
|
|
Assert.AreEqual(rulesets.AvailableRulesets.First(), rulesets2.AvailableRulesets.First());
|
2022-01-24 10:59:58 +00:00
|
|
|
Assert.AreEqual(4, realm.Realm.All<RulesetInfo>().Count());
|
2021-10-11 06:45:06 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestRetrievedRulesetsAreDetached()
|
|
|
|
{
|
2022-01-24 10:59:58 +00:00
|
|
|
RunTestWithRealm((realm, storage) =>
|
2021-10-11 06:45:06 +00:00
|
|
|
{
|
2022-02-16 08:13:51 +00:00
|
|
|
var rulesets = new RealmRulesetStore(realm, storage);
|
2021-10-11 06:45:06 +00:00
|
|
|
|
2021-12-04 13:42:01 +00:00
|
|
|
Assert.IsFalse(rulesets.AvailableRulesets.First().IsManaged);
|
|
|
|
Assert.IsFalse(rulesets.GetRuleset(0)?.IsManaged);
|
|
|
|
Assert.IsFalse(rulesets.GetRuleset("mania")?.IsManaged);
|
2021-10-11 06:45:06 +00:00
|
|
|
});
|
|
|
|
}
|
2022-08-29 05:26:09 +00:00
|
|
|
|
2022-08-29 05:28:55 +00:00
|
|
|
[Test]
|
|
|
|
public void TestRulesetThrowingOnMethods()
|
|
|
|
{
|
|
|
|
RunTestWithRealm((realm, storage) =>
|
|
|
|
{
|
|
|
|
LoadTestRuleset.Version = Ruleset.CURRENT_RULESET_API_VERSION;
|
|
|
|
LoadTestRuleset.HasImplementations = false;
|
|
|
|
|
|
|
|
var ruleset = new LoadTestRuleset();
|
|
|
|
string rulesetShortName = ruleset.RulesetInfo.ShortName;
|
|
|
|
|
|
|
|
realm.Write(r => r.Add(new RulesetInfo(rulesetShortName, ruleset.RulesetInfo.Name, ruleset.RulesetInfo.InstantiationInfo, ruleset.RulesetInfo.OnlineID)
|
|
|
|
{
|
|
|
|
Available = true,
|
|
|
|
}));
|
|
|
|
|
2023-07-06 04:37:42 +00:00
|
|
|
Assert.That(realm.Run(r => r.Find<RulesetInfo>(rulesetShortName)!.Available), Is.True);
|
2022-08-29 05:28:55 +00:00
|
|
|
|
|
|
|
// Availability is updated on construction of a RealmRulesetStore
|
|
|
|
var _ = new RealmRulesetStore(realm, storage);
|
|
|
|
|
2023-07-06 04:37:42 +00:00
|
|
|
Assert.That(realm.Run(r => r.Find<RulesetInfo>(rulesetShortName)!.Available), Is.False);
|
2022-08-29 05:28:55 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-08-29 05:26:09 +00:00
|
|
|
[Test]
|
|
|
|
public void TestOutdatedRulesetNotAvailable()
|
|
|
|
{
|
|
|
|
RunTestWithRealm((realm, storage) =>
|
|
|
|
{
|
2022-08-29 05:28:55 +00:00
|
|
|
LoadTestRuleset.Version = "2021.101.0";
|
|
|
|
LoadTestRuleset.HasImplementations = true;
|
2022-08-29 05:26:09 +00:00
|
|
|
|
2022-08-29 05:28:55 +00:00
|
|
|
var ruleset = new LoadTestRuleset();
|
2022-08-29 05:26:09 +00:00
|
|
|
string rulesetShortName = ruleset.RulesetInfo.ShortName;
|
|
|
|
|
|
|
|
realm.Write(r => r.Add(new RulesetInfo(rulesetShortName, ruleset.RulesetInfo.Name, ruleset.RulesetInfo.InstantiationInfo, ruleset.RulesetInfo.OnlineID)
|
|
|
|
{
|
|
|
|
Available = true,
|
|
|
|
}));
|
|
|
|
|
2023-07-06 04:37:42 +00:00
|
|
|
Assert.That(realm.Run(r => r.Find<RulesetInfo>(rulesetShortName)!.Available), Is.True);
|
2022-08-29 05:26:09 +00:00
|
|
|
|
|
|
|
// Availability is updated on construction of a RealmRulesetStore
|
|
|
|
var _ = new RealmRulesetStore(realm, storage);
|
|
|
|
|
2023-07-06 04:37:42 +00:00
|
|
|
Assert.That(realm.Run(r => r.Find<RulesetInfo>(rulesetShortName)!.Available), Is.False);
|
2022-08-29 05:26:09 +00:00
|
|
|
|
|
|
|
// Simulate the ruleset getting updated
|
2022-08-29 05:28:55 +00:00
|
|
|
LoadTestRuleset.Version = Ruleset.CURRENT_RULESET_API_VERSION;
|
2022-08-29 05:26:09 +00:00
|
|
|
var __ = new RealmRulesetStore(realm, storage);
|
|
|
|
|
2023-07-06 04:37:42 +00:00
|
|
|
Assert.That(realm.Run(r => r.Find<RulesetInfo>(rulesetShortName)!.Available), Is.True);
|
2022-08-29 05:26:09 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-08-29 05:28:55 +00:00
|
|
|
private class LoadTestRuleset : Ruleset
|
2022-08-29 05:26:09 +00:00
|
|
|
{
|
|
|
|
public override string RulesetAPIVersionSupported => Version;
|
|
|
|
|
|
|
|
public static bool HasImplementations = true;
|
|
|
|
|
|
|
|
public static string Version { get; set; } = CURRENT_RULESET_API_VERSION;
|
|
|
|
|
|
|
|
public override IEnumerable<Mod> GetModsFor(ModType type)
|
|
|
|
{
|
|
|
|
if (!HasImplementations)
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
|
|
return Array.Empty<Mod>();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList<Mod>? mods = null)
|
|
|
|
{
|
|
|
|
if (!HasImplementations)
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
|
|
return new DrawableOsuRuleset(new OsuRuleset(), beatmap, mods);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap)
|
|
|
|
{
|
|
|
|
if (!HasImplementations)
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
|
|
return new OsuBeatmapConverter(beatmap, new OsuRuleset());
|
|
|
|
}
|
|
|
|
|
|
|
|
public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap)
|
|
|
|
{
|
|
|
|
if (!HasImplementations)
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
|
|
return new OsuDifficultyCalculator(new OsuRuleset().RulesetInfo, beatmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string Description => "outdated ruleset";
|
|
|
|
public override string ShortName => "ruleset-outdated";
|
|
|
|
}
|
2021-10-11 06:45:06 +00:00
|
|
|
}
|
|
|
|
}
|