64 lines
3.0 KiB
C
64 lines
3.0 KiB
C
#ifdef WORKBENCH
|
|
// Disposable native fixture only. Keep native serialization, profile storage,
|
|
// PlayerManager occupancy and production constructor/Finish; replace transport.
|
|
modded class ERR_Telemetry
|
|
{
|
|
protected override void Pulse() {}
|
|
bool ERR_TestCheck(bool valid, string detail)
|
|
{
|
|
if (valid) Print("ERR SMOKE PASS: telemetry " + detail);
|
|
else Print("ERR SMOKE FAIL: telemetry " + detail, LogLevel.ERROR);
|
|
return valid;
|
|
}
|
|
int ERR_TestFinalCount(string mission)
|
|
{
|
|
int count;
|
|
foreach (string payload : m_State.pending)
|
|
{
|
|
JsonLoadContext json = new JsonLoadContext(); string id, type, outcome; int phase;
|
|
if (!json.LoadFromString(payload)) return -1;
|
|
json.ReadValue("missionId", id); json.ReadValue("type", type);
|
|
if (id != mission || type != "mission_finished") continue;
|
|
json.ReadValue("outcome", outcome); json.ReadValue("phase", phase);
|
|
if (outcome != "defeat" || phase != ERR_Phase.DEFEAT) return -1;
|
|
count++;
|
|
}
|
|
return count;
|
|
}
|
|
void ERR_TestFreeze()
|
|
{
|
|
m_Closed = true;
|
|
GetGame().GetCallqueue().Remove(Pulse);
|
|
}
|
|
bool ERR_TestOccupiedRecovery()
|
|
{
|
|
int connected = GetGame().GetPlayerManager().GetPlayerCount();
|
|
PrintFormat("ERR TELEMETRY NATIVE: connected=%1 mission=%2", connected, m_MissionId);
|
|
if (!ERR_TestCheck(Enabled() && connected > 0, "uses actual connected native player")) return false;
|
|
Checkpoint();
|
|
ERR_TelemetryState disk;
|
|
if (!ERR_TestCheck(ReadState(STATE, disk) && !disk.restartFailure.IsEmpty() && disk.previousOutcome == "unfinished", "occupied checkpoint round-trips through native JSON and profile storage")) return false;
|
|
if (!ERR_TestCheck(ERR_TestFinalCount(m_MissionId) == 0, "live checkpoint is not queued as a failure")) return false;
|
|
// Constructor recovery from persisted unfinished state, as after a forced stop.
|
|
ref ERR_Telemetry recovered = new ERR_Telemetry(m_Mode);
|
|
bool recoveredOK = recovered.ERR_TestFinalCount(m_MissionId) == 1;
|
|
recovered.ERR_TestFreeze();
|
|
if (!ERR_TestCheck(recoveredOK, "fresh service recovers exactly one defeat for the old mission")) return false;
|
|
// Restore the live service's state for the real EndGameMode test below.
|
|
if (!ERR_TestCheck(Save(), "restore original live checkpoint for native shutdown")) return false;
|
|
return true;
|
|
}
|
|
bool ERR_TestFinished()
|
|
{
|
|
ERR_TelemetryState disk;
|
|
if (!ERR_TestCheck(m_Ended && m_State.previousOutcome == "defeat" && m_State.restartFailure.IsEmpty() && ERR_TestFinalCount(m_MissionId) == 1, "actual native end records exactly one occupied failure")) return false;
|
|
if (!ERR_TestCheck(ReadState(STATE, disk) && disk.previousOutcome == "defeat" && disk.restartFailure.IsEmpty(), "completed result persisted and candidate cleared")) return false;
|
|
ref ERR_Telemetry recovered = new ERR_Telemetry(m_Mode);
|
|
bool recoveredOK = recovered.ERR_TestFinalCount(m_MissionId) == 1;
|
|
recovered.ERR_TestFreeze();
|
|
if (!ERR_TestCheck(recoveredOK, "reopening completed state does not duplicate the failure")) return false;
|
|
return Save();
|
|
}
|
|
}
|
|
#endif
|