Files
WoW-Hybrid-gateway/tests/native_movement_opcode_predicate_test.py
2026-11-23 03:28:32 +02:00

39 lines
1.9 KiB
Python

"""Compile the exact wire movement classifier without Windows/client side effects."""
from pathlib import Path
import re
import subprocess
import tempfile
import unittest
ROOT=Path(__file__).resolve().parents[1]
class MovementOpcodePredicateTest(unittest.TestCase):
def test_exact_wire_classifier_routes_only_known_direction_and_control_opcodes(self):
source=(ROOT/'native/wine_pipe_host.c').read_text()
match=re.search(r'static int movement_opcode\(uint32_t opcode\)\{[^}]+\}',source)
self.assertIsNotNone(match)
accepted=list(range(0x420000,0x420007))+list(range(0x420008,0x420010))+[
0x420016,0x420017,0x420018,0x420019,0x420027,0x420028,0x42002e,0x420048,0x420049,0x42004f,0x42007f,
0x420029,0x42002a,0x42002b,0x42003f,0x420040,0x420041,
0x42002c,0x42002d,0x420030,0x420031,0x42003a,0x42003b,0x420039]
# Ground/direction movement, six speed ACK routes, five distinct mode
# ACK opcodes and teleport ACK. Adjacent unknown opcodes stay outside.
self.assertEqual(len(accepted),len(set(accepted)))
cases=''.join(f'case {x}u:' for x in accepted)
code='#include <stdint.h>\n'+match[0]+f'''
int main(void){{
for(uint32_t opcode=0x420000;opcode<0x420100;++opcode){{
int expected=0;switch(opcode){{{cases}expected=1;break;default:break;}}
if(movement_opcode(opcode)!=expected)return 1;
}}
if(movement_opcode(0x410018)||movement_opcode(0x430018)||movement_opcode(0x3e021c))return 2;
return 0;
}}
'''
with tempfile.TemporaryDirectory(prefix='movement-classifier-') as directory:
path=Path(directory);(path/'test.c').write_text(code)
subprocess.run(['cc','-std=c11','-Wall','-Wextra','-Werror',str(path/'test.c'),'-o',str(path/'test')],check=True,capture_output=True)
subprocess.run([str(path/'test')],check=True,capture_output=True)
if __name__=='__main__':unittest.main()