Files
Dreierpack-Manager/tests/modern_coach_identity_tests.cpp
T

28 lines
4.0 KiB
C++

// SPDX-License-Identifier: GPL-3.0-only
// Authored frozen coach records; no original data or simulated game decisions.
#include "modern/content/ui_contract.hpp"
#include "formats/executable_layout.hpp"
#include <iostream>
#include <set>
#include <stdexcept>
using namespace bmh;
namespace {using J=cli::Json;using O=J::Object;const J& at(const J& j,const char* k){return j.object()->at(k);}void check(bool ok,const char* why){if(!ok)throw std::runtime_error(why);}}
int main() try {
modern::ModernState g;g.manager_records.resize(5*0xb0c);g.manager_ids={"manager:1","manager:2","manager:3","manager:4"};g.manager_serial=4;g.manager_teams={no_team()};g.world_club_id.resize(no_team()+1);g.world_club_name.resize(no_team()+1);
for(int i=0;i<4;++i){g.world_club_id[i]="club:"+std::to_string(i);g.world_club_name[i]="Club "+std::to_string(i);g.manager_presentations.push_back({g.manager_ids[i],"Human "+std::string(1,char('A'+i)),i%2?"photo":"painted"});}
g.world_club_id[no_team()]="nation:de";g.world_club_name[no_team()]="Synthetic Nation";
for(int r=0;r<5;++r){const auto team=r==0?no_team():r==4?0:r;const auto record=size_t(r)*0xb0c;g.manager_records[record+0x290]=team&255;g.manager_records[record+0x291]=(team>>8)&255;const std::string name=r==0?"Raw C":r==4?"Raw A":"Raw "+std::string(1,char('A'+r));for(size_t n=0;n<name.size();++n)g.manager_records[record+0xa8+n]=name[n];g.manager_records[record+0x221]=r==0?2:r==4?0:r;}
g.manager_records[2*0xb0c+0x21c]=1;
g.memory.add_block(layout::CoachActive,1);g.memory.set8(layout::CoachActive,1);g.memory.add_block(layout::OriginalManagerCount,1);g.memory.set8(layout::OriginalManagerCount,4);g.memory.add_block(layout::CompetitionSelection,4);g.memory.set32(layout::CompetitionSelection,3);
check(g.human_manager_slot(0)==2&&g.manager_record_slot(2)==0&&g.manager_record_slot(0)==4&&g.human_manager_slot(4)==0,"coach/backup record mapping wrong");
const auto bytes=g.manager_records;modern::UiContext c;c.manager=0;const auto session=modern::ui_read(g,c,O{{"kind","session"}});check(*at(at(session,"meta"),"scope").object()->at("managerId").string()=="manager:3","scope owns wrong human");
const auto &people=*at(at(session,"data"),"managers").array();check(people.size()==4,"waiting humans disappeared");std::set<std::string> ids;
for(int i=0;i<4;++i){const auto &m=people.at(size_t(i));check(*at(m,"id").string()==g.manager_ids[i],"human IDs reordered");ids.insert(*at(m,"id").string());check(*at(m,"teamId").string()==(i==2?"nation:de":"club:"+std::to_string(i)),"waiting human club lost");}
check(ids.size()==4&&*at(people[0],"name").string()=="Human A"&&*at(people[2],"name").string()=="Human C","canonical coach names mixed");
const auto desk=modern::ui_read(g,c,O{{"kind","desktop"},{"managerId","manager:3"}});const auto &manager=at(at(desk,"data"),"manager");check(*at(manager,"id").string()=="manager:3"&&*at(manager,"portraitGuiKey").string()=="gui:manager/painted/2","coach portrait/name belongs to wrong person");check(*at(manager,"slot").integer()==2&&*at(manager,"runtimeSlot").integer()==0,"human and runtime slot conflated");
const auto wrong=modern::ui_read(g,c,O{{"kind","desktop"},{"managerId","manager:1"}});check(*at(wrong,"code").string()=="manager_not_active","displaced human may own coach request");
g.manager_presentations.clear();const auto old=modern::ui_read(g,c,O{{"kind","desktop"}});check(*at(at(at(old,"data"),"manager"),"name").string()=="Raw C"&&*at(at(at(old,"data"),"manager"),"id").string()=="manager:3","older save fallback lost coach identity");check(bytes==g.manager_records,"projection changed original records");
g.memory.set32(layout::CompetitionSelection,2);check(g.human_manager_slot(0)==0,"world-only source chooser is not first human");g.memory.set8(layout::CoachActive,0);g.manager_teams={0,1,2,3};check(g.human_manager_slot(2)==2&&g.manager_record_slot(0)==0,"normal club mapping changed");
std::cout<<"coach stable identity, backup clubs, older metadata and read-only projection passed\n";return 0;
} catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}