Files
EscapistsReintroduced/tests/test_native_infantry_setup.py
jakub 6a667d8deb Capture current mission, AI, map and administration development
Include the current addon, terrain integrations, tools, regression tests and recorded development evidence.
2026-10-13 22:52:53 +02:00

40 lines
2.9 KiB
Python

"""Execute the actual infantry fixture setup branch; native scene boundaries adapted."""
import os,sys
from pathlib import Path
REPO=Path(os.environ.get('ERR_REPO', Path(__file__).resolve().parents[1]))
sys.path.insert(0,str(REPO/'tests'))
from policy_harness import body,run
p=Path(os.environ.get('ERR_SMOKE_SOURCE',REPO/'addons/core/Scripts/Game/ERR/40_Chat/ERR_NativeSmoke.c'))
s=body(p,'if (m_ERRTestInfantryTransfer)\n\t\t\t{')
s=s.replace('DamageManagerComponent.Cast(m_ERRSmokePlayer.FindComponent(DamageManagerComponent)).EnableDamageHandling(false);','damage.EnableDamageHandling(false);')
s=s.replace('OnStop().Insert(m_ERRInfantryTransfer.Stop);','OnStop().Insert(m_ERRInfantryTransfer);')
run(r'''
#include <cassert>
int phase=1;
struct ERR_NativeInfantryTransferProbe {static inline int created=0;ERR_NativeInfantryTransferProbe(void*){assert(phase==2);created++;}};
struct Damage {bool enabled=true;void EnableDamageHandling(bool b){enabled=b;}};
struct Invoker {int callbacks=0;void Insert(ERR_NativeInfantryTransferProbe* p){assert(p);callbacks++;}};
struct Mode {bool m_ERRTestInfantryTransfer=true,authorized=true;int m_ERRSmokePlayer=1,m_ERRSmokeStep=0,unlocks=0,failures=0;
Damage damage;Invoker stop;ERR_NativeInfantryTransferProbe*m_ERRInfantryTransfer=nullptr;
bool UnlockPrison(int p){assert(p==m_ERRSmokePlayer);unlocks++;if(!authorized)return false;phase=2;return true;}
bool ERR_Check(bool value,const char*){if(!value)failures++;return value;}Invoker&OnStop(){return stop;}
void Setup(){METHOD}
~Mode(){delete m_ERRInfantryTransfer;}
};
int main(){
{Mode m;phase=1;ERR_NativeInfantryTransferProbe::created=0;m.Setup();assert(m.unlocks==1&&phase==2&&!m.damage.enabled&&m.failures==0&&m.m_ERRSmokeStep==108&&m.stop.callbacks==1&&ERR_NativeInfantryTransferProbe::created==1);}
{Mode m;phase=1;ERR_NativeInfantryTransferProbe::created=0;m.authorized=false;m.Setup();assert(m.unlocks==1&&phase==1&&m.failures==1&&m.m_ERRSmokeStep==0&&m.stop.callbacks==0&&ERR_NativeInfantryTransferProbe::created==0);}
{Mode m;phase=1;m.m_ERRTestInfantryTransfer=false;m.Setup();assert(m.unlocks==0&&m.damage.enabled&&m.m_ERRSmokeStep==0&&m.stop.callbacks==0);}
}
'''.replace('METHOD',s))
assert 'Transition(' not in s and 'SetOrigin(' not in s
mode=REPO/'addons/core/Scripts/Game/ERR/00_Core/ERR_GameMode.c'
wrapper=body(mode,'protected void ServerTick(')
assert 'if (!Replication.IsServer() || !Active()) return;' in wrapper and 'ServerTickMeasured();' in wrapper
tick=body(mode,'protected void ServerTickMeasured(')
command_gate=body(mode,'if (m_Command && m_Phase >= ERR_Phase.RADIO_SEARCH)')
assert 'm_Command.Tick(now);' in command_gate and tick.count('m_Command.Tick(now);')==1
force_gate=body(mode,'if (m_Phase >= ERR_Phase.RADIO_SEARCH)')
assert 'TickForces(now);' in force_gate and tick.count('TickForces(now);')==1
print('PASS: actual inventory-fixture setup uses ordinary prison unlock before constructing its convoy-waiting probe; failed unlock cannot run fixture')