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

30 lines
2.3 KiB
C++

#include "gateway/world.hpp"
#include <iostream>
using namespace gateway;
void require(bool value){if(!value)throw Error("swimming teleport regression failed");}
template<class F>void reject(F call){bool failed=false;try{call();}catch(const Error&){failed=true;}require(failed);}
void flags(Bytes& body,uint32_t value){for(unsigned i=0;i<4;++i)body.at(7+i)=uint8_t(value>>(8*i));}
int main(){try{
// Actual C53W15cRollGM seq946 Source0xC7: self4509, Northshire destination,
// swimming pitch0, fallTime883. Source Objects/Object.cpp writes pitch first.
const auto captured=unhex("039d11000000000000200006c82d000acf0bc6211004c36a3ea742984c9a400000000073030000");
const auto swim=turtle_near_teleport(captured,4509);
require(swim.guid==4509&&swim.sequence==0);
require(swim.position==std::array<float,4>{-8947.759765625f,-132.06300354003906f,83.62190246582031f,4.821849822998047f});
auto grounded=captured;flags(grounded,0);grounded.erase(grounded.begin()+31,grounded.begin()+35);
const auto expected=forever_near_teleport(turtle_near_teleport(grounded,4509),70);
require(forever_near_teleport(swim,70)==expected);
for(uint32_t mode:{0u,0x40u,0x80u,0x1000u,0x10000000u,0x20000000u,0x40000000u,0x70001000u}){
auto old=grounded;flags(old,mode);require(forever_near_teleport(turtle_near_teleport(old,4509),70)==expected);
}
auto jumping=captured;flags(jumping,0x202000);for(unsigned i=0;i<4;++i)le(jumping,0,4);
require(forever_near_teleport(turtle_near_teleport(jumping,4509),70)==expected);
for(size_t n=0;n<captured.size();++n)reject([&]{turtle_near_teleport(std::span(captured).first(n),4509);});
auto extra=captured;extra.push_back(0);reject([&]{turtle_near_teleport(extra,4509);});
auto missing=captured;missing.erase(missing.begin()+31,missing.begin()+35);reject([&]{turtle_near_teleport(missing,4509);});
auto bad_pitch=captured;bad_pitch[31]=0;bad_pitch[32]=0;bad_pitch[33]=0x80;bad_pitch[34]=0x7f;reject([&]{turtle_near_teleport(bad_pitch,4509);});
auto transport=captured;flags(transport,0x02000000);reject([&]{turtle_near_teleport(transport,4509);});
reject([&]{turtle_near_teleport(captured,4514);});
std::cout<<"PASS exact captured swimming teleport, unchanged native destination/non-swim modes, optional-field order, finite pitch and malformed/foreign holds\n";
}catch(const std::exception& error){std::cerr<<error.what()<<'\n';return 1;}}