Files
2026-11-23 03:28:32 +02:00

38 lines
2.9 KiB
C++

// Synthetic fixtures: Tortoise 0x26F parse, validation, mode-76 K1/K2 DTOs, SetPetSlot mapping.
#include "gateway/pet_stable.hpp"
#include <cassert>
#include <iostream>
using namespace gateway;
template<class F>static void rejects(F f){bool r=false;try{f();}catch(const Error&){r=true;}assert(r);}
static void row(Bytes& b,uint32_t n,uint32_t e,uint32_t l,const std::string& name,uint32_t loy,uint8_t kind){le(b,n,4);le(b,e,4);le(b,l,4);b.insert(b.end(),name.begin(),name.end());b.push_back(0);le(b,loy,4);le(b,kind,1);}
static Bytes list(uint8_t slots,std::vector<std::tuple<uint32_t,uint32_t,uint8_t>> rows){
Bytes b;le(b,0xF130000000000077ull,8);le(b,rows.size(),1);le(b,slots,1);
for(auto [n,e,k]:rows)row(b,n,e,12,"Pet"+std::to_string(n),4,k);return b;
}
int main(){
auto l=turtle_stable_list(list(2,{{11,3000,1},{12,3001,2},{13,3002,2}}));
assert(l.npc==0xF130000000000077ull && l.slots==2 && l.pets.size()==3 && l.pets[0].current && l.pets[2].name=="Pet13");
validate_stable_list(l);
rejects([&]{validate_stable_list(turtle_stable_list(list(1,{{11,3000,1},{12,3001,2},{13,3002,2}})));}); // over capacity
rejects([&]{validate_stable_list(turtle_stable_list(list(2,{{12,3001,2},{11,3000,1}})));}); // current not first
rejects([&]{validate_stable_list(turtle_stable_list(list(2,{{11,3000,1},{11,3001,2}})));}); // duplicate number
rejects([&]{turtle_stable_list(list(2,{{11,3000,3}}));}); // unknown kind
{auto b=list(2,{});b.push_back(0);rejects([&]{turtle_stable_list(b);});}
// K1 round trip; metrics zero; unknown display refuses.
auto disp=[](uint32_t e){return e+100000;};
auto k1=pet_stable_from_input(pet_stable_snapshot_input(70,1,4509,l,disp));
assert(k1.kind==1 && k1.realm==70 && k1.map==1 && k1.self==4509 && k1.list.pets.size()==3 && k1.displays[1]==103001 && k1.metrics[2].happiness==0 && k1.list.pets[1].name=="Pet12");
rejects([&]{pet_stable_snapshot_input(70,1,4509,l,[](uint32_t){return 0u;});});
auto k2=pet_stable_from_input(pet_stable_close_input(70,1,4509));assert(k2.kind==2 && k2.list.pets.empty());
// SetPetSlot: current -> stable = 0x270; stabled -> active with current = SWAP 0x275; without = UNSTABLE 0x271.
auto q=[](uint32_t n,uint8_t d){return NativeSetPetSlot{n,d,{}};};
assert(source_set_pet_slot(q(11,1),l)->opcode==0x270);
auto swap=source_set_pet_slot(q(12,0),l);assert(swap->opcode==0x275);{Reader r(swap->body);assert(r.le(8)==l.npc && r.le(4)==12);r.end();}
auto solo=l;solo.pets.erase(solo.pets.begin());assert(source_set_pet_slot(q(12,0),solo)->opcode==0x271);
assert(!source_set_pet_slot(q(12,2),l)); // stable-to-stable has no Source form
assert(!source_set_pet_slot(q(11,0),l)); // already active
assert(!source_set_pet_slot(q(99,0),l)); // unknown pet
assert(!source_set_pet_slot(q(11,3),l)); // beyond purchased slots
std::cout<<"pet stable PASS\n";
}