rimworld-blax-castes/Tests/BlaxCastesTests/Source/SmokeTests.cs

79 lines
4.4 KiB
C#
Raw Normal View History

using System.Linq;
using BlaxCastes;
using HarmonyLib;
using RimWorld;
using Verse;
namespace BlaxCastesTests
{
public static class SmokeTests
{
private static readonly string[] CoreKeys =
{
"BlaxCastes_NewCasteLabel", "BlaxCastes_Unmanaged", "BlaxCastes_SlotApparel", "BlaxCastes_SlotFood", "BlaxCastes_SlotDrug",
"BlaxCastes_SlotReading", "BlaxCastes_SlotMedCare", "BlaxCastes_NoCaste", "BlaxCastes_StarterColonist", "BlaxCastes_StarterSlave",
"BlaxCastes_StarterPrisoner", "BlaxCastes_StarterSeededMessage",
"BlaxCastes_ManageCastesTitle", "BlaxCastes_JoinDefaultsTitle",
};
[BlaxTest("startup: patcher ran and logged, no errors mentioning Blax Castes")]
public static void StartupLogged()
{
int ours = Harmony.GetAllPatchedMethods()
.Select(Harmony.GetPatchInfo)
.Where(info => info != null)
.SelectMany(info => info.Prefixes.Concat(info.Postfixes).Concat(info.Finalizers).Concat(info.Transpilers))
.Count(p => p.owner == BlaxCastesStartup.HarmonyId);
T.Info("Harmony patches owned by " + BlaxCastesStartup.HarmonyId + ": " + ours);
bool logged = Log.Messages.Any(m => m.text != null && m.text.Contains("[Blax Castes]") && m.text.Contains("patches applied"));
T.Check(logged, "startup line '[Blax Castes] N patches applied' not in the log");
var errors = Log.Messages.Where(m => m.type == LogMessageType.Error && m.text != null && (m.text.Contains("Blax Castes") || m.text.Contains("BlaxCastes"))).ToList();
T.Check(errors.Count == 0, "errors mentioning Blax Castes at startup: " + string.Join(" | ", errors.Take(3).Select(e => e.text)));
}
[BlaxTest("startup: settings, game component and strings are loaded")]
public static void Loaded()
{
T.NotNull(BlaxCastesMod.Settings, "BlaxCastesMod.Settings");
T.NotNull(GameComponent_BlaxCastes.Instance, "GameComponent_BlaxCastes.Instance");
T.Check(GameComponent_BlaxCastes.Instance == Current.Game.GetComponent<GameComponent_BlaxCastes>(), "Instance is not the game's component");
var missing = CoreKeys.Concat(JoinReason.Rows.Select(r => "BlaxCastes_Row_" + r)).Where(k => !k.CanTranslate()).ToList();
T.Check(missing.Count == 0, "strings missing from Keyed: " + string.Join(", ", missing));
foreach (CasteSlot slot in CasteUtility.AllSlots)
T.Check(!CasteUtility.SlotLabel(slot).NullOrEmpty(), "no label for slot " + slot);
}
[BlaxTest("compat: IsActive finds Blax Castes and the base game, not a made-up id")]
public static void IsActiveWorks()
{
T.Check(Compat.IsActive("blax.castes"), "Compat.IsActive(\"blax.castes\") is false while Blax Castes runs");
T.Check(Compat.IsActive("ludeon.rimworld"), "Compat.IsActive(\"ludeon.rimworld\") is false");
T.Check(!Compat.IsActive("blax.castes.does.not.exist"), "Compat.IsActive is true for a made-up id");
T.Info("Blax Slaves active: " + Compat.IsActive(Compat.BlaxSlaves) + ", Ideology: " + ModsConfig.IdeologyActive + ", Biotech: " + ModsConfig.BiotechActive);
}
[BlaxTest("windows: the manager and join defaults windows construct, the join queue is callable")]
public static void WindowsConstruct()
{
T.NotNull(new Dialog_ManageCastes(), "new Dialog_ManageCastes()");
T.NotNull(new Dialog_JoinDefaults(), "new Dialog_JoinDefaults()");
Pawn p = Fixtures.Colonist();
JoinDefaults.Enqueue(p, JoinReason.NewColonist);
JoinDefaults.ApplyQueue();
}
[BlaxTest("harness: colonist, prisoner and colony slave fixtures")]
public static void Fixtures_()
{
Pawn c = Fixtures.Colonist();
T.Check(c.Spawned && c.IsFreeColonist, "colonist fixture is not a spawned free colonist");
Pawn pr = Fixtures.Prisoner();
T.Check(pr.IsPrisonerOfColony, "prisoner fixture is not a prisoner of the colony");
if (!ModsConfig.IdeologyActive)
T.Skip("slaves need Ideology; colonist and prisoner fixtures passed");
Pawn s = Fixtures.ColonySlave();
T.Check(s.IsSlaveOfColony, "slave fixture is not a slave of the colony");
}
}
}