#include "runtime_fixture_tables.hpp" #include "test_inputs.hpp" #include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include "ui/cup_draw.hpp" #include #include #include #include #include #include "formats/fbm.hpp" #include "formats/m3d.hpp" #include "formats/palette.hpp" #include "formats/savestate.hpp" #include "game/cup.hpp" #include "game/save.hpp" #include "game/state.hpp" #include "ui/manager.hpp" namespace { using bmh::test_support::check; struct Native { bmh::GameState game; bmh::LeImage exe; bmh::TextDb texts; bmh::Bytes native_stream; Native(const std::filesystem::path& data,const std::filesystem::path& save) :exe(bmh::test::load_executable(bmh::ui::asset_path(data,"BMH.exe"))),texts(bmh::load_textd(bmh::ui::asset_path(data,"TEXTD.BLK"))) { const auto fbm=bmh::load_savegame(save);check(fbm.checksum_ok,"native fixture checksum"); native_stream=fbm.stream;game=bmh::GameState::from_save(bmh::SaveState(native_stream));game.texts=&texts; } bmh::SeasonCupDrawEvent event(bmh::SeasonCupDrawPhase phase) const { bmh::SeasonCupDrawEvent e;e.phase=phase;e.entry_address=bmh::kCupTable; e.competition=game.memory.u8(e.entry_address+0x18);e.round=bmh::cup_round(game.memory,0); e.offset=bmh::cup_round_offset(game.memory,0,e.round); e.count=size_t(game.memory.u8(e.entry_address+0x1a))>>e.round; const uint32_t list=game.memory.pointer(e.entry_address)+uint32_t(e.offset)*2; for(size_t i=0;i first_flicker,second_flicker,third_flicker; for(int guard=0;guard<4000&&animation.advance_step();++guard){ if(animation.input_poll_needed()){ // Exercise an empty Source queue at all initial and between-club polls. animation.source_input(0); } if(animation.held_mouse_check_needed())animation.source_held_mouse(0); if(animation.wait_milliseconds()>0){++waits;if(animation.present_needed())++presented_waits; if(waits==6)first_flicker=animation.render(); if(waits==7)second_flicker=animation.render(); if(waits==8)third_flicker=animation.render();} if(animation.queue_flush_needed())++flushes; } check(animation.reveal_complete()&&!animation.reveal_aborted(),"uninterrupted draw reaches fresh-ACK boundary"); check(animation.revealed_count()==64,"reveal counter preserves total after rolling window trims"); check(waits==64u*14u,"Source scripts execute fourteen waits for every club"); check(presented_waits==64u*14u,"all 14 Source wait markers present, including legacy routine(0) swaps"); check(first_flicker&&second_flicker&&third_flicker&& first_flicker->pixels!=second_flicker->pixels&&first_flicker->pixels==third_flicker->pixels, "Source token-101 waits alternate the owned visible buffer without copy-back"); check(flushes==65,"queue flushes only at initial and committed-name presentation boundaries"); check(draw_native.native_stream==original_stream&&draw_native.game.club_names==original_club_names, "native save bytes and restored source names are unchanged through render and step"); check(draw_hook_calls==0,"draw-only UI never invokes a Core callback"); bmh::ui::CupDrawScreen skipped(data,draw_projection); for(int i=0;i<10;++i){check(skipped.advance_step(),"initial speed-delay poll remains active"); if(skipped.input_poll_needed()&&i==0)skipped.source_input(8);} check(skipped.reveal_aborted()&&skipped.revealed_count()==0,"initial queued skip waits all ten iterations, then aborts reveal"); auto overview_native=Native(data,fixtures/"gameend/overview.FBM"); auto overview_event=overview_native.event(bmh::SeasonCupDrawPhase::overview); auto overview_projection=bmh::ui::cup_draw_from_game(overview_native.game,overview_event,overview_native.exe,overview_native.texts); bmh::ui::CupDrawScreen overview(data,overview_projection); const auto table=overview.render(); check(table.width==320&&table.height==240,"overview has native canvas"); const int baseline=((64-int(overview_projection.count))/2)*3+26; check(overview.hit_test_team(1,baseline-4)==overview_projection.clubs[0].runtime_id,"home hit interior"); check(!overview.hit_test_team(0,baseline-4)&&!overview.hit_test_team(102,baseline-4),"home hit strict x edges"); check(!overview.hit_test_team(103,baseline-4)&&overview.hit_test_team(104,baseline-4)==overview_projection.clubs[1].runtime_id,"away hit strict x edges"); check(!overview.hit_test_team(104,baseline-6)&&!overview.hit_test_team(104,baseline),"team hit strict y edges"); if(argc>=4) { Native group_native(data,argv[3]); int group_entry=-1; for(int i=0;i=4&&comp<=7&&(group_native.game.memory.u8(at+0x14)&4)==0&& (group_native.game.memory.u8(at+0x1a)==4||group_native.game.memory.u8(at+0x1a)==6)) {group_entry=i;break;} } check(group_entry>=0,"native season input contains a real initial international group entry"); const uint32_t at=bmh::cup_entry_address(group_entry),list=group_native.game.memory.pointer(at); bmh::SeasonCupDrawEvent group_event;group_event.entry_address=at;group_event.competition=group_native.game.memory.u8(at+0x18); group_event.flags=group_native.game.memory.u8(at+0x14);group_event.group_stage=true; group_event.group_index=0;group_event.group_count=group_native.game.memory.u8(at+0x1e)&0xf; group_event.round=bmh::cup_round(group_native.game.memory,group_entry);group_event.offset=0; group_event.count=group_native.game.memory.u8(at+0x1a); for(size_t i=0;i25&&group_projection.group_caption[25]==char(group_event.group_index==0?'1':'0'+group_event.group_index),"Source group caption digit is copied into an owned string"); check(group_native.texts.strings==source_texts,"group projection never mutates shared TEXTD globals"); for(const auto& pair:group_projection.group_fixtures) check(std::find(group_event.participants.begin(),group_event.participants.end(),pair[0])!=group_event.participants.end()&& std::find(group_event.participants.begin(),group_event.participants.end(),pair[1])!=group_event.participants.end(), "round schedule positions resolve through the native group team list"); bmh::ui::CupDrawScreen group_overview(data,group_projection); const auto group_image=group_overview.render(); check(group_image.width==320&&group_image.height==240,"source group overview renders to native canvas"); check(group_overview.hit_test_team(6,34)==group_projection.group_fixtures.front()[0],"group fixture strict interior maps to runtime club ID"); check(!group_overview.hit_test_team(0,34)&&!group_overview.hit_test_team(319,34),"group fixture outer x bounds are excluded"); check(group_overview.hit_test_team(127,34)==group_projection.group_fixtures.front()[1],"home right boundary remains inside the overlapping away hitbox"); check(group_overview.hit_test_team(125,34)==group_projection.group_fixtures.front()[0]&& group_overview.hit_test_team(126,34)==group_projection.group_fixtures.front()[0],"home wins the Source overlap before the away hitbox"); check(!group_overview.hit_test_team(6,33)&&!group_overview.hit_test_team(6,39),"group fixture hitbox uses strict Source y bounds"); check(!group_overview.hit_test_team(30,132),"bottom standings are not Source fixture hit targets"); check(bmh::save_stream(group_native.game)==group_stream,"group reveal and overview do not change native game state"); } std::cout<<"Cup draw Source projection, framebuffer timeline, rolling reveal count, and overview hitboxes passed\n"; bmh::draw_hook=previous_draw_hook; return 0; }catch(const std::exception&e){std::cerr<<"cup_draw_tests: "<