Files
WoW-Hybrid-gateway/tests/native_go_custom_lifecycle_test.cpp

35 lines
6.1 KiB
C++

#include "world_translation.hpp"
#include "gateway/object_updates.hpp"
#include <iostream>
using namespace gateway;
static int checks=0,failures=0;
static constexpr uint64_t go=0xf110000002000124ull;
static void check(bool ok,const char* label){++checks;if(!ok){++failures;std::cerr<<"FAIL "<<label<<'\n';}}
static NativeWorldTranslation world(){NativeWorldTranslation w{};w.realm=70;w.selected.guid=4509;w.selected.race=1;w.selected.cls=1;w.selected.name="Fixture";w.self_created=true;w.location=WorldLocation{0,{0,0,0,0}};return w;}
static NativeEntityTranslation::Actor actor(uint64_t id=go){NativeEntityTranslation::Actor a{};a.kind=5;a.entry=2;a.generation=1;a.sent=true;a.eligible=true;a.presentation_realm=70;a.presentation_map=0;a.modern=forever_game_object_guid(id,2,70,0);return a;}
static Bytes guid(uint64_t id){Bytes b;le(b,id,8);return b;}
static Bytes custom(uint64_t id,uint32_t anim=0){auto b=guid(id);le(b,anim,4);return b;}
static std::vector<Bytes> dispatch(NativeWorldTranslation& w,uint32_t op,const Bytes& body){auto b=w.translate({op,body},0x10046,0,nullptr);std::vector<Bytes> out;if(b.empty())return out;Reader r(b);auto n=r.le(4);while(n--){auto code=r.le(4),size=r.le(4);auto raw=r.take(size);if(code==0x470068)out.emplace_back(raw.begin(),raw.end());}r.end();return out;}
static std::vector<Bytes> tick(NativeWorldTranslation& w){return dispatch(w,0x127,Bytes{2,0,0,0,0});}
static Bytes expected(const NativeEntityTranslation::Actor& a,uint32_t anim=0){auto b=pack_guid(a.modern);le(b,anim,4);le(b,0,1);return b;}
int main(){try{
{auto w=world();w.entities.actors[go]=actor();check(dispatch(w,0xb3,custom(go,0xffffffff))==std::vector<Bytes>{expected(actor(),0xffffffff)},"bound GO exact full animation payload");check(w.held_go_anims.empty(),"bound animation not queued");}
// Bobber animation can arrive before its create/template is presented.
{auto w=world();check(dispatch(w,0xb3,custom(go)).empty()&&w.held_go_anims.size()==1,"unknown GO held before create");check(tick(w).empty()&&w.held_go_anims.size()==1,"unbound hold retained");w.entities.actors[go]=actor();check(tick(w)==std::vector<Bytes>{expected(actor())}&&w.held_go_anims.empty(),"valid binding replays once");check(tick(w).empty(),"no second replay");}
{auto w=world();auto a=actor();a.sent=false;a.eligible=false;w.entities.actors[go]=a;dispatch(w,0xb3,custom(go,7));check(w.held_go_anims.size()==1&&tick(w).empty(),"known unsent GO waits for metadata");w.entities.actors[go]=actor();check(tick(w)==std::vector<Bytes>{expected(actor(),7)},"same generation becomes presentable");}
for(auto id:{uint64_t(0),uint64_t(88),uint64_t(4509),uint64_t(0xf130000001000123ull),uint64_t(0xf100000000000125ull)}){auto w=world();check(dispatch(w,0xb3,custom(id)).empty()&&w.held_go_anims.empty(),"nonGO GUID not emitted or queued");}
for(int field=0;field<7;++field){auto w=world();auto a=actor();if(field==0)a.kind=3;if(field==1)a.kind=4;if(field==2)a.presentation_realm=71;if(field==3)a.presentation_map=1;if(field==4)a.generation=0;if(field==5)a.eligible=false;if(field==6)a.modern={};w.entities.actors[go]=a;check(dispatch(w,0xb3,custom(go)).empty()&&w.held_go_anims.empty(),"invalid current actor rejected");}
// Expiry is forced via the recorded deadline, with no wall-clock sleep.
{auto w=world();dispatch(w,0xb3,custom(go));w.held_go_anims.front().until=std::chrono::steady_clock::now()-std::chrono::seconds(1);w.entities.actors[go]=actor();check(tick(w).empty()&&w.held_go_anims.empty(),"expired animation never replayed");}
for(int state=0;state<7;++state){auto w=world();dispatch(w,0xb3,custom(go));w.entities.actors[go]=actor();if(state==0)w.self_created=false;if(state==1)w.location.reset();if(state==2)w.logout_complete=true;if(state==3)w.pending_teleport=NearTeleport{};if(state==4)w.far_transfer=NativeWorldTranslation::FarTransfer{};if(state==5)w.realm=71;if(state==6)w.selected.guid=4510;check(tick(w).empty()&&w.held_go_anims.empty(),"pending animation retired with world scope");}
{auto w=world();dispatch(w,0xb3,custom(go));w.location->map=1;auto a=actor();a.presentation_map=1;a.modern=forever_game_object_guid(go,2,70,1);w.entities.actors[go]=a;check(tick(w).empty()&&w.held_go_anims.empty(),"pending animation cannot cross map");}
{auto w=world();auto a=actor();a.sent=false;w.entities.actors[go]=a;dispatch(w,0xb3,custom(go));a.sent=true;a.generation=2;w.entities.actors[go]=a;check(tick(w).empty()&&w.held_go_anims.empty(),"pending known generation cannot cross recreation");}
{auto w=world();dispatch(w,0xb3,custom(go));auto a=actor();a.sent=false;w.entities.actors[go]=a;tick(w);a.sent=true;a.generation=2;w.entities.actors[go]=a;check(tick(w).empty()&&w.held_go_anims.empty(),"unknown hold binds first observed generation");}
{auto w=world();dispatch(w,0xb3,custom(go));dispatch(w,0xaa,guid(go));check(w.held_go_anims.empty(),"source destroy cancels precreate hold");w.entities.actors[go]=actor();check(tick(w).empty(),"destroyed hold cannot revive");}
{auto w=world();dispatch(w,0xb3,custom(go));Bytes out;le(out,1,4);le(out,0,1);le(out,4,1);le(out,1,4);append(out,pack_guid(guid(go)));dispatch(w,0xa9,out);check(w.held_go_anims.empty(),"source out-of-range cancels precreate hold");}
{auto w=world();dispatch(w,0xb3,custom(go));dispatch(w,0x4d,{});check(w.held_go_anims.empty(),"genuine source logout clears hold");}
{auto w=world();for(unsigned i=0;i<17;++i)dispatch(w,0xb3,custom(go+i,i));check(w.held_go_anims.size()==16&&w.held_go_anims.front().source==go+1,"queue bounded oldest first");w.entities.actors[go]=actor();check(tick(w).empty(),"evicted event never replayed");w.entities.actors[go+1]=actor(go+1);check(tick(w)==std::vector<Bytes>{expected(actor(go+1),1)},"retained event replays exact anim");}
for(int size=0;size<=13;++size){if(size==12)continue;auto w=world();auto b=custom(go);b.resize(size);bool rejected=false;try{dispatch(w,0xb3,b);}catch(const Error&){rejected=true;}check(rejected&&w.held_go_anims.empty(),"malformed packet cannot mutate queue");}
std::cout<<checks<<" custom-animation lifecycle checks; failures="<<failures<<'\n';return failures?1:0;
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}}