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

46 lines
3.3 KiB
C++

#include "world_translation.hpp"
#include <cstdlib>
#include <iostream>
using namespace gateway;
static void expect(bool value){if(!value)throw Error("GameObjUse fixture assertion");}
static void held(const NativeWorldTranslation& world,uint32_t opcode,const Bytes& body){
bool rejected=false;try{(void)world.gameplay(opcode,body);}catch(const Error&){rejected=true;}expect(rejected);
}
int main(){try{
constexpr uint64_t source=(uint64_t(0xf110)<<48)|(uint64_t(1731)<<24)|19;
NativeWorldTranslation world;world.selected.guid=4520;world.realm=70;
world.location=WorldLocation{};world.location->map=0;world.self_created=true;
auto native=forever_game_object_guid(source,1731,70,0);
NativeEntityTranslation::Actor actor;actor.entry=1731;actor.kind=5;actor.generation=9;
actor.presentation_realm=70;actor.presentation_map=0;actor.modern=native;actor.sent=true;actor.eligible=true;
world.entities.actors.emplace(source,actor);Bytes request=pack_guid(native);
auto packet=world.gameplay(0x3f008b,request);
Bytes expected;le(expected,source,8);expect(packet.opcode==0xb1 && packet.body==expected);
// No aliases: report-only criteria and unrelated time-offset messages do
// not become a second Use or an ordinary spell request.
held(world,0x3f008a,request);held(world,0x3f008c,request);
{auto copy=world;const auto time=copy.gameplay(0x4400ca,{});expect(time.opcode==0x1ce && time.body.empty());} // a time query, never a Use
for(size_t n=0;n<request.size();++n)held(world,0x3f008b,Bytes(request.begin(),request.begin()+n));
auto tail=request;tail.push_back(0);held(world,0x3f008b,tail);
auto changed=world;changed.self_created=false;held(changed,0x3f008b,request);
changed=world;changed.location.reset();held(changed,0x3f008b,request);
changed=world;changed.pending_teleport=NearTeleport{};held(changed,0x3f008b,request);
changed=world;changed.entities.actors.clear();held(changed,0x3f008b,request);
for(uint8_t kind:{uint8_t(0),uint8_t(3),uint8_t(4),uint8_t(7)}){
changed=world;changed.entities.actors.at(source).kind=kind;held(changed,0x3f008b,request);
}
changed=world;changed.entities.actors.at(source).sent=false;held(changed,0x3f008b,request);
changed=world;changed.entities.actors.at(source).eligible=false;held(changed,0x3f008b,request);
changed=world;changed.entities.actors.at(source).generation=0;held(changed,0x3f008b,request);
changed=world;changed.realm=71;held(changed,0x3f008b,request);
changed=world;changed.location->map=1;held(changed,0x3f008b,request);
changed=world;changed.entities.actors.at(source).presentation_map=1;held(changed,0x3f008b,request);
changed=world;changed.entities.actors.at(source).modern=forever_game_object_guid(source,1731,71,0);
held(changed,0x3f008b,pack_guid(changed.entities.actors.at(source).modern));
auto unbound=forever_game_object_guid(source+1,1731,70,0);held(world,0x3f008b,pack_guid(unbound));
// Repeated real button presses remain independent Use requests: this
// translator does not invent retry, cast, loot or source interaction success.
expect(world.gameplay(0x3f008b,request).body==expected);
std::cout<<"GameObjUse dispatcher and binding guards PASS\n";return EXIT_SUCCESS;
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return EXIT_FAILURE;}}