// SPDX-License-Identifier: GPL-3.0-only #include "modern/ui/demo_career_reports.hpp" #include #include #include #include using namespace bmh::modern_ui; namespace { void require(bool ok,const char *message){if(!ok)throw std::runtime_error(message);} std::string id(int i){return "club:career-test-"+std::to_string(i);} struct Fixture { fs::path root;std::shared_ptr world; explicit Fixture(int count) { root=fs::temp_directory_path()/("openbmh-career-reports-"+std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));fs::create_directories(root/"world"); const auto write=[&](const std::string &name,const Json &value){bmh::editor::write_atomic(root/name,value.dump());}; write("manifest.json",{{"format","openbmh-world"},{"kind","world"},{"format_version","1.1"},{"id","world:synthetic-career-reports"},{"start_date","2026-07-01"},{"requires",{"editor:world-v1"}},{"x-editor",{{"profile","editor-world-v1"}}}}); write("world/nations.json",{{"items",{{{"id","nation:de"},{"name","Synthetic nation"}}}}}); write("world/competitions.json",{{"items",{{{"id","competition:career-test"},{"type","league"},{"nation","nation:de"},{"name","Synthetic league"}}}}}); Json clubs=Json::array();for(int i=0;irows("clubs"); const auto current=demo_achievements(*f.world,s,0);require(current.at("ok")==true&¤t.at("available")==true&¤t.at("fictional")==true,"Career report unavailable for actual first-manager club"); require(current.at("club")==id(4)&¤t.at("manager")=="Synthetic first manager","Career projection silently selected another manager or club"); require(current.at("first_year")==2019&¤t.at("last_year")==2026&¤t.at("range")=="2019/20 – 2026/27","Career window does not end at the last completed season"); require(current.at("charts").size()==3&¤t.at("history").size()==12,"Expected three charts and twelve historical seasons"); for(int page=0;page<=4;++page) { const auto view=demo_achievements(*f.world,s,page);require(view.at("last_year")==2026-page&&view.at("first_year")==2019-page,"Page must shift by one season, not eight"); require(view.at("history")==current.at("history"),"Club history changed when paging chart window"); for(const auto &chart:view.at("charts")) { require(chart.at("seasons").size()==8,"Chart does not contain eight seasons"); for(size_t i=0;i<8;++i)require(chart.at("seasons")[i].at("year")==2019-page+int(i),"Chart years not chronological"); require(chart.at("latest")==chart.at("seasons")[7],"Latest summary disagrees with visible last season"); } } const auto older=demo_achievements(*f.world,s,4);std::set tiers; for(const auto &r:older.at("charts")[0].at("seasons"))tiers.insert(r.at("tier").get()); require(tiers==std::set({1,2,3,4}),"Four league bands were collapsed"); const auto &league=current.at("charts")[0].at("latest");require(league.at("value")==1&&league.at("winner")==true&&league.at("label")=="1. Platz"&&league.at("tier")==1,"Gold championship sample or title highlighting changed"); require(current.at("charts")[1].at("latest").at("label")=="Sieger"&¤t.at("charts")[2].at("latest").at("label")=="Viertelfinale","Cup/Europe result labels changed"); bool zero=false;for(const auto &r:current.at("history"))for(const auto &value:r.at("results"))if(value.at("value")==0){zero=true;require(value.at("label")=="Nicht teilgenommen"&&value.at("caption")=="–"&&value.at("winner")==false,"Nonparticipation was fabricated into a played result or title");} require(zero,"Historical demo lost its nonparticipation fixture"); require(demo_achievements(*f.world,s,-1).value("ok",true)==false&&demo_achievements(*f.world,s,5).value("ok",true)==false,"Out-of-range career page accepted"); const auto scores=demo_highscores(*f.world,s);require(scores.at("rows").size()==8,"Highscore must show at most eight existing clubs");std::set seen; for(size_t i=0;i<8;++i) { const auto &r=scores.at("rows")[i];const auto club=r.at("club").get();require(f.world->find("clubs",club)&&club!="nt:synthetic"&&seen.insert(club).second,"Unknown, national or duplicated club in highscore"); require(r.at("rank")==i+1&&r.at("points")==18200-int(i)*1575&&r.at("championships")==8-int(i%5)&&r.at("cups")==6-int(i%4)&&r.at("europe")==3-int(i%3)&&r.at("fictional")==true,"Highscore order/totals differ from deterministic Gold preview"); } require(scores.at("rows")[0].at("club")==id(4)&&scores.at("rows")[0].at("manager")=="Synthetic first manager"&&scores.at("rows")[1].at("manager")=="Chris Winter","First manager or explicitly fictional manager fixtures changed"); auto other=s;other["reports"]={{"league","elsewhere"},{"filter",0}};other["cash"]=0; require(demo_achievements(*f.world,other,0)==current&&demo_highscores(*f.world,other)==scores,"Career projection depends on unrelated filters or wallet"); other=s;other["managers"][0]["club"]=id(7);other["managers"][0]["name"]="Changed snapshot name"; require(demo_achievements(*f.world,other).at("club")==id(7)&&demo_highscores(*f.world,other).at("rows")[0].at("manager")=="Changed snapshot name","Manager switch retained a stale identity"); other=s;other["date"]="2027-06-30";require(demo_achievements(*f.world,other).at("last_year")==2025,"June incorrectly treated the current season as completed"); other["date"]="2028-02-29";require(demo_achievements(*f.world,other).at("last_year")==2026,"Valid leap date was rejected"); other["date"]="2027-02-29";require(demo_achievements(*f.world,other).at("last_year")==2025,"Invalid date did not use the deterministic manifest reference"); require(s==original&&f.world->rows("clubs")==clubs&&demo_achievements(*f.world,s)==current&&demo_highscores(*f.world,s)==scores,"Read-only projections mutated source/catalogue or were nondeterministic"); } void test_short(int n) { Fixture f(n);auto s=state(n?id(n-1):"club:missing");const auto before=s; const auto a=demo_achievements(*f.world,s),h=demo_highscores(*f.world,s); require(a.at("available")==bool(n)&&h.at("available")==bool(n)&&h.at("rows").size()==size_t(n),"Short catalogue invented extra clubs"); if(!n)require(a.at("charts").empty()&&a.at("history").empty()&&a.at("club").is_null(),"Empty catalogue invented an own club or historical identity"); if(n){s["managers"][0]["name"]="";require(demo_highscores(*f.world,s).at("rows")[0].at("manager")=="—","Missing current manager received a fictional name");s=before;} for(const auto &bad:std::vector{nullptr,Json::array(),Json::object(),Json{{"managers",Json::array()}},state("club:missing"),state("nt:synthetic")}) { const auto aa=demo_achievements(*f.world,bad),hh=demo_highscores(*f.world,bad);require(aa.at("ok")==true&&aa.at("available")==false&&aa.at("history").empty()&&hh.at("rows").empty(),"Missing/invalid first-manager identity silently fell back to another club"); } require(s==before,"Short catalogue projection changed state"); } } // namespace int main()try{test_full();test_short(0);test_short(1);test_short(3);std::cout<<"Modern career report checks passed\n";return 0;}catch(const std::exception &e){std::cerr<