// SPDX-License-Identifier: GPL-3.0-only // Authored cup records exercise the existing Modern overview, without original data. #include "modern/content/ui_contract.hpp" #include "modern/content/projections.hpp" #include "modern/game/cup.hpp" #include "formats/executable_layout.hpp" #include "formats/textd.hpp" #include #include 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 yes,const char* why){if(!yes)throw std::runtime_error(why);} } int main() try { modern::ModernState g;g.manager_teams={0};g.manager_records.resize(0xb0c);g.display_start_year=2026; g.memory.add_block(layout::CupTable,modern::kCupEntries*modern::kCupEntrySize); g.memory.add_block(layout::ActiveSelectors,8); g.memory.add_block(layout::SyntheticCupParticipantsBegin,0x100); g.memory.add_block(layout::SyntheticCupResultsBegin,0x100); for(int i=0;isize()==2,"active cup index differs"); const auto first=read("cup-view:0:0",1);const auto &m=*at(at(first,"data"),"matches").array();check(m.size()==2,"full first round missing");check(*at(m[0],"status").string()=="played"&&*at(m[0],"result").array()->at(0).integer()==2,"score changed");check(std::holds_alternative(at(m[1],"result").value),"open fixture has invented score"); const auto future=read("cup-view:0:0",2);check(!std::get(at(at(future,"data"),"available").value)&&at(at(future,"data"),"matches").array()->empty(),"future draw invented"); const auto legs=read("cup-view:1:0",1);const auto &leg=at(at(legs,"data"),"matches").array()->at(0);check(*at(leg,"phase").integer()==1&&*at(leg,"secondLegPhase").integer()==2,"cup phases lost");check(*at(leg,"secondLeg").array()->at(0).integer()==2&&*at(leg,"secondLeg").array()->at(1).integer()==3,"second leg not oriented to displayed sides"); check(*at(read("cup-view:0:0",0),"messageType").string()=="error"&&*at(read("cup-view:0:0",3),"messageType").string()=="error","invalid cup rounds accepted"); check(*at(read("cup-view:99:0",1),"messageType").string()=="error","foreign cup accepted"); g.memory.add_block(layout::CalendarState_FormatError_RuntimeField3,2);g.memory.set16(layout::CalendarState_FormatError_RuntimeField3,10); descriptor(2,12,2,1,4);g.memory.set8(layout::ActiveSelectors+2,12); g.memory.set_pointer(modern::cup_entry_address(2),0);g.memory.set_pointer(modern::cup_entry_address(2)+0x0c,0); const auto metadata=modern::ui_read(g,c,O{{"kind","other-index"}});check(at(at(metadata,"data"),"views").array()->size()==3,"metadata index accessed uninitialised row arrays"); g.memory.set_pointer(modern::cup_entry_address(2),layout::SyntheticCupParticipantsBegin);g.memory.set_pointer(modern::cup_entry_address(2)+0x0c,layout::SyntheticCupResultsBegin+32);g.memory.set16(layout::SyntheticCupResultsBegin+32,5); const auto scheduled=read("cup-view:12:0",1);const auto &planned=at(at(scheduled,"data"),"matches").array()->at(0); check(*at(planned,"status").string()=="scheduled"&&std::holds_alternative(at(planned,"result").value)&&at(planned,"date").string(),"scheduled offset was decoded as score"); check(g.memory.u16(layout::SyntheticCupResultsBegin)==0x41&&g.memory.u8(layout::ActiveSelectors)==0,"pure read changed source bytes"); std::cout<<"cup index, null results, future draws, phases and reversed legs passed\n";return 0; } catch(const std::exception& e){std::cerr<