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

70 lines
3.8 KiB
C++

#include "initial_spell_ids.hpp"
#include "wine_wire_abi.h"
#include <array>
#include <stdexcept>
#include <vector>
namespace {
void require(bool ok){if(!ok)throw std::runtime_error("initial Source spell copy regression");}
uint64_t number(const std::vector<uint8_t>& bytes,size_t offset,unsigned width){
uint64_t value=0;for(unsigned i=0;i<width;++i)value|=uint64_t(bytes.at(offset+i))<<(8*i);return value;
}
}
int main(){
static_assert(GW_WIRE_TRANSPORT_OPEN_IPV4_BYTES==44 && GW_WIRE_INITIAL_SPELL_IDS==45);
static_assert(sizeof(gw_wire_call)==640);
NativeWorldTranslation world{};
world.selected.guid=0x0102030405060708ull;
world.talent_spells_ready=true;
// Deliberately preSelf: holding the original world FIFO cannot require
// self creation to obtain this already parsed Source snapshot.
require(!world.self_created && !world.location);
std::array<gateway::Character,2> roster{};
roster[0].guid=99;roster[1].guid=world.selected.guid;
std::vector<uint8_t> output(12+4096*4+8,0xa5);
uint32_t required=123;
auto copy=[&](bool authenticated=true,bool roster_seen=true,uint32_t capacity=16396){
return gateway::native::copy_initial_spell_ids(authenticated,roster_seen,roster,&world,output.data(),capacity,&required);
};
// Empty-ready differs from unavailable; no invented spell is supplied.
require(copy()==0 && required==12);
require(number(output,0,8)==world.selected.guid && number(output,8,4)==0 && output[12]==0xa5);
world.spells={51602,23922,45595,23922};
const auto before=world.spells;
std::fill(output.begin(),output.end(),0xa5);
require(copy()==0 && required==24);
require(number(output,0,8)==0x0102030405060708ull && number(output,8,4)==3);
require(number(output,12,4)==23922 && number(output,16,4)==45595 && number(output,20,4)==51602);
require(world.spells==before && !world.self_created && output[24]==0xa5);
auto first=output;
require(copy()==0 && output==first); // No consumption or generation change.
// Capacity retry must not leak a prefix or consume the cached list.
std::fill(output.begin(),output.end(),0xa5);
require(copy(true,true,23)==-3 && required==24);
require(std::all_of(output.begin(),output.end(),[](auto v){return v==0xa5;}) && world.spells==before);
require(gateway::native::copy_initial_spell_ids(true,true,roster,&world,nullptr,0,&required)==-3 && required==24);
auto rejected=[&](bool authenticated=true,bool roster_seen=true){
required=123;require(copy(authenticated,roster_seen)==-1 && required==0);
require(std::all_of(output.begin(),output.end(),[](auto v){return v==0xa5;}));
};
rejected(false);rejected(true,false);
world.talent_spells_ready=false;rejected();world.talent_spells_ready=true;
world.logout_complete=true;rejected();world.logout_complete=false;
auto guid=world.selected.guid;
world.selected.guid=0;rejected();world.selected.guid=1234;rejected();world.selected.guid=guid;
require(gateway::native::copy_initial_spell_ids(true,true,{},&world,output.data(),16396,&required)==-1 && !required);
require(gateway::native::copy_initial_spell_ids(true,true,roster,nullptr,output.data(),16396,&required)==-1 && !required);
require(gateway::native::copy_initial_spell_ids(true,true,roster,&world,nullptr,12,&required)==-1 && !required);
require(gateway::native::copy_initial_spell_ids(true,true,roster,&world,output.data(),16396,nullptr)==-1);
require(copy(true,true,GW_CODEC_BOUND+1)==-1 && !required);
// Test the inclusive bound with the actual output framing and canary.
world.spells.clear();for(uint32_t id=1;id<=4096;++id)world.spells.insert(id);
require(copy()==0 && required==16396 && number(output,8,4)==4096 && number(output,16392,4)==4096 && output[16396]==0xa5);
std::fill(output.begin(),output.end(),0xa5);
world.spells.insert(4097);rejected();
}