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

33 lines
1.9 KiB
C++

#include "world_translation.hpp"
#include <iostream>
using namespace gateway;
unsigned checks=0,failures=0;
void check(bool ok,const char* why){++checks;if(!ok){++failures;std::cerr<<why<<'\n';}}
int main(){
NativeWorldTranslation world{};world.realm=70;world.selected.guid=42;
auto send=[&](const Bytes& b){return world.translate({0x127,b},0x10046,0,nullptr);};
auto source=[](uint8_t cls,uint32_t mask){Bytes b{cls};le(b,mask,4);return b;};
auto wanted=[](uint8_t cls,uint32_t mask){Bytes b;le(b,1,4);le(b,0x4701e0,4);le(b,5,4);le(b,mask,4);le(b,cls,1);return b;};
// Source login and EffectProficiency send only weapon=2 and armor=4.
// Native writer moves the full uint32 mask before its uint8 class.
for(uint8_t cls:{2,4}){
for(unsigned bit=0;bit<32;++bit)check(send(source(cls,uint32_t(1)<<bit))==wanted(cls,uint32_t(1)<<bit),"proficiency mask bit changed");
for(uint32_t mask:{0u,0xffffffffu,0xaaaaaaaaU,0x55555555U})
check(send(source(cls,mask))==wanted(cls,mask),"proficiency complete mask changed");
}
for(unsigned cls=0;cls<256;++cls){
if(cls==2||cls==4)continue;
bool rejected=false;try{(void)send(source(uint8_t(cls),0xffffffffu));}catch(const std::exception&){rejected=true;}
check(rejected,"unsupported proficiency class admitted");
}
auto full=source(2,0x12345678);
for(size_t n=0;n<full.size();++n){
bool rejected=false;try{(void)send(Bytes(full.begin(),full.begin()+n));}catch(const std::exception&){rejected=true;}
check(rejected,"truncated proficiency admitted");
}
full.push_back(0);bool rejected=false;try{(void)send(full);}catch(const std::exception&){rejected=true;}
check(rejected,"trailing proficiency admitted");
check(send(source(4,0x80000001u))==wanted(4,0x80000001u),"invalid input poisoned subsequent proficiency");
std::cout<<checks<<" checks; "<<failures<<" failures\n";return failures?1:0;
}