Files
metin2-client/tests/wiki/test_ava2_shop_wire.py
T
shenandshen 846a993183 feat: complete xxf-ch5 35 features migration, protocol bindings, and gate validation
- S1: Chinese locale pack, target HP/drop preview, elemental icons, exchange level display, item highlight, FOV settings, advanced skybox, GM warp.
- S2: 5-page 225-slot inventory, seamless channel switch, wiki/drop query/chest preview.
- S3: Auto-refine/attribute locks, sash combine/absorb, talisman/elemental stats, costume/mount/shining slots, changelook, soulbind, glove, quiver, magic reduction.
- S4: Modern cube renewal, mythic dragon soul (6 grades/1152 slots), DS attr change, global rankings, dice system.
- S5: Multi-token shop, offline private shop search, offline shop state machine, 64-bit gold alignment, Won dual currency exchange.
- S6: Single account 5-character slot adaptive wire protocol, Wolfman profession & claw weapon/applies, Conqueror level & Sungma attributes, pets & 6th/7th attrs, battle pass & boss tracking.
- Pass 42/42 platform gate test suites in scripts/port_gate.sh macos.
2026-10-22 01:29:14 -07:00

38 lines
2.1 KiB
Python

"""Run the shipped shop decoder against malformed and valid wire frames."""
import os,subprocess,tempfile,unittest
from pathlib import Path
ROOT=Path(__file__).resolve().parents[2]
class WireTests(unittest.TestCase):
def test_complete_frame_and_no_partial_mutation(self):
code=r'''
#include "src/port/UserInterface/Ava2ShopWire.h"
#include <cassert>
#include <string>
#pragma pack(push,1)
struct Item { uint32_t vnum; int64_t price; char body[35]; };
struct Price { uint32_t vnum,count; };
struct Frame { uint32_t owner; Item items[40]; Price prices[40]; };
#pragma pack(pop)
static_assert(sizeof(Item)==47,"native baseline wire size");
static_assert(sizeof(Frame)==2204,"shop start payload size");
int main(){
Frame frame={};frame.items[0].vnum=25163;frame.items[0].price=100000000000LL;frame.prices[0]={90011,10};
Item items[40]={};Price prices[40]={};uint32_t owner=99;
const char* data=reinterpret_cast<const char*>(&frame);
assert(!DecodeAva2ShopStart(data,sizeof(frame)-1,owner,items,prices));assert(owner==99);
assert(!DecodeAva2ShopStart(data,sizeof(frame)+1,owner,items,prices));assert(owner==99);
assert(!DecodeAva2ShopStart(nullptr,sizeof(frame),owner,items,prices));
frame.prices[1]={90010,0};assert(!DecodeAva2ShopStart(data,sizeof(frame),owner,items,prices));assert(items[0].vnum==0);
frame.prices[1]={90010,20};assert(!DecodeAva2ShopStart(data,sizeof(frame),owner,items,prices));assert(owner==99);
frame.prices[1]={0,0};assert(DecodeAva2ShopStart(data,sizeof(frame),owner,items,prices));
assert(items[0].price==100000000000LL);
frame.items[0].price=-1;assert(!DecodeAva2ShopStart(data,sizeof(frame),owner,items,prices));assert(items[0].price==100000000000LL);
assert(owner==0 && items[0].vnum==25163 && prices[0].vnum==90011 && prices[0].count==10);
}
'''
with tempfile.TemporaryDirectory() as d:
p=Path(d);(p/'test.cpp').write_text(code)
subprocess.run([os.environ.get('CXX','c++'),'-std=c++17','-I'+str(ROOT),str(p/'test.cpp'),'-o',str(p/'test')],check=True)
subprocess.run([str(p/'test')],check=True)
if __name__=='__main__':unittest.main()