Files
WoW-Hybrid-gateway/tests/primary_profession_test.cpp

154 lines
6.8 KiB
C++

#include "gateway/professions.hpp"
#include "gateway/profession_delta.hpp"
#include <map>
#include <iostream>
#include <vector>
using namespace gateway;
static void check(bool value){if(!value)throw Error("Primary profession fixture failed");}
template<class F>void rejects(F f){try{f();}catch(const Error&){return;}throw Error("Expected invalid profession state rejection");}
// Captured Blesisi self-create, source sequence 1, 4128 compressed bytes,
// before Skinning was learned. Only decoded skill fields are retained.
// The later 4123-byte failing frame was not present in the available capture.
static void blesisi_regression(){
std::map<uint32_t,uint32_t> fields{
{718,43},
{719,19661100},
{720,196608},
{721,44},
{722,19661030},
{724,54},
{725,19661100},
{726,196608},
{727,55},
{728,19661048},
{729,196608},
{730,95},
{731,19661100},
{732,1310756},
{733,98},
{734,19661100},
{736,131201},
{737,9830475},
{739,65678},
{740,4915215},
{742,160},
{743,19660845},
{744,196608},
{745,162},
{746,19661100},
{748,172},
{749,19660850},
{751,183},
{752,19661100},
{754,184},
{755,19661100},
{757,65721},
{758,4915260},
{760,262341},
{761,19661054},
{763,229},
{764,19661086},
{766,267},
{767,19661100},
{769,293},
{770,65537},
{772,65869},
{773,4915239},
{775,413},
{776,65537},
{778,414},
{779,65537},
{781,415},
{782,65537},
{784,433},
{785,65537},
{787,594},
{788,19661100},
{790,754},
{791,19661100},
{793,66298},
{794,4915275},
};
auto read=[&](uint32_t i){auto it=fields.find(i);return it==fields.end()?0:it->second;};
check(primary_profession_lines(read,SourceSkillFirst)==std::array<int32_t,2>{197,333});
ProfessionSkillState state;state.initialize(fields,SourceSkillFirst);
unsigned slot=0;while(slot<128 && read(SourceSkillFirst+3*slot))++slot;
check(slot<128);
// Reproduce the reported learn/setskill (confirmed read-only in character_skills).
// Slot placement is synthetic; the captured prior create is unchanged above.
std::map<uint32_t,uint32_t> learned{{SourceSkillFirst+3*slot,393},
{SourceSkillFirst+3*slot+1,300u|(300u<<16)}};
auto delta=state.observe(learned,SourceSkillFirst);
check(!delta.slot_mask && delta.slots==std::array<int32_t,2>{197,333});
bool skin=false,child=false;
for(auto row:delta.rows){
if(row.id==393)skin=row.rank==300 && row.maximum==300;
if(row.id==2947)child=row.rank==300 && row.maximum==300;
}
check(skin&&child);
for(auto [i,v]:learned)fields[i]=v;
auto saved=fields;
check(primary_profession_lines(read,SourceSkillFirst)==std::array<int32_t,2>{197,333});
ProfessionSkillState reconnect;reconnect.initialize(fields,SourceSkillFirst);
// Losing a summary profession promotes the third, without dropping its skill row.
auto removed=reconnect.observe(std::map<uint32_t,uint32_t>{{SourceSkillFirst+3*14,0},
{SourceSkillFirst+3*14+1,0}},SourceSkillFirst);
check(removed.slot_mask==1 && removed.slots==std::array<int32_t,2>{393,333});
check(fields==saved);
}
static void full_skill_catalogue(){
std::map<uint32_t,uint32_t> fields;
// Fill every Source slot. Non-profession IDs are deliberately opaque to this
// summary helper; it must not restrict unrelated skills, spells or inventory.
for(unsigned slot=0;slot<128;++slot){
fields[3*slot]=10000+slot;fields[3*slot+1]=65535u|(65535u<<16);
fields[3*slot+2]=0x0003fff9;
}
unsigned slot=0;
for(auto id:source_skills::PrimaryProfessions)fields[3*slot++]=id;
auto read=[&](uint32_t i){return fields.at(i);};
check(primary_profession_lines(read,0)==std::array<int32_t,2>{164,165});
auto saved=fields;unsigned children=0;
profession_child_views(read,0,[&](auto v){check(v.rank==65535 && v.max_rank==65535);++children;});
check(children==9 && fields==saved); // Jewelcrafting has no generated child.
ProfessionSkillState state;state.initialize(fields,0);
// Validate duplicates even beyond the two summary slots.
fields[3*127]=393;rejects([&]{primary_profession_lines(read,0);});
}
int main(){
blesisi_regression();full_skill_catalogue();
for(unsigned tier=1;tier<=4;++tier){
check(profession_skill_step(164,1u|((75u*tier)<<16))==tier);
check(profession_skill_step(185,1u|((75u*tier)<<16))==tier);
}
check(profession_skill_step(164|(2u<<16),300u<<16)==2); // Explicit source step wins.
check(profession_skill_step(43,300u<<16)==0); // Weapon caps are not profession ranks.
check(profession_skill_step(98,300u<<16)==0); // Nor are languages.
std::map<uint32_t,uint32_t> fields;
auto read=[&](uint32_t i){auto r=fields.find(i);return r==fields.end()?0:r->second;};
auto set=[&](unsigned slot,unsigned id,unsigned rank){fields[500+3*slot]=id|(4u<<16);fields[501+3*slot]=rank|(300u<<16);};
auto views=[&](){std::vector<ProfessionChildView> out;profession_child_views(read,500,[&](auto v){out.push_back(v);});return out;};
check(views().empty());
check(primary_profession_lines(read,500)==std::array<int32_t,2>{0,0});
set(0,43,300);set(1,129,300);set(2,185,300);set(3,356,178); // Weapon/secondary skills do not own primary slots.
check(primary_profession_lines(read,500)==std::array<int32_t,2>{0,0});
set(11,164,300);set(39,186,300);
check(primary_profession_lines(read,500)==std::array<int32_t,2>{164,186});
auto children=views();check(children.size()==5);
bool smith=false;
for(auto v:children){
check(v.slot>=128&&v.slot<300&&v.max_rank==300&&v.step==4);
if(v.id==2938){smith=true;check(v.rank==300);}
}
check(smith);
fields[500+3*11]=164;fields[502+3*11]=0x0003ffff;
children=views();for(auto v:children)if(v.id==2938)check(v.step==4&&v.temp_bonus==65535&&v.perm_bonus==3);
fields[501+3*39]=0;check(primary_profession_lines(read,500)==std::array<int32_t,2>{164,0});
set(39,755,1);check(primary_profession_lines(read,500)==std::array<int32_t,2>{164,755}); // Source custom profession, not a character-ID exception.
set(80,171,1);check(primary_profession_lines(read,500)==std::array<int32_t,2>{164,755});
set(80,164,1);rejects([&]{primary_profession_lines(read,500);});
rejects([&]{views();});
set(80,2938,1);rejects([&]{views();});
std::cout<<"Source primary categories, sparse slots, secondary exclusion, zero rank, duplicates, all 128 skill slots, all primary professions and Blesisi third-profession regression passed\n";
}