63 lines
3.0 KiB
C#
63 lines
3.0 KiB
C#
using System.Linq;
|
|
using BlaxSlaves;
|
|
using HarmonyLib;
|
|
using RimWorld;
|
|
using Verse;
|
|
|
|
namespace BlaxSlavesTests
|
|
{
|
|
public static class SmokeTests
|
|
{
|
|
[BlaxTest("startup: patches applied and logged")]
|
|
public static void PatchesApplied()
|
|
{
|
|
var 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 == "blax.slaves");
|
|
T.Info("Harmony patches owned by blax.slaves: " + ours);
|
|
T.Check(ours >= 17, "expected at least 17 patches from blax.slaves, found " + ours);
|
|
bool logged = Log.Messages.Any(m => m.text != null && m.text.Contains("[Blax Slaves]") && m.text.Contains("patches applied"));
|
|
T.Check(logged, "startup line '[Blax Slaves] N patches applied' not in the log");
|
|
var errors = Log.Messages.Where(m => m.type == LogMessageType.Error && m.text != null && m.text.Contains("Blax")).ToList();
|
|
T.Check(errors.Count == 0, "errors mentioning Blax at startup: " + string.Join(" | ", errors.Take(3).Select(e => e.text)));
|
|
}
|
|
|
|
[BlaxTest("startup: settings and defs loaded")]
|
|
public static void DefsLoaded()
|
|
{
|
|
T.NotNull(BlaxSlavesMod.Settings, "BlaxSlavesMod.Settings");
|
|
T.NotNull(BlaxDefOf.BlaxSlaves_SlaveBrand, "hediff BlaxSlaves_SlaveBrand");
|
|
T.NotNull(DefDatabase<RecipeDef>.GetNamedSilentFail("BlaxSlaves_BrandSlave"), "recipe BlaxSlaves_BrandSlave");
|
|
T.NotNull(DefDatabase<RecipeDef>.GetNamedSilentFail("BlaxSlaves_RebrandSlave"), "recipe BlaxSlaves_RebrandSlave");
|
|
T.NotNull(DefDatabase<ThoughtDef>.GetNamedSilentFail("BlaxSlaves_Branded"), "thought BlaxSlaves_Branded");
|
|
T.Check(ThingDefOf.Human.AllRecipes.Any(r => r.defName == "BlaxSlaves_BrandSlave"), "humans don't list the branding surgery");
|
|
}
|
|
|
|
[BlaxTest("harness: colony slave fixture")]
|
|
public static void SlaveFixture()
|
|
{
|
|
Pawn slave = Fixtures.ColonySlave();
|
|
T.Check(slave.Spawned, "slave not spawned");
|
|
T.Check(slave.IsSlaveOfColony, "fixture pawn is not a slave of the colony");
|
|
}
|
|
|
|
[BlaxTest("harness: save and reload kept a marker pawn", phase: 2)]
|
|
public static void ReloadWorked()
|
|
{
|
|
T.Check(T.Carry.TryGetValue("marker", out string id), "phase 1 marker missing");
|
|
Pawn p = Fixtures.FindPawnById(id);
|
|
T.NotNull(p, "marker pawn " + id + " after reload");
|
|
T.Check(p.IsSlaveOfColony, "marker pawn lost slave status over save and load");
|
|
}
|
|
|
|
[BlaxTest("harness: set up marker pawn for reload")]
|
|
public static void MarkerSetup()
|
|
{
|
|
Pawn slave = Fixtures.Keep(Fixtures.ColonySlave());
|
|
T.Carry["marker"] = slave.ThingID;
|
|
}
|
|
}
|
|
}
|