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

51 lines
3.9 KiB
C++

#include "entity_translation.hpp"
#include "persistent_ground_fixture.hpp"
#include "serializer.h"
#include <bit>
#include <iostream>
#include <source_location>
using namespace gateway;
static void check(bool ok,const std::source_location where=std::source_location::current()) {
if(!ok)throw Error("persistent ground test line "+std::to_string(where.line()));
}
using ground_fixture::source;
using ground_fixture::update;
int main(){try {
Character self{};self.guid=4528;self.cls=2;self.race=1;self.name="Fixture";
auto fields=ground_fixture::consecration_fields(self.guid);
std::vector<Bytes> calls;
auto codec=[&](uint32_t mode,const Bytes& input){check(mode==GW_CODEC_PERSISTENT_GROUND);calls.push_back(input);Bytes out;le(out,0,2);le(out,1,4);return out;};
NativeEntityTranslation state;state.self_presentation_ready=true;
check(state.translate(update(source,true,fields),self,70,1,0,codec).empty());check(calls.empty()&&state.persistent_ground.empty());
state.persistent_ground_enabled=true;
auto out=state.translate(update(source,true,fields),self,70,1,0,codec);check(out.size()==1&&calls.size()==1&&calls.back()[0]==0);
check(state.actors.at(source).sent&&state.actors.at(source).kind==6);
Reader id(state.actors.at(source).modern);check(id.le(8)==0x1000001u);check((id.le(8)>>58)==12);
auto tick=state.persistent_ground.at(source).cast_time;auto generation=state.actors.at(source).generation;
out=state.translate(update(source,false,{{10,std::bit_cast<uint32_t>(12.0f)}}),self,70,1,0,codec);
check(out.size()==1&&calls.size()==2&&calls.back()[0]==1);
const auto& ground=state.persistent_ground.at(source);check(ground.radius==12&&ground.caster==4528&&ground.spell==26573&&ground.cast_time==tick);
check(state.translate(update(source,false,{{40,17}}),self,70,1,0,codec).empty());
// Full caster GUID survives a partial update; unbound casters are held.
out=state.translate(update(source,false,{{7,0xf1300000}}),self,70,1,0,codec);check(out.empty());
check(state.persistent_ground.at(source).caster==0xf1300000000011b0ULL);
out=state.translate(update(source,false,{{7,0}}),self,70,1,0,codec);check(out.size()==1);
// Authoritative destroy retires the exact emitted identity; late values do nothing.
Bytes destroy;le(destroy,source,8);out=state.translate({0xaa,destroy},self,70,1,0,codec);
check(out.size()==1&&!state.actors.contains(source)&&!state.persistent_ground.contains(source));
check(state.translate(update(source,false,{{10,std::bit_cast<uint32_t>(4.0f)}}),self,70,1,0,codec).empty());
out=state.translate(update(source,true,fields),self,70,1,0,codec);check(out.size()==1&&state.actors.at(source).generation>generation);
// Source Flare flags are not silently narrowed to the area enum.
auto flare=fields;flare[8]=0x10;out=state.translate(update(source+1,true,flare),self,70,1,0,codec);check(out.empty()&&!state.actors.at(source+1).sent);
// A create awaiting a live self binding may be emitted only while Source remains alive.
NativeEntityTranslation waiting;waiting.persistent_ground_enabled=true;
check(waiting.translate(update(source,true,fields),self,70,1,0,codec).empty());
waiting.self_presentation_ready=true;out=waiting.translate({0x51,{}},self,70,1,0,codec);check(out.size()==1);
// New map invalidates old map-local identities without stale creates/removals.
check(waiting.translate({0x51,{}},self,70,1,1,codec).empty());check(waiting.persistent_ground.empty()&&!waiting.actors.contains(source));
// No usable visual link: keep the real source object unpresented.
fields[3]=fields[9]=51968;out=state.translate(update(source+2,true,fields),self,70,1,0,codec);check(out.empty()&&!state.actors.at(source+2).sent);
std::cout<<"Persistent ground source lifecycle, full GUID, sparse retention, caster/visual gates and private default passed\n";
return 0;
}catch(const std::exception&e){std::cerr<<e.what()<<'\n';return 1;}}