Files
WoW-Hybrid-gateway/tests/item_use_packet_test.cpp
praxisandClaude Fable 5.2 7f2139d8d0 Offline test fixtures
883 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

69 lines
6.5 KiB
C++

#include "gateway/gameplay.hpp"
#include <algorithm>
#include <iostream>
using namespace gateway;
static void check(bool v){if(!v)throw Error("item-use source fixture assertion");}
template<class F>void rejects(F f){try{f();}catch(const Error&){return;}throw Error("expected item-use rejection");}
int main(){
auto captured=unhex("ff2303806a8d0c018301426cbc00000000000000000000000000b1010000889c030000000000000000000000000000000000000000000000000000000000000000000000000000000000");auto request=forever_item_use(captured);
check(request.bag==255 && request.slot==35 && request.spell.spell==433 && !request.spell.target_flags);
check(turtle_item_use(request,255,23,{})==Bytes({255,23,0,0,0}));
// Actual693840 original Battle Stance68byte request, genuine cast2457.
auto spellBody=unhex("018701426602bc0000000000000000000000000099090000c6a2030000000000000000000000000000000000000000000000000000000000000000000000000000000000");auto normal=forever_spell_request(spellBody);
check(normal.spell==2457 && !normal.target_flags);
check(turtle_spell_request(normal,{})==Bytes({0x99,9,0,0,0,0}));
for(size_t n=0;n<spellBody.size();++n)rejects([&]{forever_spell_request(std::span(spellBody).first(n));});
auto extraSpell=spellBody;extraSpell.push_back(0);rejects([&]{forever_spell_request(extraSpell);});
auto optionalSpell=spellBody;optionalSpell.back()=0x40;rejects([&]{forever_spell_request(optionalSpell);});
// Real70334 targeted stone12404 -> equipped sword36198, captured after
// original /use0/3 then /use16. Item-target semantics differ from food.
auto stone=forever_item_use(unhex("ff250380868d0c01870282c20fbc000000000000000000000000000a3f0000dfbf0300000000001000000000000380668d0c00000000000000000000000000000000000000000000000000000000"));
check(stone.slot==37 && stone.spell.spell==16138 && stone.spell.target_flags==16);
constexpr uint64_t sword=(0x4000ULL<<48)|36198;
auto stoneWire=turtle_item_use(stone,255,25,{{sword,stone.spell.item}});
Bytes stoneExpected{255,25,0,16,0},swordRaw;le(swordRaw,sword,8);append(stoneExpected,pack_guid(swordRaw));check(stoneWire==stoneExpected);
// Unit::SendPeriodicAuraLog: packed target/caster, spell/count/type32,
// then damage/school/absorb32 and signed resist32. Actual Rend tick is39bytes.
Bytes periodic,periodicTarget,periodicCaster;le(periodicTarget,(0xf130ULL<<48)|(7446ULL<<24)|0x2c51cc,8);le(periodicCaster,4509,8);
append(periodic,pack_guid(periodicTarget));append(periodic,pack_guid(periodicCaster));le(periodic,772,4);le(periodic,1,4);le(periodic,3,4);auto periodicPrefix=periodic;
le(periodic,46,4);le(periodic,0,4);le(periodic,0,4);le(periodic,0,4);
check(periodic.size()==39);auto tick=turtle_periodic_aura_log(periodic);check(tick && tick->amount==46 && tick->school==1 && tick->original==46);
for(size_t n=0;n<periodic.size();++n)rejects([&]{turtle_periodic_aura_log(std::span(periodic).first(n));});
auto trailingTick=periodic;trailingTick.push_back(0);rejects([&]{turtle_periodic_aura_log(trailingTick);});
auto variant=[&](uint32_t amount,uint32_t school,uint32_t absorb,int32_t resist){auto b=periodicPrefix;le(b,amount,4);le(b,school,4);le(b,absorb,4);le(b,uint32_t(resist),4);return b;};
check(turtle_periodic_aura_log(variant(40,3,5,1))->original==46);
check(turtle_periodic_aura_log(variant(50,0,0,-4))->original==46);
check(turtle_periodic_aura_log(variant(0,2,46,0))->original==46);
rejects([&]{turtle_periodic_aura_log(variant(46,7,0,0));});rejects([&]{turtle_periodic_aura_log(variant(0,0,0,-1));});rejects([&]{turtle_periodic_aura_log(variant(0x7fffffff,0,1,0));});
auto unsupportedTick=periodic;unsupportedTick[periodicPrefix.size()-4]=8;check(!turtle_periodic_aura_log(unsupportedTick));
rejects([&]{forever_periodic_aura_log(*tick,{});});
// Spell.cpp source contract: item/caster packed64, spell32/flags16,
// START milliseconds32; GO raw64 hit/miss lists; targets mask16/item64.
Bytes cast;Bytes casterRaw;le(casterRaw,(0x4000ULL<<48)|36230,8);append(cast,pack_guid(casterRaw));Bytes selfRaw;le(selfRaw,4509,8);append(cast,pack_guid(selfRaw));le(cast,16138,4);
auto start=cast;le(start,2,2);le(start,3000,4);le(start,16,2);append(start,pack_guid(swordRaw));
auto began=turtle_spell_cast(0x131,start);check(began && began->time==3000 && began->target_item==sword && began->unit==4509);
for(size_t n=0;n<start.size();++n)rejects([&]{turtle_spell_cast(0x131,std::span(start).first(n));});
auto go=cast;le(go,0x100,2);le(go,1,1);le(go,4509,8);le(go,1,1);le(go,4509,8);le(go,11,1);le(go,2,1);le(go,16,2);append(go,pack_guid(swordRaw));
auto ended=turtle_spell_cast(0x132,go);check(ended && ended->hits==std::vector<uint64_t>{4509} && ended->misses.size()==1 && ended->misses[0].reason==11 && ended->misses[0].reflect==2);
auto projectile=start;projectile[cast.size()]|=0x20;check(!turtle_spell_cast(0x131,projectile));
auto extraStart=start;extraStart.push_back(0);rejects([&]{turtle_spell_cast(0x131,extraStart);});
Bytes failed;le(failed,439,4);le(failed,2,1);le(failed,1,1);
auto full=turtle_cast_failure(failed);check(full && full->reason==2 && full->arg1==-1);
for(size_t n=0;n<failed.size();++n)rejects([&]{turtle_cast_failure(std::span(failed).first(n));});
auto unsupported=failed;unsupported[5]=12;check(!turtle_cast_failure(unsupported));
auto area=failed;area[5]=93;le(area,12,4);auto areaFailure=turtle_cast_failure(area);check(areaFailure && areaFailure->arg1==12 && areaFailure->reason==122);
for(size_t n=0;n<captured.size();++n)rejects([&]{forever_item_use(std::span(captured).first(n));});
auto extra=captured;extra.push_back(0);rejects([&]{forever_item_use(extra);});
Guid128 item{};item[0]=75;item[15]=12;
std::map<uint64_t,Guid128> known{{(0x4000ULL<<48)|75,item}};
request.spell.target_flags=16;request.spell.item=item;
auto targeted=turtle_item_use(request,255,23,known);Bytes expected{255,23,0,16,0};Bytes raw;le(raw,(0x4000ULL<<48)|75,8);append(expected,pack_guid(raw));check(targeted==expected);
rejects([&]{turtle_item_use(request,255,23,{});});
request.spell.target_flags=0;rejects([&]{turtle_item_use(request,255,23,known);});
request.spell.target_flags=2;request.spell.item={};request.spell.unit=item;rejects([&]{turtle_item_use(request,255,23,known);});
// The captured optional-layout byte is last; unsupported movement/order flags
// must fail rather than be interpreted as a harmless stationary consumable.
auto optional=captured;optional.back()=0x40;rejects([&]{forever_item_use(optional);});
std::cout<<"Actual70334 food specimen433 exact parse; all truncations, trailing bytes, optional movement, unbound targets and item/unit category confusion reject. Owned item target emits Turtle mask16. Gameplay effects not asserted.\n";
}