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

42 lines
3.6 KiB
C++

// Use a synthetic 0x5F reply by default. A supplied packet keeps the original replay mode.
#include "world_translation.hpp"
#include <algorithm>
#include <fstream>
#include <iostream>
#include <iterator>
using namespace gateway;
static void expect(bool v){if(!v)throw Error("empty-name query boundary assertion");}
static Bytes read(const char* p){std::ifstream f(p,std::ios::binary);if(!f)throw Error("private packet unavailable");return Bytes(std::istreambuf_iterator<char>(f),{});}
static Bytes source_reply(uint32_t entry, uint32_t type, uint32_t display, const std::string& name){
Bytes body;
le(body,entry,4); le(body,type,4); le(body,display,4);
cstring(body,name);
for (unsigned i=0; i<4; ++i) cstring(body,"");
for (unsigned i=0; i<24; ++i) le(body,0,4);
return body;
}
int main(int argc,char** argv){try{
const auto actual = argc > 1 ? read(argv[1]) : source_reply(56810,8,192,"");
NativeWorldTranslation world;world.selected.guid=4520;world.realm=70;world.self_created=true;world.location=WorldLocation{};
if(argc>2 && std::string(argv[2])=="--expect-old"){
bool reproduced=false;try{(void)world.translate({0x5f,actual},0x10046,0,nullptr);}catch(const Error& e){reproduced=std::string(e.what())=="empty source game-object name";}
expect(reproduced);std::cout<<"PASS captured empty-name reply reproduces prior world failure\n";return 0;
}
const auto parsed=turtle_gameobject_template(actual);expect(parsed.found && parsed.entry==56810 && parsed.type==8 && parsed.display==192);
expect(std::all_of(parsed.names.begin(),parsed.names.end(),[](const auto& n){return n.empty();}) && parsed.extra_name.empty());
constexpr uint64_t guid=(uint64_t(0xf110)<<48)|(uint64_t(1731)<<24)|19;
const auto modern=forever_game_object_guid(guid,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=modern;actor.sent=true;actor.eligible=true;world.entities.actors.emplace(guid,actor);
Bytes input;le(input,1731,4);append(input,pack_guid(modern));world.gameplay_sent(0x3e0144,input);
const Bytes empty(4,0);expect(world.translate({0x5f,actual},0x10046,0,nullptr)==empty);
expect(world.gameobject_queries.contains(1731) && !world.gameobject_query_evidence && world.self_created && !world.logout_complete);
expect(world.translate({0x5f,source_reply(1731,3,310,"Synthetic fixture chest")},0x10046,0,nullptr)==empty);
expect(world.gameobject_queries.empty() && world.gameobject_query_evidence && world.gameobject_query_evidence->found && world.gameobject_query_evidence->display==310 && world.gameobject_query_evidence->request.generation==9);
expect(world.self_created && !world.logout_complete); // No exception enters the CAPI fatal world-error path.
auto unnamed_chest=parsed;unnamed_chest.entry=1731;unnamed_chest.type=3;
GameObjectTemplateBinding binding;binding.source_guid=guid;binding.request_generation=binding.current_generation=9;binding.entry=1731;binding.realm=70;binding.native_guid=modern;
auto held=forever_gameobject_template(unnamed_chest,binding);expect(!held.packet && std::any_of(held.held.begin(),held.held.end(),[](auto i){return i.reason==GameObjectTemplateHold::MissingName;}));
auto truncated=actual;truncated.pop_back();bool rejected=false;try{(void)turtle_gameobject_template(truncated);}catch(const Error&){rejected=true;}expect(rejected);
std::cout<<"PASS valid empty-name reply, retained query continuation, explicit projection hold and malformed boundary\n";return 0;
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}}