feat: add gated CH5 quiver support and unified regression runner
This commit is contained in:
@@ -35,6 +35,9 @@ class CompatTests(unittest.TestCase):
|
||||
m.Window=type('Window',(Window,),{});m.ImageBox=type('Image',(Image,),{})
|
||||
sys.modules['ui']=m;self.ui=m
|
||||
source=(ROOT/'src/platform/ScriptLib/Ava2UICompatScript.inc').read_text().split('R"PY(',1)[1].rsplit(')PY";',1)[0]
|
||||
# The embedded runtime is Python 2; adapt only its exec statement for this
|
||||
# Python 3 fixture. Native C++ tests run the unmodified runtime script.
|
||||
source=source.replace('exec code in dict','exec(code, dict)')
|
||||
exec(source,{})
|
||||
def tearDown(self):
|
||||
if self.previous is None:sys.modules.pop('ui',None)
|
||||
|
||||
@@ -32,7 +32,7 @@ class Action(Widget):
|
||||
|
||||
# vnum -> (type, subtype, antiflags)
|
||||
ITEMS={11299:(1,0,0),11499:(1,0,0x08|0x10|0x20),12049:(2,0,0x04|0x10|0x20|0x40),8000:(1,6,0),
|
||||
41001:(28,0,0x01),45001:(28,1,0x02),27001:(3,0,0),11259:(2,1,0)}
|
||||
41001:(28,0,0x01),45001:(28,1,0x02),27001:(3,0,0),11259:(2,1,0),8001:(1,9,0)}
|
||||
|
||||
|
||||
class Targets(object):
|
||||
@@ -64,7 +64,7 @@ class PreviewTests(unittest.TestCase):
|
||||
mods['game'].GameWindow=type('GameWindow',(),dict(Open=lambda s:None,Close=lambda s:None))
|
||||
grp=mods['grp'];grp.SetColor=grp.RenderBar=grp.RenderBox=lambda *a:None
|
||||
it=mods['item']
|
||||
for k,v in dict(ITEM_TYPE_WEAPON=1,ITEM_TYPE_ARMOR=2,ITEM_TYPE_COSTUME=28,WEAPON_ARROW=6,ARMOR_BODY=0,
|
||||
for k,v in dict(ITEM_TYPE_WEAPON=1,ITEM_TYPE_ARMOR=2,ITEM_TYPE_COSTUME=28,WEAPON_ARROW=6,WEAPON_QUIVER=9,ARMOR_BODY=0,
|
||||
COSTUME_TYPE_BODY=0,COSTUME_TYPE_HAIR=1,ITEM_ANTIFLAG_FEMALE=0x01,ITEM_ANTIFLAG_MALE=0x02,
|
||||
ITEM_ANTIFLAG_WARRIOR=0x04,ITEM_ANTIFLAG_ASSASSIN=0x08,ITEM_ANTIFLAG_SURA=0x10,
|
||||
ITEM_ANTIFLAG_SHAMAN=0x20).items():setattr(it,k,v)
|
||||
@@ -106,7 +106,7 @@ class PreviewTests(unittest.TestCase):
|
||||
self.assertEqual(spec(12049),('armor',[5,1])) # assassin only
|
||||
self.assertEqual(spec(41001),('armor',[0,5,2,7])) # anti-female costume
|
||||
self.assertEqual(spec(45001),('hair',[4,1,6,3]))
|
||||
for vnum in (8000,27001,11259):self.assertIsNone(spec(vnum)) # arrow, potion, helmet
|
||||
for vnum in (8000,8001,27001,11259):self.assertIsNone(spec(vnum)) # arrow, quiver, potion, helmet
|
||||
self.assertTrue(self.ns['Previewable']('mob',101));self.assertFalse(self.ns['Previewable']('item',27001))
|
||||
|
||||
def test_item_preview_races_and_reset(self):
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
"""Compile the actual client arrow-slot check without invoking the game UI."""
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
|
||||
|
||||
class QuiverClientTests(unittest.TestCase):
|
||||
def test_actual_client_ammunition_gate(self):
|
||||
text = (ROOT/'src/port/UserInterface/PythonPlayerSkill.cpp').read_text()
|
||||
body = text[text.index('bool CPythonPlayer::__HasEnoughArrow()'):text.index('bool CPythonPlayer::__HasItem(')]
|
||||
code = r'''
|
||||
#include <cassert>
|
||||
enum {INVENTORY,c_Equipment_Arrow};
|
||||
struct TItemPos{TItemPos(int,int){}};
|
||||
struct CItemData{
|
||||
enum {ITEM_TYPE_WEAPON=1,WEAPON_ARROW=6,WEAPON_QUIVER=9};
|
||||
int type=ITEM_TYPE_WEAPON,subtype=WEAPON_ARROW;
|
||||
int GetType(){return type;}int GetSubType(){return subtype;}
|
||||
};
|
||||
struct CItemManager{
|
||||
CItemData* item=nullptr;static CItemManager& Instance(){static CItemManager m;return m;}
|
||||
bool GetItemDataPointer(int,CItemData** out){*out=item;return item!=nullptr;}
|
||||
};
|
||||
int errors=0;
|
||||
#define Py_BuildValue(...) nullptr
|
||||
void PyCallClassMemberFunc(void*,const char*,void*){++errors;}
|
||||
struct CPythonPlayer{
|
||||
void* m_ppyGameWindow=nullptr;
|
||||
int GetItemIndex(TItemPos){return 0;}bool __HasEnoughArrow();
|
||||
};
|
||||
''' + body + r'''
|
||||
int main(){
|
||||
CPythonPlayer player;CItemData item;
|
||||
assert(!player.__HasEnoughArrow() && errors==1);
|
||||
CItemManager::Instance().item=&item;
|
||||
assert(player.__HasEnoughArrow());
|
||||
item.subtype=CItemData::WEAPON_QUIVER;assert(player.__HasEnoughArrow());
|
||||
item.subtype=2;assert(!player.__HasEnoughArrow());
|
||||
item.subtype=CItemData::WEAPON_QUIVER;item.type=3;
|
||||
assert(!player.__HasEnoughArrow() && errors==3);
|
||||
}
|
||||
'''
|
||||
with tempfile.TemporaryDirectory(prefix='ch5-quiver-client-') as folder:
|
||||
root = Path(folder)
|
||||
(root/'probe.cpp').write_text(code)
|
||||
subprocess.run(['c++','-std=c++17','-fsanitize=address,undefined',
|
||||
str(root/'probe.cpp'),'-o',str(root/'probe')],check=True)
|
||||
subprocess.run([str(root/'probe')],check=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user