Add test to do sanity checking of core picker and default core prefs
This commit is contained in:
parent
c5802e9154
commit
56916fbbca
|
@ -11,7 +11,28 @@ namespace BizHawk.Client.Common
|
|||
public class Config
|
||||
{
|
||||
public static string ControlDefaultPath => Path.Combine(PathUtils.ExeDirectoryPath, "defctrl.json");
|
||||
|
||||
|
||||
/// <remarks>
|
||||
/// <c>AppliesTo[0]</c> is used as the group label, and
|
||||
/// <c>Config.PreferredCores[AppliesTo[0]]</c> (lookup on global <see cref="Config"/> instance) determines the currently selected option.
|
||||
/// The tuples' order determines the order of menu items.
|
||||
/// </remarks>
|
||||
public static readonly IReadOnlyList<(string[] AppliesTo, string[] CoreNames)> CorePickerUIData = new List<(string[], string[])>
|
||||
{
|
||||
(new[] { "NES" },
|
||||
new[] { CoreNames.QuickNes, CoreNames.NesHawk, CoreNames.SubNesHawk }),
|
||||
(new[] { "SNES" },
|
||||
new[] { CoreNames.Faust, CoreNames.Snes9X, CoreNames.Bsnes }),
|
||||
(new[] { "SGB" },
|
||||
new[] { CoreNames.SameBoy, CoreNames.Bsnes }),
|
||||
(new[] { "GB", "GBC" },
|
||||
new[] { CoreNames.Gambatte, CoreNames.GbHawk, CoreNames.SubGbHawk }),
|
||||
(new[] { "DGB" },
|
||||
new[] { CoreNames.DualGambatte, CoreNames.GBHawkLink }),
|
||||
(new[] { "PCE", "PCECD", "SGX" },
|
||||
new[] { CoreNames.TurboNyma, CoreNames.HyperNyma, CoreNames.PceHawk })
|
||||
};
|
||||
|
||||
public static string DefaultIniPath { get; private set; } = Path.Combine(PathUtils.ExeDirectoryPath, "config.ini");
|
||||
|
||||
// Shenanigans
|
||||
|
|
|
@ -44,21 +44,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
public partial class MainForm : FormBase, IDialogParent, IMainFormForApi, IMainFormForConfig, IMainFormForTools
|
||||
{
|
||||
/// <remarks><c>AppliesTo[0]</c> is used as the group label, and <c>Config.PreferredCores[AppliesTo[0]]</c> determines the currently selected option</remarks>
|
||||
private static readonly IReadOnlyCollection<(string[] AppliesTo, string[] CoreNames)> CoreData = new List<(string[], string[])> {
|
||||
(new[] { "NES" }, new[] { CoreNames.QuickNes, CoreNames.NesHawk, CoreNames.SubNesHawk }),
|
||||
(new[] { "SNES" }, new[] { CoreNames.Faust, CoreNames.Snes9X, CoreNames.Bsnes }),
|
||||
(new[] { "SGB" }, new[] { CoreNames.SameBoy, CoreNames.Bsnes }),
|
||||
(new[] { "GB", "GBC" }, new[] { CoreNames.Gambatte, CoreNames.GbHawk, CoreNames.SubGbHawk }),
|
||||
(new[] { "DGB" }, new[] { CoreNames.DualGambatte, CoreNames.GBHawkLink }),
|
||||
(new[] { "PCE", "PCECD", "SGX" }, new[] { CoreNames.TurboNyma, CoreNames.HyperNyma, CoreNames.PceHawk })
|
||||
};
|
||||
|
||||
private void MainForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
SetWindowText();
|
||||
|
||||
foreach (var (appliesTo, coreNames) in CoreData)
|
||||
foreach (var (appliesTo, coreNames) in Config.CorePickerUIData)
|
||||
{
|
||||
var groupLabel = appliesTo[0];
|
||||
var submenu = new ToolStripMenuItem { Text = groupLabel };
|
||||
|
|
|
@ -14,6 +14,9 @@ namespace BizHawk.Emulation.Cores
|
|||
{
|
||||
private readonly Dictionary<string, List<Core>> _systems = new Dictionary<string, List<Core>>();
|
||||
|
||||
/// <summary>keys are system IDs; values are core/ctor info for all that system's cores</summary>
|
||||
public IReadOnlyDictionary<string, List<Core>> AllCores => _systems;
|
||||
|
||||
public readonly IReadOnlyCollection<Core> SystemsFlat;
|
||||
|
||||
public class Core
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using BizHawk.Client.Common;
|
||||
using BizHawk.Emulation.Cores;
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace BizHawk.Tests.Client.EmuHawk
|
||||
{
|
||||
[TestClass]
|
||||
public sealed class CorePickerStabilityTests
|
||||
{
|
||||
private static readonly IReadOnlyDictionary<string, string> DefaultCorePrefDict = new Config().PreferredCores;
|
||||
|
||||
[TestMethod]
|
||||
public void AssertAllChoicesInMenu()
|
||||
{
|
||||
var multiCoreSystems = CoreInventory.Instance.AllCores.Where(kvp => kvp.Value.Count != 1)
|
||||
.Select(kvp => kvp.Key)
|
||||
.ToHashSet();
|
||||
foreach (var sysID in DefaultCorePrefDict.Keys)
|
||||
{
|
||||
Assert.IsTrue(multiCoreSystems.Contains(sysID), $"a default core preference exists for {sysID} but that system doesn't have alternate cores");
|
||||
}
|
||||
foreach (var (appliesTo, _) in Config.CorePickerUIData)
|
||||
{
|
||||
Assert.IsTrue(
|
||||
appliesTo.Any(multiCoreSystems.Contains),
|
||||
$"core picker has submenu for {appliesTo[0]} ({string.Join('/', appliesTo)}), but {(appliesTo.Length == 1 ? "that system doesn't have" : "none of those systems have")} alternate cores");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AssertNoMissingCores()
|
||||
{
|
||||
var allCoreNames = CoreInventory.Instance.SystemsFlat.Select(coreInfo => coreInfo.Name).ToHashSet();
|
||||
foreach (var kvp in DefaultCorePrefDict)
|
||||
{
|
||||
Assert.IsTrue(allCoreNames.Contains(kvp.Value), $"default core preference for {kvp.Key} is \"{kvp.Value}\", which doesn't exist");
|
||||
}
|
||||
foreach (var (appliesTo, coreNames) in Config.CorePickerUIData) foreach (var coreName in coreNames)
|
||||
{
|
||||
Assert.IsTrue(allCoreNames.Contains(coreName), $"core picker includes nonexistant core \"{coreName}\" under {appliesTo[0]} group");
|
||||
}
|
||||
}
|
||||
|
||||
/// <remarks>this really shouldn't be necessary</remarks>
|
||||
[TestMethod]
|
||||
public void AssertNoMissingSystems()
|
||||
{
|
||||
var allSysIDs = CoreInventory.Instance.AllCores.Keys.ToHashSet();
|
||||
#if false // already covered by AssertAllChoicesInMenu
|
||||
foreach (var sysID in DefaultCorePrefDict.Keys)
|
||||
{
|
||||
Assert.IsTrue(allSysIDs.Contains(sysID), $"a default core preference exists for {sysID}, which isn't emulated by any core");
|
||||
}
|
||||
#endif
|
||||
foreach (var (appliesTo, _) in Config.CorePickerUIData) foreach (var sysID in appliesTo)
|
||||
{
|
||||
Assert.IsTrue(allSysIDs.Contains(sysID), $"core picker has choices for {sysID}, which isn't emulated by any core");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue