Files
WoW-Hybrid-gateway/tests/quest_status_refresh_world_test.cpp
2026-11-23 03:28:32 +02:00

55 lines
4.4 KiB
C++

// SPDX-License-Identifier: GPL-2.0-or-later
#include "world_translation.hpp"
#include <iostream>
#include <source_location>
using namespace gateway;
static void check(bool b,const std::source_location where=std::source_location::current()){if(!b)throw Error("quest status world fixture line "+std::to_string(where.line()));}
static int codec(uint32_t mode,const uint8_t*,uint32_t,uint32_t,uint8_t* out,uint32_t cap,uint32_t* needed){
*needed=mode==GW_CODEC_UNIT_VALUES_PROFILE?6:1;if(cap<*needed)return GW_CODEC_CAPACITY;
std::fill(out,out+*needed,0);return GW_CODEC_OK;
}
static LegacyPacket status(uint64_t guid){Bytes b;le(b,guid,8);le(b,5,4);return {0x183,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)};
}
int main(){try{
NativeWorldTranslation w;w.selected.guid=4509;w.realm=70;w.location=WorldLocation{};w.self_created=true;
NativeEntityTranslation::Actor a;a.kind=3;a.generation=10;a.presentation_realm=70;a.presentation_map=0;a.eligible=true;a.sent=false;a.questgiver=true;a.modern[0]=1;w.entities.actors[123]=a;
// Empty genuine Source object update exercises the real publication boundary.
LegacyPacket update{0xa9,Bytes{0,0,0,0,0}};
(void)w.translate(update,0x46010046,0,codec);check(!w.next_quest_status_refresh());
w.entities.actors[123].sent=true;(void)w.translate(update,0x46010046,0,codec);
auto query=w.next_quest_status_refresh();check(query&&query->guid==123&&query->generation==10);
w.quest_status_refresh.sent_pending(*query);auto result=w.translate(status(123),0x46010046,0,codec);Reader r(result);
check(r.le(4)==1&&r.le(4)==0x67001b);r.take(r.le(4));r.end();
// No duplicate query for the same published generation.
(void)w.translate(update,0x46010046,0,codec);check(!w.next_quest_status_refresh());
w.entities.actors[123].generation=11;(void)w.translate(update,0x46010046,0,codec);
query=w.next_quest_status_refresh();check(query&&query->generation==11);w.quest_status_refresh.sent_pending(*query);
w.entities.actors[123].generation=12;auto stale=w.translate(status(123),0x46010046,0,codec);Reader no(stale);check(no.le(4)==0);no.end();
(void)w.translate(update,0x46010046,0,codec);query=w.next_quest_status_refresh();check(query.has_value());
w.quest_status_refresh.sent_pending(*query);
// A genuine Source reward acknowledgement makes this unchanged NPC stale.
Bytes reward;le(reward,1641,4);le(reward,3,4);le(reward,0,4);le(reward,0,4);le(reward,0,4);
const auto before_reward=w.quest_status_refresh.epoch;
auto acknowledged=w.translate({0x191,reward},0x46010046,0,codec);Reader ack(acknowledged);
check(ack.le(4)==1&&ack.le(4)==0x670003);ack.take(ack.le(4));ack.end();
check(w.quest_status_refresh.epoch==before_reward+1&&!w.next_quest_status_refresh());
// A late pre-reward reply emits no guessed or stale marker and cannot
// retire the pending post-reward query, which has not yet been sent.
auto old=w.translate(status(123),0x46010046,0,codec);Reader old_result(old);check(old_result.le(4)==0);old_result.end();
query=w.next_quest_status_refresh();check(query&&query->generation==12);
w.quest_status_refresh.sent_pending(*query);auto fresh=w.translate(status(123),0x46010046,0,codec);Reader fresh_result(fresh);
check(fresh_result.le(4)==1&&fresh_result.le(4)==0x67001b);fresh_result.take(fresh_result.le(4));fresh_result.end();
const auto before_fields=w.quest_status_refresh.epoch;
(void)w.translate(values(999,198,1641),0x46010046,0,codec);check(w.quest_status_refresh.epoch==before_fields);
(void)w.translate(values(w.selected.guid,22,1),0x46010046,0,codec);check(w.quest_status_refresh.epoch==before_fields);
(void)w.translate(values(w.selected.guid,198,1641),0x46010046,0,codec);
check(w.quest_status_refresh.epoch==before_fields+1&&w.next_quest_status_refresh());
const auto before_objective=w.quest_status_refresh.epoch;Bytes objective;le(objective,1641,4);
(void)w.translate({0x198,objective},0x46010046,0,codec);check(w.quest_status_refresh.epoch==before_objective+1);
std::cout<<"Quest status real world translation publication and stale reply passed\n";return 0;
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}}