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

75 lines
4.5 KiB
C++

#include "world_translation.hpp"
#include "gateway/chat.hpp"
#include <iostream>
using namespace gateway;
namespace {
void require(bool value,const char* why){if(!value)throw Error(why);}
Bytes fixture(size_t note,size_t officer){
Bytes out;le(out,2,4);cstring(out,"");cstring(out,"");le(out,1,4);le(out,0x41,4);
for(uint64_t guid:{182,183}){
le(out,guid,8);le(out,1,1);cstring(out,guid==182?"One":"Two");
le(out,0,4);le(out,60,1);le(out,1,1);le(out,0,4);
cstring(out,std::string(guid==182?note:0,'n'));
cstring(out,std::string(guid==182?officer:0,'o'));
}
return out;
}
void no_packets(const Bytes& out){Reader r(out);require(r.le(4)==0,"held roster published a packet");r.end();}
template<class F> void invalid(F call){
bool caught=false;
try{call();}catch(const GuildRosterHold&){throw Error("malformed Source packet treated as presentation hold");}
catch(const Error&){caught=true;}
require(caught,"malformed Source roster accepted");
}
void bank_context(NativeWorldTranslation& world){
const uint64_t npc=(uint64_t(0xf130)<<48)|(uint64_t(80918)<<24)|17;
auto modern=forever_creature_guid(npc,80918,70,1);
NativeEntityTranslation::Actor actor;actor.entry=80918;actor.kind=3;actor.sent=true;actor.generation=1;actor.modern=modern;
world.entities.actors.emplace(npc,actor);
world.bank_window=NativeWorldTranslation::BankWindow{npc,1,22,1,modern,true};
world.guild_bank.metadata_ready=true;world.guild_bank.money=1;
world.bank_roster_pending=true;
}
}
int main(){
try{
RosterRealm realm{};realm.realm_id=70;realm.virtual_address=0x46010046;
NativeWorldTranslation world{};world.realm=70;world.self_created=true;
world.guild_id=22;world.guild_rank=0;world.selected.guid=182;
// Both string fields independently cross the original 129-byte
// storage capacity. Source parsing must still preserve every byte.
for(size_t length:{129,255})for(bool officer:{false,true}){
auto source=fixture(officer?0:length,officer?length:0);
auto roster=turtle_guild_roster(source);
require((officer?roster.members[0].officer_note:roster.members[0].note).size()==length,"Source text was truncated");
bool held=false;try{forever_guild_roster(roster,realm);}catch(const GuildRosterHold&){held=true;}
require(held,"original native note capacity not enforced");
no_packets(world.translate({0x8a,source},realm.virtual_address,0,nullptr));
}
// The successful original 868-member framing is a retained receipt;
// this is only the changed admission edge and recovery in one world.
auto restored=world.translate({0x8a,fixture(128,128)},realm.virtual_address,0,nullptr);
Reader ok(restored);require(ok.le(4)==1 && ok.le(4)==0x530003,"representable roster did not recover");
ok.take(ok.le(4));ok.end();
bank_context(world);
auto held_bank=world.translate({0x8a,fixture(129,0)},realm.virtual_address,0,nullptr);
require(world.bank_rank_rights==std::optional(std::vector<uint32_t>{0x41}) && !world.bank_roster_pending,"held presentation discarded rank permissions");
Reader bank(held_bank);require(bank.le(4)==1 && bank.le(4)==0x530028,"held roster suppressed independent bank permissions");
auto payload=bank.take(bank.le(4));Reader permissions(payload);
require(permissions.le(4)==0 && permissions.le(4)==0x80041,"server bank rights changed");
permissions.take(permissions.left());bank.end();
world.bank_roster_pending=true;world.bank_rank_rights=std::vector<uint32_t>{0x80};
auto malformed=fixture(129,0);malformed.pop_back();
invalid([&]{world.translate({0x8a,malformed},realm.virtual_address,0,nullptr);});
auto trailing=fixture(0,255);trailing.push_back(1);
invalid([&]{world.translate({0x8a,trailing},realm.virtual_address,0,nullptr);});
require(world.bank_roster_pending && world.bank_rank_rights==std::optional(std::vector<uint32_t>{0x80}),"partial Source parse changed rights");
auto oversized=fixture(256,0);
invalid([&]{world.translate({0x8a,oversized},realm.virtual_address,0,nullptr);});
world.guild_id=0;
no_packets(world.translate({0x8a,fixture(129,0)},realm.virtual_address,0,nullptr));
require(world.bank_roster_pending,"late foreign roster changed bank state");
std::cout<<"PASS guild note capacity, nonfatal hold, recovery, bank rights and strict Source parsing\n";
}catch(const std::exception& error){std::cerr<<error.what()<<'\n';return 1;}
}