using System.Collections.Generic; 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 and no Blax Castes warnings")] 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); string line = Log.Messages.FirstOrDefault(m => m.text != null && m.text.Contains("[Blax Castes]") && m.text.Contains("patches applied"))?.text; T.Check(line != null, "startup line '[Blax Castes] N patches applied' not in the log"); T.Check(!line.Contains("failed"), "a patch failed to apply: " + line); 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))); // Any DLC set: no error from the mod's code while the game started (world generation included), no // cross-reference or patch warnings, and the Caste column placed by the XML patches. List startupErrors = TestRunner.StartupErrors; T.Check(startupErrors.Count == 0, "errors from Blax Castes before the tests: " + string.Join(" | ", startupErrors.Take(3))); List warnings = TestRunner.StartupWarnings; T.Check(warnings.Count == 0, "Blax Castes warnings at startup: " + string.Join(" | ", warnings.Take(3))); } [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(), "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) + ", Royalty: " + ModsConfig.RoyaltyActive + ", Ideology: " + ModsConfig.IdeologyActive + ", Biotech: " + ModsConfig.BiotechActive + ", Anomaly: " + ModsConfig.AnomalyActive + ", Odyssey: " + ModsConfig.OdysseyActive); } [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("needs Ideology (slaves); colonist and prisoner fixtures passed"); Pawn s = Fixtures.ColonySlave(); T.Check(s.IsSlaveOfColony, "slave fixture is not a slave of the colony"); } } }