Files
WoW-Hybrid-gateway/tests/quest_poi_60141_runtime_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

73 lines
5.4 KiB
C++

// SPDX-License-Identifier: GPL-2.0-or-later
#include "world_translation.hpp"
#include "gateway/object_updates.hpp"
#include <dlfcn.h>
#include <fstream>
#include <iostream>
#include <iterator>
using namespace gateway;
static void check(bool b){if(!b)throw Error("quest60141 local prototype boundary");}
static Bytes request(){Bytes b;le(b,1,4);le(b,60141,4);for(unsigned i=1;i<175;++i)le(b,0,4);return b;}
static Bytes source_definition(){
// Explicit test fixture. A running candidate requires a genuine cached Source 0x05d.
Bytes b;for(auto n:{60141,2,9,12,0,0,0,0,0,0,0,0,0,0,0})le(b,n,4);
for(unsigned i=0;i<20;++i)le(b,0,4);for(unsigned i=0;i<4;++i)le(b,0,4);
for(auto s:{"Duty to the Light","Collect meat","Details",""})cstring(b,s);
for(unsigned i=0;i<4;++i){le(b,0,4);le(b,0,4);le(b,i==0?51868:0,4);le(b,i==0?8:0,4);}
for(unsigned i=0;i<4;++i)cstring(b,"");return b;
}
static LegacyPacket values(uint64_t guid,uint16_t field,uint32_t value){
Bytes b;le(b,1,4);le(b,0,1);le(b,0,1);Bytes raw;le(raw,guid,8);append(b,pack_guid(raw));
const auto n=field/32+1;le(b,n,1);for(unsigned i=0;i<n;++i)le(b,i==field/32?1u<<(field%32):0,4);
le(b,value,4);return {0xa9,std::move(b)};
}
static int codec(uint32_t,const uint8_t*,uint32_t,uint32_t,uint8_t* output,uint32_t capacity,uint32_t* required){
*required=1;if(capacity<1)return GW_CODEC_CAPACITY;output[0]=0;return GW_CODEC_OK;
}
int main(int argc,char** argv){try{
if(argc<2 || argc>3)throw Error("need saved Source self-create and optional codec library");
void* library=nullptr;auto serialize=&codec;
if(argc==3){library=dlopen(argv[2],RTLD_NOW|RTLD_LOCAL);if(!library)throw Error("cannot load codec");serialize=reinterpret_cast<decltype(&gw_codec_serialize)>(dlsym(library,"gw_codec_serialize"));if(!serialize)throw Error("codec entry missing");}
std::ifstream f(argv[1],std::ios::binary);Bytes raw((std::istreambuf_iterator<char>(f)),{});check(!raw.empty());
NativeWorldTranslation w;w.selected.guid=4509;w.realm=70;w.self_created=true;w.location=WorldLocation{};
for(const auto& u:turtle_object_updates(0x1f6,raw))if(u.guid==4509&&(u.kind==2||u.kind==3)&&u.type==4)
(void)w.entities.self_quest_log.observe(u.fields,true);
check(w.entities.self_quest_log.initialized());auto active=w.entities.self_quest_log.active_quests();
check(std::find(active.begin(),active.end(),60141)!=active.end());
auto bytes=request();auto prepared=w.quests.client(0x4400de,bytes,w.quest_bindings());
check(prepared.held&&prepared.packets.empty());w.quests.sent(prepared);
// Both explicit enablement and loopback realm evidence are necessary.
w.local_gameobject_authority=true;check(!w.queue_quest_poi_60141(bytes,false));
check(w.queue_quest_poi_60141(bytes,true)); // A real request triggers one Source definition lookup.
check(w.quest_poi_60141_waiting_definition&&!w.local_presentation_pending());
check(w.requests.size()==1&&w.requests.front().opcode==0x05c);
Reader source_query(w.requests.front().body);check(source_query.le(4)==60141);source_query.end();
check(!w.queue_quest_poi_60141(bytes,true)&&w.requests.size()==1);
// An intervening SELF quest-log update cancels the pending request.
(void)w.translate(values(4509,199,0),0x46010046,0,serialize);
check(!w.quest_poi_60141_pending&&!w.quest_poi_60141_waiting_definition);
w.requests.clear();check(w.queue_quest_poi_60141(bytes,true));
auto reply=w.translate({0x05d,source_definition()},0x46010046,0,serialize);Reader info(reply);
check(info.le(4)==1&&info.le(4)==0x670016);info.take(info.le(4));info.end();
check(!w.quest_poi_60141_waiting_definition&&w.local_presentation_pending());
auto first=w.local_presentation(0x46010046,nullptr);Reader first_reader(first);
check(first_reader.le(4)==1&&first_reader.le(4)==0x67001d);first_reader.take(first_reader.le(4));first_reader.end();
w.local_gameobject_authority=false;check(!w.queue_quest_poi_60141(bytes,true));
w.local_gameobject_authority=true;check(w.queue_quest_poi_60141(bytes,true));
check(!w.queue_quest_poi_60141(bytes,true)); // One pending delivery per real request.
check(w.local_presentation_pending());auto bundle=w.local_presentation(0x46010046,nullptr);Reader r(bundle);
check(r.le(4)==1&&r.le(4)==0x67001d);auto payload=r.take(r.le(4));r.end();Reader p(payload);
check(p.le(4)==1&&p.le(4)==1&&p.le(4)==60141&&p.le(4)==23);
check(!w.local_presentation_pending());
// Recreated SELF and removals invalidate even a ready candidate.
check(w.queue_quest_poi_60141(bytes,true));LegacyObjectUpdate create;
create.kind=2;create.guid=4509;create.type=4;w.observe_quest_poi_updates({create});check(!w.quest_poi_60141_pending);
check(w.queue_quest_poi_60141(bytes,true));LegacyObjectUpdate removed;
removed.kind=4;removed.removed={4509};w.observe_quest_poi_updates({removed});check(!w.quest_poi_60141_pending);
// A pending candidate must be cancelled if the Source quest disappears or definition changes.
check(w.queue_quest_poi_60141(bytes,true));(void)w.entities.self_quest_log.observe({{201,0}},false);
auto cleared_bytes=w.local_presentation(0x46010046,nullptr);Reader cleared(cleared_bytes);check(cleared.le(4)==0);cleared.end();
check(!w.queue_quest_poi_60141(bytes,true));
std::cout<<"Default hold, deferred real Source lookup, explicit local binding, delivery and cancellation passed\n";return 0;
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}}