From 9870d90d6507db66174b521e5c238694c2ac0d19 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 11 Nov 2026 14:52:42 +0100 Subject: [PATCH] Tests share one check helper; stale references in comments corrected 116 test files had their own identical copy of check(bool, const char*); they use bmh::test_support::check from src/testing/check.hpp. Seven comments pointed to documents that no longer exist or named a former author. Co-Authored-By: Claude --- src/cli/console/windows_info.cpp | 2 +- src/cli/console/windows_squad.cpp | 2 +- src/cli/console/windows_state.cpp | 2 +- src/game/cup.cpp | 2 +- src/launch/fltd.hpp | 2 +- src/testing/check.hpp | 13 +++++++++++++ src/ui/achievements_tests.cpp | 3 ++- src/ui/advertising_tests.cpp | 5 ++--- src/ui/alltime_table_tests.cpp | 3 ++- src/ui/analytics_tests.cpp | 3 ++- src/ui/contracts_tests.cpp | 5 ++--- src/ui/desktop_tests.cpp | 3 ++- src/ui/environment_tests.cpp | 5 ++--- src/ui/finance_totals_tests.cpp | 3 ++- src/ui/friendly_match_tests.cpp | 5 ++--- src/ui/league_table_tests.cpp | 5 ++--- src/ui/lineup_tests.cpp | 3 ++- src/ui/mailbox_screen_tests.cpp | 3 ++- src/ui/mailbox_state_tests.cpp | 5 ++--- src/ui/manager_tests.cpp | 5 ++--- src/ui/matchday_results_tests.cpp | 3 ++- src/ui/opportunities_tests.cpp | 3 ++- src/ui/pitch_tests.cpp | 3 ++- src/ui/player_card_tests.cpp | 3 ++- src/ui/preparation_tests.cpp | 3 ++- src/ui/save_load_tests.cpp | 5 ++--- src/ui/season_entrants_tests.cpp | 5 ++--- src/ui/settings_tests.cpp | 5 ++--- src/ui/sprite_font_tests.cpp | 5 ++--- src/ui/statistics_rankings_tests.cpp | 5 ++--- src/ui/tactics_tests.cpp | 3 ++- src/ui/top_scorers_tests.cpp | 5 ++--- src/ui/training_camp_tests.cpp | 3 ++- src/ui/training_tests.cpp | 3 ++- tests/app_controller_tests.cpp | 3 ++- tests/autosave_tests.cpp | 3 ++- tests/balance_plan_app_tests.cpp | 3 ++- tests/bank_lender_app_tests.cpp | 3 ++- tests/bank_lender_ui_tests.cpp | 5 ++--- tests/bank_robbery_month_tests.cpp | 3 ++- tests/calendar_epoch_tests.cpp | 3 ++- tests/classic_rules_unit_tests.cpp | 3 ++- tests/club_info_category_tests.cpp | 3 ++- tests/club_info_tests.cpp | 3 ++- tests/club_info_ui_tests.cpp | 3 ++- tests/club_player_detail_tests.cpp | 3 ++- tests/club_player_detail_ui_tests.cpp | 3 ++- tests/competition_winner_tests.cpp | 3 ++- tests/cup_cursor_tests.cpp | 3 ++- tests/cup_draw_ui_tests.cpp | 3 ++- tests/cup_followup_tests.cpp | 3 ++- tests/cup_seeded_followup_tests.cpp | 3 ++- tests/daily_interest_unit_tests.cpp | 3 ++- tests/desktop_feedback_tests.cpp | 3 ++- tests/environment_tests.cpp | 3 ++- tests/fixture_table_tests.cpp | 3 ++- tests/format_tests.cpp | 4 ++-- tests/game_end_alternate_tests.cpp | 3 ++- tests/game_end_cli_tests.cpp | 3 ++- tests/game_end_tax_animation_tests.cpp | 3 ++- tests/human_buyer_market_app_tests.cpp | 3 ++- tests/human_buyer_pending_app_tests.cpp | 3 ++- tests/human_buyer_pending_offer_tests.cpp | 3 ++- tests/league_pairings_tests.cpp | 3 ++- tests/league_table_controls_app_tests.cpp | 3 ++- tests/league_table_controls_flow_tests.cpp | 5 ++--- tests/lineup_assistant_detail_tests.cpp | 5 ++--- tests/lineup_foreign_limit_tests.cpp | 3 ++- tests/loaded_manager_loop_tests.cpp | 5 ++--- tests/long_career_tests.cpp | 3 ++- tests/manager_desks_tests.cpp | 3 ++- tests/manager_join_app_tests.cpp | 3 ++- tests/matchday_intro_tests.cpp | 3 ++- tests/national_nomination_tests.cpp | 3 ++- tests/national_pending_match_tests.cpp | 3 ++- tests/native_save_version_tests.cpp | 3 ++- tests/other_games_app_tests.cpp | 5 ++--- tests/other_games_ui_tests.cpp | 5 ++--- tests/pending_offer_app_tests.cpp | 3 ++- tests/pending_offer_desk_tests.cpp | 3 ++- tests/pending_offer_tests.cpp | 3 ++- tests/pending_offer_ui_tests.cpp | 5 ++--- tests/phase_results_career_tests.cpp | 5 ++--- tests/process_timer_tests.cpp | 3 ++- tests/quit_confirmation_unit_tests.cpp | 3 ++- tests/reality_ball_tests.cpp | 3 ++- tests/reality_career_special_tests.cpp | 5 ++--- tests/reality_deferred_tests.cpp | 3 ++- tests/reality_duel_tests.cpp | 3 ++- tests/reality_forced_event_tests.cpp | 3 ++- tests/reality_matchday_tests.cpp | 3 ++- tests/reality_motion_tests.cpp | 3 ++- tests/reality_movement_tests.cpp | 3 ++- tests/reality_reporter_layout_tests.cpp | 3 ++- tests/reality_reporter_tests.cpp | 3 ++- tests/reality_scene_tests.cpp | 3 ++- tests/reality_setup_tests.cpp | 3 ++- tests/reality_space_tests.cpp | 3 ++- tests/season_cup_draw_tests.cpp | 3 ++- tests/season_end_desk_tests.cpp | 3 ++- tests/season_player_reset_tests.cpp | 3 ++- tests/season_promotion_tests.cpp | 3 ++- tests/season_tax_tests.cpp | 3 ++- tests/shared_desktop_actions_tests.cpp | 5 ++--- tests/sound_settings_app_tests.cpp | 3 ++- tests/sportschau_eleven_tests.cpp | 3 ++- tests/sportschau_rating_tests.cpp | 3 ++- tests/sportschau_scene_tests.cpp | 3 ++- tests/sportschau_teaminfo_tests.cpp | 3 ++- tests/sportschau_ui_tests.cpp | 5 ++--- tests/stadium_block_app_tests.cpp | 5 ++--- tests/stadium_block_ui_tests.cpp | 5 ++--- tests/stadium_extended_limits_tests.cpp | 3 ++- tests/start_screen_tests.cpp | 3 ++- tests/statistics_case2_app_tests.cpp | 3 ++- tests/team_statistics_tests.cpp | 3 ++- tests/top_scorers_app_tests.cpp | 5 ++--- tests/training_camp_app_tests.cpp | 3 ++- tests/training_dispatch_app_tests.cpp | 3 ++- tests/transfer_offer_player_info_tests.cpp | 3 ++- tests/transfer_offer_team_info_tests.cpp | 3 ++- tests/weekly_human_buyer_loan_tests.cpp | 3 ++- tests/world_layout_tests.cpp | 5 ++--- 123 files changed, 252 insertions(+), 179 deletions(-) create mode 100644 src/testing/check.hpp diff --git a/src/cli/console/windows_info.cpp b/src/cli/console/windows_info.cpp index dccce06..dff7a04 100644 --- a/src/cli/console/windows_info.cpp +++ b/src/cli/console/windows_info.cpp @@ -36,7 +36,7 @@ constexpr int kHighscorePrefix = 889; // the high score file prefix ("high/h.") void Console::register_info_commands() { // --- TopScorers (05-information 7, menu 20) ------------------------------------------- - // Codex's read-only port of TopScorersFromGame (game/top_scorers.hpp): the best ten of the own + // The read-only port of TopScorersFromGame (game/top_scorers.hpp): the best ten of the own // league by goals, assists or both (one point each), for the whole league or only the // managers' clubs. No state changes and no random draws, so the console reads it directly. struct ScorerView { diff --git a/src/cli/console/windows_squad.cpp b/src/cli/console/windows_squad.cpp index 152547f..0eabab3 100644 --- a/src/cli/console/windows_squad.cpp +++ b/src/cli/console/windows_squad.cpp @@ -166,7 +166,7 @@ void Console::register_squad_commands() { }); // Moving a player, the formations and the automatic weights: the requests the SDL pitch // screen builds (src/ui/pitch.cpp click / save_formation), dispatched through - // CareerSession::dispatch_pitch (PitchScreen pitch branch, Codex's source port). + // CareerSession::dispatch_pitch (PitchScreen pitch branch, the source port). auto pitch_context = [this] { const auto p = prep(); if (!p.pitch || !p.pitch->indoor.has_value()) fail("E_ENGINE_GAP", "no pitch mode projection"); diff --git a/src/cli/console/windows_state.cpp b/src/cli/console/windows_state.cpp index 298a4ac..0965d29 100644 --- a/src/cli/console/windows_state.cpp +++ b/src/cli/console/windows_state.cpp @@ -90,7 +90,7 @@ Json mailbox_record(const ui::MailboxState& m) { } // namespace -// --- Advice and Scoreboard (for agents that learn: docs/CLI_CONCEPT/16-playbook.md) ------- +// --- Advice and Scoreboard (for agents that learn: docs/CLI_CONCEPT/10-agenten-und-tests.md) ------- // Advice names what needs a decision now, from the engine's own data; it judges nothing // the player could not see on his screens, it only collects it. Scoreboard compares the // human managers. Both read only. diff --git a/src/game/cup.cpp b/src/game/cup.cpp index 8d16b6c..55973ca 100644 --- a/src/game/cup.cpp +++ b/src/game/cup.cpp @@ -642,7 +642,7 @@ void advance_cup(GameState& g, int id, WatcomRandom& rand, MinuteReport& report, if (mem.u8(e + 0x17) != 0 && winners.size() > 1) mem.set16(cup_entry_address(mem.u8(e + 0x17)) + 0x22, winners[1]); // (the indoor tournament only: the English League Cup has no Masters; its winner - // would go to EN CupRuntimeField6 for Europe - not ported, see docs/fltd.md) + // would go to EN CupRuntimeField6 for Europe - not ported) if (type != 0xb || league_system().english_competitions) return; // the indoor tournament: the four places (CupRuntimeField7 picks them from the list // champion..fourth) earn points for the Masters (CupRuntimeField8 x strength class diff --git a/src/launch/fltd.hpp b/src/launch/fltd.hpp index c67e5f3..889921c 100644 --- a/src/launch/fltd.hpp +++ b/src/launch/fltd.hpp @@ -6,7 +6,7 @@ // M3D.MAN. prepare_english_game() turns an English installation into such a data directory, // once, in the launcher cache: // - TEXTE.BLK -> TEXTD.BLK and M3E.MAN -> M3D.MAN (same formats, the text slots are the -// same variables; docs/formats/TEXTD_INVENTORY.md), +// same variables; docs/formats/TEXTD.md), // - FLTD.EXE -> "BMH.exe" in the OpenBMH image format (formats/le.hpp): an image in the // German address space. Every German data object the engine reads is filled from its // English counterpart (src/launch/fltd_map.inc, generated by runtime verification), German diff --git a/src/testing/check.hpp b/src/testing/check.hpp new file mode 100644 index 0000000..9dafbb3 --- /dev/null +++ b/src/testing/check.hpp @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-3.0-only +#pragma once +// The check of the test programs: a failed expectation ends the test with its message (the main +// function of a test prints the message and returns 1). Until 1.0.12 every test file had its own copy. +#include + +namespace bmh::test_support { + +inline void check(bool ok, const char* message) { + if (!ok) throw std::runtime_error(message); +} + +} // namespace bmh::test_support diff --git a/src/ui/achievements_tests.cpp b/src/ui/achievements_tests.cpp index 3523a8d..932dacc 100644 --- a/src/ui/achievements_tests.cpp +++ b/src/ui/achievements_tests.cpp @@ -1,5 +1,6 @@ // Tests for the achievements projection and screen (ui/achievements.hpp). #include "../../tests/test_inputs.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include "ui/achievements.hpp" @@ -12,7 +13,7 @@ #include "game/messages.hpp" namespace { -void check(bool ok, const char* why) { if (!ok) throw std::runtime_error(why); } +using bmh::test_support::check; } int main(int argc, char** argv) { diff --git a/src/ui/advertising_tests.cpp b/src/ui/advertising_tests.cpp index 07fbc72..9c05925 100644 --- a/src/ui/advertising_tests.cpp +++ b/src/ui/advertising_tests.cpp @@ -19,14 +19,13 @@ #include "game/state.hpp" #include "ui/manager.hpp" #include "ui/setup.hpp" +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; namespace { -void check(bool ok, const char* message) { - if (!ok) throw std::runtime_error(message); -} +using bmh::test_support::check; void rejected(const std::function& action) { try { action(); } catch (const FormatError&) { return; } throw std::runtime_error("expected invalid advertising projection rejection"); diff --git a/src/ui/alltime_table_tests.cpp b/src/ui/alltime_table_tests.cpp index 6fbccd4..dd49126 100644 --- a/src/ui/alltime_table_tests.cpp +++ b/src/ui/alltime_table_tests.cpp @@ -7,8 +7,9 @@ #include "ui/manager.hpp" #include #include +#include "testing/check.hpp" namespace { -void check(bool ok,const char* why){if(!ok)throw std::runtime_error(why);} +using bmh::test_support::check; void put16(bmh::Bytes& b,uint32_t base,uint32_t a,uint16_t x){b.at(a-base)=uint8_t(x);b.at(a-base+1)=uint8_t(x>>8);} void rec(bmh::GameState&g,int team,uint16_t points,uint16_t gf,uint16_t ga,uint16_t w,uint16_t d,uint16_t l){size_t p=size_t(team)*0x4a+0x1e;for(auto [o,v]:{std::pair{0,points},std::pair{2,gf},std::pair{4,ga},std::pair{6,w},std::pair{8,d},std::pair{10,l}}){g.club_table[p+o]=uint8_t(v);g.club_table[p+o+1]=uint8_t(v>>8);}} } diff --git a/src/ui/analytics_tests.cpp b/src/ui/analytics_tests.cpp index e3d88bd..efebbdb 100644 --- a/src/ui/analytics_tests.cpp +++ b/src/ui/analytics_tests.cpp @@ -1,5 +1,6 @@ // Tests for the analytics projection, toggles and acknowledgement (ui/analytics.hpp). #include "../../tests/test_inputs.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include "ui/analytics.hpp" @@ -8,7 +9,7 @@ #include namespace { -void check(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); } +using bmh::test_support::check; void put32(std::vector& b, size_t at, uint32_t v) { for (int i = 0; i < 4; ++i) b.at(at + size_t(i)) = uint8_t(v >> (i * 8)); } diff --git a/src/ui/contracts_tests.cpp b/src/ui/contracts_tests.cpp index d0a89e8..b8cf335 100644 --- a/src/ui/contracts_tests.cpp +++ b/src/ui/contracts_tests.cpp @@ -7,13 +7,12 @@ #include "formats/textd.hpp" #include +#include "testing/check.hpp" using namespace bmh::ui; namespace { -void check(bool value, const char* message) { - if (!value) throw std::runtime_error(message); -} +using bmh::test_support::check; } int main(int argc, char** argv) { diff --git a/src/ui/desktop_tests.cpp b/src/ui/desktop_tests.cpp index a0da6f2..e0b1f38 100644 --- a/src/ui/desktop_tests.cpp +++ b/src/ui/desktop_tests.cpp @@ -1,5 +1,6 @@ // Tests for the desk state projection, DesktopScreen input and request flow (ui/desktop.hpp, ui/desk_state.hpp). #include "../../tests/runtime_fixture_tables.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include "../../tests/test_inputs.hpp" @@ -31,7 +32,7 @@ using namespace bmh; using namespace bmh::ui; namespace { -void check(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); } +using bmh::test_support::check; void rejected(const std::function& action) { static int index = 0; ++index; try { action(); } catch (const FormatError&) { return; } diff --git a/src/ui/environment_tests.cpp b/src/ui/environment_tests.cpp index 433f4ff..970270b 100644 --- a/src/ui/environment_tests.cpp +++ b/src/ui/environment_tests.cpp @@ -1,5 +1,6 @@ // Tests for the environment view, rendering and requests (ui/environment.hpp). #include "../../tests/runtime_fixture_tables.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include "ui/environment.hpp" @@ -21,9 +22,7 @@ using namespace bmh; using namespace bmh::ui; namespace { -void check(bool ok, const char* message) { - if (!ok) throw std::runtime_error(message); -} +using bmh::test_support::check; uint8_t pixel(const Image& image, int x, int y) { return image.pixels.at(size_t(y) * size_t(image.width) + size_t(x)); } diff --git a/src/ui/finance_totals_tests.cpp b/src/ui/finance_totals_tests.cpp index 491d131..d935dca 100644 --- a/src/ui/finance_totals_tests.cpp +++ b/src/ui/finance_totals_tests.cpp @@ -1,5 +1,6 @@ // Tests for the finance totals projection (ui/finance_totals.hpp). #include "../../tests/runtime_fixture_tables.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include "finance_totals.hpp" @@ -15,7 +16,7 @@ #include "ui/setup.hpp" namespace { -void check(bool b,const char* what){if(!b)throw std::runtime_error(what);} +using bmh::test_support::check; uint32_t u32(const std::vector& b,size_t at){return uint32_t(b.at(at))|uint32_t(b.at(at+1))<<8|uint32_t(b.at(at+2))<<16|uint32_t(b.at(at+3))<<24;} uint16_t u16(const std::vector& b,size_t at){return uint16_t(b.at(at))|uint16_t(b.at(at+1))<<8;} int32_t si32(const std::vector& b,size_t at){return int32_t(u32(b,at));} diff --git a/src/ui/friendly_match_tests.cpp b/src/ui/friendly_match_tests.cpp index d9f3732..17623e0 100644 --- a/src/ui/friendly_match_tests.cpp +++ b/src/ui/friendly_match_tests.cpp @@ -12,13 +12,12 @@ #include "game/schedule.hpp" #include "game/state.hpp" #include "game/messages.hpp" +#include "testing/check.hpp" using namespace bmh::ui; namespace { -void check(bool ok, const char* message) { - if (!ok) throw std::runtime_error(message); -} +using bmh::test_support::check; FriendlyMatchState fixture(const std::filesystem::path& data) { FriendlyMatchState state; diff --git a/src/ui/league_table_tests.cpp b/src/ui/league_table_tests.cpp index b66cc0f..d004e1d 100644 --- a/src/ui/league_table_tests.cpp +++ b/src/ui/league_table_tests.cpp @@ -17,6 +17,7 @@ #include "ui/desktop.hpp" #include "ui/manager.hpp" #include "ui/setup.hpp" +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; @@ -24,9 +25,7 @@ using namespace bmh::ui; namespace { int counted_draws = 0; void count_draw(int) { ++counted_draws; } -void check(bool ok, const char* message) { - if (!ok) throw std::runtime_error(message); -} +using bmh::test_support::check; void rejected(const std::function& action) { try { action(); } catch (const FormatError&) { return; } throw std::runtime_error("expected rejected league table input"); diff --git a/src/ui/lineup_tests.cpp b/src/ui/lineup_tests.cpp index 2520bff..0b30e97 100644 --- a/src/ui/lineup_tests.cpp +++ b/src/ui/lineup_tests.cpp @@ -16,12 +16,13 @@ #include "game/lineup.hpp" #include "game/save.hpp" #include "game/state.hpp" +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; namespace { -void check(bool ok, const char* message) { if(!ok)throw std::runtime_error(message); } +using bmh::test_support::check; void rejected(const std::function& action) { try { action(); } catch(const FormatError&) { return; } throw std::runtime_error("expected rejected lineup operation"); diff --git a/src/ui/mailbox_screen_tests.cpp b/src/ui/mailbox_screen_tests.cpp index b5a641d..8e2eb55 100644 --- a/src/ui/mailbox_screen_tests.cpp +++ b/src/ui/mailbox_screen_tests.cpp @@ -10,12 +10,13 @@ #include "game/messages.hpp" #include "game/state.hpp" #include "ui/setup.hpp" +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; namespace { -void check(bool value, const char* reason) { if (!value) throw std::runtime_error(reason); } +using bmh::test_support::check; void rejected(const std::function& action) { try { action(); } catch (const FormatError&) { return; } throw std::runtime_error("invalid mailbox screen state was accepted"); diff --git a/src/ui/mailbox_state_tests.cpp b/src/ui/mailbox_state_tests.cpp index a9fa899..2db2827 100644 --- a/src/ui/mailbox_state_tests.cpp +++ b/src/ui/mailbox_state_tests.cpp @@ -10,14 +10,13 @@ #include "game/messages.hpp" #include "game/state.hpp" #include "ui/manager.hpp" +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; namespace { -void check(bool ok, const char* message) { - if (!ok) throw std::runtime_error(message); -} +using bmh::test_support::check; void rejected(const std::function& action) { try { action(); } catch (const FormatError&) { return; } throw std::runtime_error("expected rejected mailbox input"); diff --git a/src/ui/manager_tests.cpp b/src/ui/manager_tests.cpp index dad135f..1ae5a05 100644 --- a/src/ui/manager_tests.cpp +++ b/src/ui/manager_tests.cpp @@ -5,11 +5,10 @@ #include #include "ui/flow.hpp" +#include "testing/check.hpp" using namespace bmh::ui; -static void check(bool condition, const char* message) { - if (!condition) throw std::runtime_error(message); -} +using bmh::test_support::check; int main(int argc, char** argv) { try { diff --git a/src/ui/matchday_results_tests.cpp b/src/ui/matchday_results_tests.cpp index 9e91a3a..e855030 100644 --- a/src/ui/matchday_results_tests.cpp +++ b/src/ui/matchday_results_tests.cpp @@ -18,12 +18,13 @@ #include "game/schedule.hpp" #include "game/match_engine.hpp" #include "game/turn_driver.hpp" +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; namespace { -void check(bool ok, const char* why) { if (!ok) throw std::runtime_error(why); } +using bmh::test_support::check; void rejected(const std::function& action) { try { action(); } catch (const FormatError&) { return; } throw std::runtime_error("expected rejected results input"); diff --git a/src/ui/opportunities_tests.cpp b/src/ui/opportunities_tests.cpp index 6bac134..cdd311a 100644 --- a/src/ui/opportunities_tests.cpp +++ b/src/ui/opportunities_tests.cpp @@ -1,4 +1,5 @@ #include "../../tests/test_inputs.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only // Tests for OpportunitiesScreen and StatisticsMenuScreen: mode buttons, rank strip clipping, owner refresh and request guards. #include "formats/executable_layout.hpp" @@ -14,7 +15,7 @@ using namespace bmh; using namespace bmh::ui; namespace { -void check(bool ok,const char* what){if(!ok)throw std::runtime_error(what);} +using bmh::test_support::check; OpportunitiesState fixture(){ OpportunitiesState s;s.identity={0,45,17,196,8,12,0};s.mode=1;s.league_size=18; s.current_rank=3;s.ranks.fill(1);s.ranks[0]=0;s.ranks[2]=0xff;s.underlay=Image(320,240);return s; diff --git a/src/ui/pitch_tests.cpp b/src/ui/pitch_tests.cpp index 2cbc040..4849149 100644 --- a/src/ui/pitch_tests.cpp +++ b/src/ui/pitch_tests.cpp @@ -10,11 +10,12 @@ #include "formats/fbm.hpp" #include "formats/savestate.hpp" #include "game/state.hpp" +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; namespace { -void check(bool ok,const char* message){if(!ok)throw std::runtime_error(message);} +using bmh::test_support::check; void rejected(const std::function& fn){try{fn();}catch(const FormatError&){return;}throw std::runtime_error("expected pitch rejection");} LineupState lineup(){LineupState s;s.manager_slot=0;s.runtime_club=12;s.revision=7;s.source="engine_projection"; s.club_name="UNITFC";s.entry_prepared=true;s.view=LineupView::data_b; diff --git a/src/ui/player_card_tests.cpp b/src/ui/player_card_tests.cpp index c10592a..c505778 100644 --- a/src/ui/player_card_tests.cpp +++ b/src/ui/player_card_tests.cpp @@ -10,11 +10,12 @@ #include "formats/fbm.hpp" #include "formats/savestate.hpp" #include "game/state.hpp" +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; namespace { -void check(bool value,const char* message){if(!value)throw std::runtime_error(message);} +using bmh::test_support::check; void rejected(const std::function& action){try{action();}catch(const FormatError&){return;}throw std::runtime_error("expected rejected player card");} GameState fixture(const LeImage& exe) { GameState g;g.memory.add_block(::bmh::layout::ActiveManager,1);g.memory.add_block(::bmh::layout::CareerSession_AnyOf_ExecutableField,8);g.memory.add_block(::bmh::layout::LeaguePresentationOptions,0xb4); diff --git a/src/ui/preparation_tests.cpp b/src/ui/preparation_tests.cpp index 832e887..ebbfe9c 100644 --- a/src/ui/preparation_tests.cpp +++ b/src/ui/preparation_tests.cpp @@ -8,11 +8,12 @@ #include #include #include +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; namespace { -void check(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); } +using bmh::test_support::check; void rejected(const std::function& action) { try { action(); } catch (const FormatError&) { return; } throw std::runtime_error("expected rejected operation"); diff --git a/src/ui/save_load_tests.cpp b/src/ui/save_load_tests.cpp index ee992bd..e959c7d 100644 --- a/src/ui/save_load_tests.cpp +++ b/src/ui/save_load_tests.cpp @@ -8,14 +8,13 @@ #include #include #include +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; namespace { -void check(bool value, const char* message) { - if (!value) throw std::runtime_error(message); -} +using bmh::test_support::check; } int main(int argc, char** argv) { diff --git a/src/ui/season_entrants_tests.cpp b/src/ui/season_entrants_tests.cpp index da6137d..85bcb90 100644 --- a/src/ui/season_entrants_tests.cpp +++ b/src/ui/season_entrants_tests.cpp @@ -1,4 +1,5 @@ #include "../../tests/test_inputs.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only // Tests for season_entrants_from_game(): footer order, untouched competition pools, and suppression in non-league mode. #include "formats/executable_layout.hpp" @@ -12,9 +13,7 @@ #include "ui/manager.hpp" namespace { -void check(bool ok, const char* message) { - if (!ok) throw std::runtime_error(message); -} +using bmh::test_support::check; bmh::GameState fixture() { bmh::GameState g; diff --git a/src/ui/settings_tests.cpp b/src/ui/settings_tests.cpp index 0159e28..40d3439 100644 --- a/src/ui/settings_tests.cpp +++ b/src/ui/settings_tests.cpp @@ -1,4 +1,5 @@ #include "../../tests/runtime_fixture_tables.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only // Tests for the settings screen: availability rules, edit requests, sound capabilities and the readme viewer paging. #include "formats/executable_layout.hpp" @@ -20,9 +21,7 @@ using namespace bmh; using namespace bmh::ui; namespace { -void check(bool condition, const char* why) { - if (!condition) throw std::runtime_error(why); -} +using bmh::test_support::check; } int main(int argc, char** argv) try { diff --git a/src/ui/sprite_font_tests.cpp b/src/ui/sprite_font_tests.cpp index 399c705..18fbf4d 100644 --- a/src/ui/sprite_font_tests.cpp +++ b/src/ui/sprite_font_tests.cpp @@ -9,14 +9,13 @@ #include #include "ui/setup.hpp" +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; namespace { -void check(bool condition, const char* message) { - if (!condition) throw std::runtime_error(message); -} +using bmh::test_support::check; } int main(int argc, char** argv) { diff --git a/src/ui/statistics_rankings_tests.cpp b/src/ui/statistics_rankings_tests.cpp index c89e285..c06f41f 100644 --- a/src/ui/statistics_rankings_tests.cpp +++ b/src/ui/statistics_rankings_tests.cpp @@ -1,4 +1,5 @@ #include "../../tests/test_inputs.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only // Tests for StatisticsRankingsScreen: category selection requests, pressed-state cancel on move-off, and reachability of the oldest archived rows. #include "formats/executable_layout.hpp" @@ -13,9 +14,7 @@ using namespace bmh; using namespace bmh::ui; namespace { -void check(bool condition, const char* message) { - if (!condition) throw std::runtime_error(message); -} +using bmh::test_support::check; GameState sample() { GameState game; diff --git a/src/ui/tactics_tests.cpp b/src/ui/tactics_tests.cpp index af878b4..7509e78 100644 --- a/src/ui/tactics_tests.cpp +++ b/src/ui/tactics_tests.cpp @@ -10,11 +10,12 @@ #include "formats/fbm.hpp" #include "formats/savestate.hpp" #include "game/state.hpp" +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; namespace { -void check(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); } +using bmh::test_support::check; void rejected(const std::function& f) { try { f(); } catch (const FormatError&) { return; } throw std::runtime_error("expected FormatError"); diff --git a/src/ui/top_scorers_tests.cpp b/src/ui/top_scorers_tests.cpp index fa05db9..e8175d1 100644 --- a/src/ui/top_scorers_tests.cpp +++ b/src/ui/top_scorers_tests.cpp @@ -5,14 +5,13 @@ #include #include #include +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; namespace { -void check(bool ok, const char* message) { - if (!ok) throw std::runtime_error(message); -} +using bmh::test_support::check; TopScorersState state_for(TopScorersMetric metric, TopScorersScope scope) { TopScorersState state; diff --git a/src/ui/training_camp_tests.cpp b/src/ui/training_camp_tests.cpp index 83f73a6..7d3553f 100644 --- a/src/ui/training_camp_tests.cpp +++ b/src/ui/training_camp_tests.cpp @@ -10,12 +10,13 @@ #include #include +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; namespace { -void check(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); } +using bmh::test_support::check; void rejected(const std::function& fn) { try { fn(); } catch (const FormatError&) { return; } throw std::runtime_error("expected rejected operation"); diff --git a/src/ui/training_tests.cpp b/src/ui/training_tests.cpp index 114e81e..d5409d2 100644 --- a/src/ui/training_tests.cpp +++ b/src/ui/training_tests.cpp @@ -10,12 +10,13 @@ #include "formats/fbm.hpp" #include "formats/savestate.hpp" #include "game/state.hpp" +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; namespace { -void check(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); } +using bmh::test_support::check; void rejected(const std::function& fn) { try { fn(); } catch (const FormatError&) { return; } throw std::runtime_error("expected rejected operation"); diff --git a/tests/app_controller_tests.cpp b/tests/app_controller_tests.cpp index bad3354..b74cace 100644 --- a/tests/app_controller_tests.cpp +++ b/tests/app_controller_tests.cpp @@ -1,4 +1,5 @@ #include "test_inputs.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include "formats/league_visibility.hpp" @@ -47,7 +48,7 @@ using namespace bmh; using namespace bmh::ui; namespace { -void check(bool value, const char* message) { if (!value) throw std::runtime_error(message); } +using bmh::test_support::check; uint8_t session_runtime_byte(const GameState& state,const std::map& runtime,uint32_t address) { if(state.memory.has(address))return state.memory.u8(address); diff --git a/tests/autosave_tests.cpp b/tests/autosave_tests.cpp index 5bf7e4e..31136af 100644 --- a/tests/autosave_tests.cpp +++ b/tests/autosave_tests.cpp @@ -1,4 +1,5 @@ #include "runtime_fixture_tables.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include "app/career_session.hpp" @@ -13,7 +14,7 @@ #include using namespace bmh; -void check(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); } +using bmh::test_support::check; void period_one(app::CareerSession& session, const std::filesystem::path& data, uint64_t& revision) { const auto exe = bmh::test::load_executable(data / "BMH.exe"); diff --git a/tests/balance_plan_app_tests.cpp b/tests/balance_plan_app_tests.cpp index 3bdd446..55f3ed0 100644 --- a/tests/balance_plan_app_tests.cpp +++ b/tests/balance_plan_app_tests.cpp @@ -11,10 +11,11 @@ #include "game/balance_plan.hpp" #include "game/save.hpp" #include "ui/balance_plan.hpp" +#include "testing/check.hpp" using namespace bmh; namespace fs=std::filesystem; -static void check(bool value,const char* why){if(!value)throw std::runtime_error(why);} +using bmh::test_support::check; static void immediate_close(const fs::path& data,const fs::path& save){ app::CareerSession session(data,911,save);uint64_t revision=23;std::string error; const int manager=session.state().memory.u8(::bmh::layout::ActiveManager);auto& records=session.state().manager_records; diff --git a/tests/bank_lender_app_tests.cpp b/tests/bank_lender_app_tests.cpp index 5f4ace4..547e98b 100644 --- a/tests/bank_lender_app_tests.cpp +++ b/tests/bank_lender_app_tests.cpp @@ -9,10 +9,11 @@ #include "app/controller.hpp" #include "game/bank_credit.hpp" #include "game/save.hpp" +#include "testing/check.hpp" using namespace bmh; namespace { -void check(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); } +using bmh::test_support::check; struct TemporarySaves { std::filesystem::path path = std::filesystem::temp_directory_path() / diff --git a/tests/bank_lender_ui_tests.cpp b/tests/bank_lender_ui_tests.cpp index 7b89083..dfd92fc 100644 --- a/tests/bank_lender_ui_tests.cpp +++ b/tests/bank_lender_ui_tests.cpp @@ -13,14 +13,13 @@ #include #include #include +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; namespace { -void check(bool ok, const char* message) { - if (!ok) throw std::runtime_error(message); -} +using bmh::test_support::check; std::unique_ptr career(const std::filesystem::path& data, int manager_count) { auto session = std::make_unique(data, uint32_t(0x31415926 + manager_count)); diff --git a/tests/bank_robbery_month_tests.cpp b/tests/bank_robbery_month_tests.cpp index 9348dba..4b95642 100644 --- a/tests/bank_robbery_month_tests.cpp +++ b/tests/bank_robbery_month_tests.cpp @@ -7,10 +7,11 @@ #include #include #include +#include "testing/check.hpp" using namespace bmh; namespace { -void check(bool ok,const char* why){if(!ok)throw std::runtime_error(why);} +using bmh::test_support::check; void cash(GameState& state,int manager,int32_t value) { const size_t at=size_t(manager)*0xb0c+0x314; for(size_t n=0;n<4;++n)state.manager_records.at(at+n)=uint8_t(uint32_t(value)>>(8*n)); diff --git a/tests/calendar_epoch_tests.cpp b/tests/calendar_epoch_tests.cpp index 2d6c525..e06a77c 100644 --- a/tests/calendar_epoch_tests.cpp +++ b/tests/calendar_epoch_tests.cpp @@ -8,8 +8,9 @@ #include #include #include +#include "testing/check.hpp" -void check(bool ok,const char* message){if(!ok)throw std::runtime_error(message);} +using bmh::test_support::check; bmh::LeImage image(int year,int weekday) { constexpr uint32_t base=0x10000; constexpr size_t image_size=0xb0000; diff --git a/tests/classic_rules_unit_tests.cpp b/tests/classic_rules_unit_tests.cpp index a3a8b1f..9df0811 100644 --- a/tests/classic_rules_unit_tests.cpp +++ b/tests/classic_rules_unit_tests.cpp @@ -7,7 +7,8 @@ #include #include #include -void check(bool v,const char* m){if(!v)throw std::runtime_error(m);} +#include "testing/check.hpp" +using bmh::test_support::check; int main()try { using namespace bmh; constexpr uint32_t image_base=0x10000; diff --git a/tests/club_info_category_tests.cpp b/tests/club_info_category_tests.cpp index ba4d7e8..1faee6c 100644 --- a/tests/club_info_category_tests.cpp +++ b/tests/club_info_category_tests.cpp @@ -3,8 +3,9 @@ #include #include "game/club_info.hpp" #include "game/random.hpp" +#include "testing/check.hpp" using namespace bmh; -static void check(bool ok,const char* m){if(!ok)throw std::runtime_error(m);} +using bmh::test_support::check; static GameState fixture(int n){GameState g;g.team_morale.resize(358);for(size_t i=0;i>6;} int main(){try{ diff --git a/tests/club_info_tests.cpp b/tests/club_info_tests.cpp index 1e14b60..8860304 100644 --- a/tests/club_info_tests.cpp +++ b/tests/club_info_tests.cpp @@ -3,8 +3,9 @@ #include #include "game/club_info.hpp" #include "game/random.hpp" +#include "testing/check.hpp" using namespace bmh; -static void check(bool ok,const char* m){if(!ok)throw std::runtime_error(m);} +using bmh::test_support::check; static GameState fixture(int team,int count=20){GameState g;auto r=squad_range(team);g.squad_slots.assign(r.first+r.count,0x0fff);g.players.resize(64);for(int i=0;i #include +#include "testing/check.hpp" namespace { -void check(bool value, const char* what) { if (!value) throw std::runtime_error(what); } +using bmh::test_support::check; bmh::ui::ClubInfoProjection projection(bool squad) { bmh::ui::ClubInfoProjection p; diff --git a/tests/club_player_detail_tests.cpp b/tests/club_player_detail_tests.cpp index dcb982b..2067fa4 100644 --- a/tests/club_player_detail_tests.cpp +++ b/tests/club_player_detail_tests.cpp @@ -6,10 +6,11 @@ #include #include #include +#include "testing/check.hpp" using namespace bmh; namespace { -void check(bool value, const char* message) { if (!value) throw std::runtime_error(message); } +using bmh::test_support::check; GameState fixture() { GameState g; g.manager_teams = {0}; g.manager_records.resize(5 * 0xb0c); g.tactics.resize(5 * 0x840); diff --git a/tests/club_player_detail_ui_tests.cpp b/tests/club_player_detail_ui_tests.cpp index b9e31a3..ae2b262 100644 --- a/tests/club_player_detail_ui_tests.cpp +++ b/tests/club_player_detail_ui_tests.cpp @@ -5,11 +5,12 @@ #include "ui/manager.hpp" #include #include +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; namespace { -void check(bool ok,const char* why){if(!ok)throw std::runtime_error(why);} +using bmh::test_support::check; GameState fixture(const LeImage& exe){ GameState g;g.manager_teams={0};g.manager_records.resize(5*0xb0c);g.manager_options.resize(20); g.tactics.resize(5*0x840);g.squad_slots.assign(3096,0x0fff); diff --git a/tests/competition_winner_tests.cpp b/tests/competition_winner_tests.cpp index 650cded..d00e81c 100644 --- a/tests/competition_winner_tests.cpp +++ b/tests/competition_winner_tests.cpp @@ -9,8 +9,9 @@ #include "ui/sportschau.hpp" #include #include +#include "testing/check.hpp" using namespace bmh; -void check(bool value,const char* why){if(!value)throw std::runtime_error(why);} +using bmh::test_support::check; int main(int argc,char**argv){try{ check(argc==3,"winner tests data real-last-league-save");const std::filesystem::path data=argv[1],input=argv[2]; app::CareerSession plain(data,8128,input),observed(data,8128,input);auto& g=observed.state(); diff --git a/tests/cup_cursor_tests.cpp b/tests/cup_cursor_tests.cpp index 17ac8f9..b63565c 100644 --- a/tests/cup_cursor_tests.cpp +++ b/tests/cup_cursor_tests.cpp @@ -1,4 +1,5 @@ #include "runtime_fixture_tables.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include @@ -21,7 +22,7 @@ using namespace bmh; namespace { -void check(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); } +using bmh::test_support::check; GameState load(const std::filesystem::path& path, const LeImage& exe, const TextDb& texts) { const auto file=load_savegame(path); check(file.checksum_ok && file.version=="V2.24", "native fixture checksum/version"); diff --git a/tests/cup_draw_ui_tests.cpp b/tests/cup_draw_ui_tests.cpp index 233e72b..23cab6e 100644 --- a/tests/cup_draw_ui_tests.cpp +++ b/tests/cup_draw_ui_tests.cpp @@ -1,5 +1,6 @@ #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" @@ -20,7 +21,7 @@ #include "ui/manager.hpp" namespace { -void check(bool ok,const char* what){if(!ok)throw std::runtime_error(what);} +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) diff --git a/tests/cup_followup_tests.cpp b/tests/cup_followup_tests.cpp index 1a5869b..a380bda 100644 --- a/tests/cup_followup_tests.cpp +++ b/tests/cup_followup_tests.cpp @@ -1,4 +1,5 @@ #include "runtime_fixture_tables.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include @@ -18,7 +19,7 @@ using namespace bmh; namespace { -void check(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); } +using bmh::test_support::check; GameState load(const std::filesystem::path& path, const LeImage& exe, const TextDb& texts) { const auto file = load_savegame(path); diff --git a/tests/cup_seeded_followup_tests.cpp b/tests/cup_seeded_followup_tests.cpp index 68a7ac1..263ca87 100644 --- a/tests/cup_seeded_followup_tests.cpp +++ b/tests/cup_seeded_followup_tests.cpp @@ -1,4 +1,5 @@ #include "fixture_tables.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include @@ -11,7 +12,7 @@ using namespace bmh; namespace { -void check(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); } +using bmh::test_support::check; void entry(GameState& g, int index, int type, uint32_t teams, uint32_t results, uint8_t flags, uint8_t team_count, uint8_t rounds, uint8_t played, diff --git a/tests/daily_interest_unit_tests.cpp b/tests/daily_interest_unit_tests.cpp index 1e65df8..a649e08 100644 --- a/tests/daily_interest_unit_tests.cpp +++ b/tests/daily_interest_unit_tests.cpp @@ -4,10 +4,11 @@ #include #include #include +#include "testing/check.hpp" using namespace bmh; namespace { -void check(bool ok,const char* message){if(!ok)throw std::runtime_error(message);} +using bmh::test_support::check; void write(GameState& state,size_t at,int32_t value) { for(int byte=0;byte<4;++byte)state.manager_records.at(at+byte)=uint8_t(uint32_t(value)>>(byte*8)); } diff --git a/tests/desktop_feedback_tests.cpp b/tests/desktop_feedback_tests.cpp index 3994d06..34e1356 100644 --- a/tests/desktop_feedback_tests.cpp +++ b/tests/desktop_feedback_tests.cpp @@ -10,9 +10,10 @@ #include #include #include +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; -void check(bool ok,const char* message){if(!ok)throw std::runtime_error(message);} +using bmh::test_support::check; void capture(const std::filesystem::path& dir,const char* name,const Image& image,const Palette& palette){ if(dir.empty())return; std::filesystem::create_directories(dir); diff --git a/tests/environment_tests.cpp b/tests/environment_tests.cpp index 050706e..aaedb09 100644 --- a/tests/environment_tests.cpp +++ b/tests/environment_tests.cpp @@ -4,10 +4,11 @@ #include "ui/live_timing.hpp" #include #include +#include "testing/check.hpp" using namespace bmh; namespace { -void check(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); } +using bmh::test_support::check; GameState fixture() { GameState g; g.manager_teams = {0, 1}; diff --git a/tests/fixture_table_tests.cpp b/tests/fixture_table_tests.cpp index 826d822..8d0c406 100644 --- a/tests/fixture_table_tests.cpp +++ b/tests/fixture_table_tests.cpp @@ -6,10 +6,11 @@ #include #include #include +#include "testing/check.hpp" using namespace bmh; namespace { -void check(bool value, const char* message) { if (!value) throw std::runtime_error(message); } +using bmh::test_support::check; template void invalid(F action) { try { action(); } catch (const std::invalid_argument&) { return; } throw std::runtime_error("malformed fixture input was accepted"); diff --git a/tests/format_tests.cpp b/tests/format_tests.cpp index e55fe4e..4777a61 100644 --- a/tests/format_tests.cpp +++ b/tests/format_tests.cpp @@ -9,7 +9,7 @@ // // The data directory is an original installation (supported game edition 2026/27 in development). // The optional reference directory holds savegames recorded in the running original -// (see docs/REFERENCE.md): SP1VOR.FBM right before and SP2VOR.FBM right after +// (measured in the original): SP1VOR.FBM right before and SP2VOR.FBM right after // matchday 1. Expected values in these tests were read off the original's screens. #include #include @@ -221,7 +221,7 @@ static void test_schedule(const fs::path& data) { for (size_t i = 0; i < kResultsSize; i++) CHECK(!decode_result(results[i]).played); } -// Matchday 1 of the Bundesliga as shown by the original (docs/REFERENCE.md). +// Matchday 1 of the Bundesliga as shown by the original. static void test_matchday1(const fs::path& refs) { Savegame s = load_savegame(refs / "SP2VOR.FBM"); CHECK(s.checksum_ok); diff --git a/tests/game_end_alternate_tests.cpp b/tests/game_end_alternate_tests.cpp index 8244396..b6f3c8c 100644 --- a/tests/game_end_alternate_tests.cpp +++ b/tests/game_end_alternate_tests.cpp @@ -5,11 +5,12 @@ #include #include #include +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; namespace { -void check(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); } +using bmh::test_support::check; size_t colored(const Image& image, uint8_t color) { return size_t(std::count(image.pixels.begin(),image.pixels.end(),color)); } diff --git a/tests/game_end_cli_tests.cpp b/tests/game_end_cli_tests.cpp index 829809b..e4345bc 100644 --- a/tests/game_end_cli_tests.cpp +++ b/tests/game_end_cli_tests.cpp @@ -7,12 +7,13 @@ #include "app/career_session.hpp" #include "game/save.hpp" +#include "testing/check.hpp" using namespace bmh; using cli::Json; using Object = Json::Object; namespace { -void check(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); } +using bmh::test_support::check; Json request(Object fields) { return Json(std::move(fields)); } bool ok(const Json& response) { return *response.object()->at("ok").boolean(); } std::string error(const Json& response) { diff --git a/tests/game_end_tax_animation_tests.cpp b/tests/game_end_tax_animation_tests.cpp index de24e65..df38196 100644 --- a/tests/game_end_tax_animation_tests.cpp +++ b/tests/game_end_tax_animation_tests.cpp @@ -7,11 +7,12 @@ #include #include #include +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; namespace { -void check(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); } +using bmh::test_support::check; void rejected(const std::function& action) { try { action(); } catch (const FormatError&) { return; } throw std::runtime_error("expected malformed animation rejection"); diff --git a/tests/human_buyer_market_app_tests.cpp b/tests/human_buyer_market_app_tests.cpp index ebc9d5e..ef08c37 100644 --- a/tests/human_buyer_market_app_tests.cpp +++ b/tests/human_buyer_market_app_tests.cpp @@ -21,11 +21,12 @@ #include "game/save.hpp" #include "game/weekly.hpp" #include "ui/pending_offer.hpp" +#include "testing/check.hpp" namespace fs = std::filesystem; using namespace bmh; namespace { -void check(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); } +using bmh::test_support::check; uint32_t read32(const Bytes& b, size_t at) { uint32_t result = 0; for (size_t i = 0; i < 4; ++i) result |= uint32_t(b.at(at + i)) << (8 * i); diff --git a/tests/human_buyer_pending_app_tests.cpp b/tests/human_buyer_pending_app_tests.cpp index 67e8d25..831bc35 100644 --- a/tests/human_buyer_pending_app_tests.cpp +++ b/tests/human_buyer_pending_app_tests.cpp @@ -12,11 +12,12 @@ #include "game/match_engine.hpp" #include "game/save.hpp" #include "ui/pending_offer.hpp" +#include "testing/check.hpp" namespace fs = std::filesystem; using namespace bmh; namespace { -void check(bool value,const char* message){if(!value)throw std::runtime_error(message);} +using bmh::test_support::check; bool contains(const GameState& g,int team,int player){const auto r=squad_range(team); for(size_t i=r.first;i IncomingTransferScreen/ProjectTransferOfferList -> Void2 -> // SettleHumanBuyerSale -> PendingOfferAnswer -> 42707. No production pending adapter is called. @@ -428,7 +429,7 @@ using namespace bmh; namespace { constexpr uint32_t kOffers=::bmh::layout::OfferSlots, kList=::bmh::layout::EditorList+40*0x58; constexpr size_t kPool=0xb70+40, kRecord=0xb0c, kBoard=0x840, kBoardSlot=0x58; -void check(bool v,const char* what){if(!v)throw std::runtime_error(what);} +using bmh::test_support::check; uint32_t read32(const std::vector& b,size_t at){uint32_t v=0;for(int i=0;i<4;++i)v|=uint32_t(b.at(at+size_t(i)))<<(8*i);return v;} void write32(std::vector& b,size_t at,uint32_t v){for(int i=0;i<4;++i)b.at(at+size_t(i))=uint8_t(v>>(i*8));} bool contains(const GameState& g,int team,int player){const auto r=squad_range(team);for(size_t i=r.first;i @@ -21,7 +22,7 @@ #include "ui/strengths_state.hpp" using namespace bmh; namespace fs=std::filesystem; namespace { -void check(bool b,const char* why){if(!b)throw std::runtime_error(why);} +using bmh::test_support::check; template void rejects(F f,const char* why){bool rejected=false;try{f();}catch(const std::exception&){rejected=true;}check(rejected,why);} struct Oracle {uint32_t w;int32_t g;uint64_t wc,gc; void stir(){++wc;w=w*0x41c64e6du+0x3039;const int n=int(((w>>16)&32767)*201u/32768)+100; diff --git a/tests/league_table_controls_app_tests.cpp b/tests/league_table_controls_app_tests.cpp index 27ceab4..b057db8 100644 --- a/tests/league_table_controls_app_tests.cpp +++ b/tests/league_table_controls_app_tests.cpp @@ -10,11 +10,12 @@ #include "formats/le.hpp" #include "ui/league_family_request.hpp" #include "ui/league_table.hpp" +#include "testing/check.hpp" using namespace bmh; namespace fs = std::filesystem; namespace { -void check(bool ok, const char* why) { if (!ok) throw std::runtime_error(why); } +using bmh::test_support::check; struct Fixture { app::CareerSession session; uint64_t revision = 1; diff --git a/tests/league_table_controls_flow_tests.cpp b/tests/league_table_controls_flow_tests.cpp index 9ddd961..e04adda 100644 --- a/tests/league_table_controls_flow_tests.cpp +++ b/tests/league_table_controls_flow_tests.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" +#include "testing/check.hpp" // Controller/Flow integration coverage for the Source Table UI protocol. // These tests simulate the SDL host's real-present callback sequence; they are // not evidence of an actual SDL window run. The separate E37 root QA runner @@ -23,9 +24,7 @@ using namespace bmh; namespace fs = std::filesystem; namespace { -void check(bool ok, const char* message) { - if (!ok) throw std::runtime_error(message); -} +using bmh::test_support::check; struct Context { fs::path data; diff --git a/tests/lineup_assistant_detail_tests.cpp b/tests/lineup_assistant_detail_tests.cpp index bada8b6..c91c29f 100644 --- a/tests/lineup_assistant_detail_tests.cpp +++ b/tests/lineup_assistant_detail_tests.cpp @@ -3,11 +3,10 @@ #include #include "game/lineup.hpp" +#include "testing/check.hpp" namespace { -void check(bool ok, const char* what) { - if (!ok) throw std::runtime_error(what); -} +using bmh::test_support::check; bmh::GameState fixture(uint8_t style, uint8_t option, bool indoor) { bmh::GameState g; diff --git a/tests/lineup_foreign_limit_tests.cpp b/tests/lineup_foreign_limit_tests.cpp index 2496742..c7e146b 100644 --- a/tests/lineup_foreign_limit_tests.cpp +++ b/tests/lineup_foreign_limit_tests.cpp @@ -6,9 +6,10 @@ #include "formats/executable_layout.hpp" #include #include +#include "testing/check.hpp" namespace { -void check(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); } +using bmh::test_support::check; void enabled(bool value) { auto exe = bmh::LeImage::from_bytes(bmh::layout::ForeignPlayerLimitEnabled, bmh::Bytes{uint8_t(value)}); bmh::install_lineup_rules(exe); diff --git a/tests/loaded_manager_loop_tests.cpp b/tests/loaded_manager_loop_tests.cpp index 849bb11..d529a24 100644 --- a/tests/loaded_manager_loop_tests.cpp +++ b/tests/loaded_manager_loop_tests.cpp @@ -1,4 +1,5 @@ #include "runtime_fixture_tables.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include @@ -26,9 +27,7 @@ constexpr uint32_t kManagerPosition = ::bmh::layout::DeskPosition; constexpr uint32_t kManagerOrder = ::bmh::layout::NextDeskManager; constexpr uint32_t kOfferWords = ::bmh::layout::OfferSlots; -void check(bool value, const char* message) { - if (!value) throw std::runtime_error(message); -} +using bmh::test_support::check; GameState load(const std::filesystem::path& path, const LeImage& exe, const TextDb& texts) { const auto file = load_savegame(path); diff --git a/tests/long_career_tests.cpp b/tests/long_career_tests.cpp index 7acd269..1d14c0b 100644 --- a/tests/long_career_tests.cpp +++ b/tests/long_career_tests.cpp @@ -8,9 +8,10 @@ #include "game/matchday.hpp" #include "game/national.hpp" #include "game/save.hpp" +#include "testing/check.hpp" using namespace bmh; namespace { -void check(bool yes, const char* why) { if (!yes) throw std::runtime_error(why); } +using bmh::test_support::check; GameState fixture() { GameState g; g.season = 0; g.manager_teams = {0}; g.manager_records.resize(5 * 0xb0c); g.tactics.resize(5 * 0x840); diff --git a/tests/manager_desks_tests.cpp b/tests/manager_desks_tests.cpp index c2c248b..467b489 100644 --- a/tests/manager_desks_tests.cpp +++ b/tests/manager_desks_tests.cpp @@ -8,10 +8,11 @@ #include "formats/savestate.hpp" #include "game/matchday_setup.hpp" #include "game/save.hpp" +#include "testing/check.hpp" using namespace bmh; namespace { -void check(bool ok, const char* reason) { if (!ok) throw std::runtime_error(reason); } +using bmh::test_support::check; void set_f6(app::CareerSession& session, uint64_t& revision, uint8_t value) { if (session.state().memory.u8(::bmh::layout::MatchdaySetup_MatchdayNeedsManagerDesks_RuntimeField) == value) return; std::string error; diff --git a/tests/manager_join_app_tests.cpp b/tests/manager_join_app_tests.cpp index 0231646..9985ebe 100644 --- a/tests/manager_join_app_tests.cpp +++ b/tests/manager_join_app_tests.cpp @@ -5,11 +5,12 @@ #include #include "app/controller.hpp" #include "game/save.hpp" +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; namespace { -void check(bool value, const char* message) { if (!value) throw std::runtime_error(message); } +using bmh::test_support::check; struct Harness { std::filesystem::path data, saves; StartupFlow flow; diff --git a/tests/matchday_intro_tests.cpp b/tests/matchday_intro_tests.cpp index 7b85ea0..f0e9b90 100644 --- a/tests/matchday_intro_tests.cpp +++ b/tests/matchday_intro_tests.cpp @@ -7,9 +7,10 @@ #include "game/season.hpp" #include "ui/sportschau.hpp" #include "ui/live_reality.hpp" +#include "testing/check.hpp" using namespace bmh; -static void check(bool b,const char* why){if(!b)throw std::runtime_error(why);} +using bmh::test_support::check; static MatchGroup group(uint8_t type,uint32_t id=0){MatchGroup g;g.desc.assign(0xd0,0);g.desc[0]=type; for(size_t i=0;i<4;++i)g.desc[0xcc+i]=uint8_t(id>>(8*i));return g;} static void projection_and_pixels(const std::filesystem::path& data,const std::filesystem::path& input) { diff --git a/tests/national_nomination_tests.cpp b/tests/national_nomination_tests.cpp index 117f722..378f0e7 100644 --- a/tests/national_nomination_tests.cpp +++ b/tests/national_nomination_tests.cpp @@ -1,4 +1,5 @@ #include "runtime_fixture_tables.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include @@ -19,7 +20,7 @@ using namespace bmh; namespace { -void check(bool ok,const char* message){if(!ok)throw std::runtime_error(message);} +using bmh::test_support::check; struct Candidate { int player; int score; }; } int main(int argc,char**argv){try{ diff --git a/tests/national_pending_match_tests.cpp b/tests/national_pending_match_tests.cpp index 8838254..3d0760f 100644 --- a/tests/national_pending_match_tests.cpp +++ b/tests/national_pending_match_tests.cpp @@ -7,9 +7,10 @@ #include "app/career_session.hpp" #include "game/save.hpp" #include "national_coach_desk_pending_fixture.hpp" +#include "testing/check.hpp" using namespace bmh; namespace { -void check(bool ok,const char* why){if(!ok)throw std::runtime_error(why);} +using bmh::test_support::check; auto request(const GameState& g){return PendingOfferDeskRequest{ PendingOfferDeskRuntimeMode::normal_interactive,int(g.manager_teams.size()),int(g.memory.u8(::bmh::layout::DeskPosition))};} TurnAdvanceResult advance(app::CareerSession& s,uint64_t& revision){ diff --git a/tests/native_save_version_tests.cpp b/tests/native_save_version_tests.cpp index 67284a6..74ae9b8 100644 --- a/tests/native_save_version_tests.cpp +++ b/tests/native_save_version_tests.cpp @@ -7,9 +7,10 @@ #include #include #include +#include "testing/check.hpp" using namespace bmh; namespace { -void check(bool value,const char* why){if(!value)throw std::runtime_error(why);} +using bmh::test_support::check; templatevoid rejects(F function,const char* message){bool rejected=false;try{function();}catch(const FormatError&){rejected=true;}check(rejected,message);} } int main()try { diff --git a/tests/other_games_app_tests.cpp b/tests/other_games_app_tests.cpp index 7cf3bd4..78720f3 100644 --- a/tests/other_games_app_tests.cpp +++ b/tests/other_games_app_tests.cpp @@ -21,6 +21,7 @@ #include "game/messages.hpp" #include "ui/flow.hpp" #include "ui/other_games_state.hpp" +#include "testing/check.hpp" using namespace bmh; @@ -29,9 +30,7 @@ uint32_t other_games_source_round_day_for_test(const GameState&,uint32_t,int); } namespace { -void check(bool value, const char* message) { - if (!value) throw std::runtime_error(message); -} +using bmh::test_support::check; void start_career(const std::filesystem::path& data, ui::StartupFlow& flow, std::unique_ptr& session, uint64_t& revision, diff --git a/tests/other_games_ui_tests.cpp b/tests/other_games_ui_tests.cpp index 4ba3fde..79a47af 100644 --- a/tests/other_games_ui_tests.cpp +++ b/tests/other_games_ui_tests.cpp @@ -8,14 +8,13 @@ #include #include #include +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; namespace { -void check(bool ok, const char* message) { - if (!ok) throw std::runtime_error(message); -} +using bmh::test_support::check; void rejected(const std::function& action, const char* message) { try { action(); } catch (const FormatError&) { return; } throw std::runtime_error(message); diff --git a/tests/pending_offer_app_tests.cpp b/tests/pending_offer_app_tests.cpp index ef5df96..5c58f6e 100644 --- a/tests/pending_offer_app_tests.cpp +++ b/tests/pending_offer_app_tests.cpp @@ -8,9 +8,10 @@ #include "game/messages.hpp" #include "game/save.hpp" #include "ui/pending_offer.hpp" +#include "testing/check.hpp" using namespace bmh; namespace { -void check(bool value,const char* message){if(!value)throw std::runtime_error(message);} +using bmh::test_support::check; constexpr ClubPlayerDetailSelection selection{33,14,5,5,-1}; struct Snapshot { Bytes native; uint32_t w; int32_t g; uint64_t wc,gc; }; Snapshot snap(app::CareerSession& s){return {save_stream(s.state()),s.rand().seed(),s.game().seed(),s.rand().calls(),s.game().calls()};} diff --git a/tests/pending_offer_desk_tests.cpp b/tests/pending_offer_desk_tests.cpp index cd88b4a..6e3e695 100644 --- a/tests/pending_offer_desk_tests.cpp +++ b/tests/pending_offer_desk_tests.cpp @@ -10,12 +10,13 @@ #include "formats/textd.hpp" #include "game/pending_offer.hpp" #include "game/save.hpp" +#include "testing/check.hpp" using namespace bmh; namespace { constexpr uint32_t kOffers=::bmh::layout::OfferSlots, kOrder=::bmh::layout::NextDeskManager, kPosition=::bmh::layout::DeskPosition; constexpr size_t kPool40=0xb70+40, kClickedBoard=5*0x58; -void check(bool ok,const char* message){if(!ok)throw std::runtime_error(message);} +using bmh::test_support::check; uint32_t read32(const std::vector& bytes,size_t at){uint32_t v=0;for(int i=0;i<4;++i)v|=uint32_t(bytes.at(at+size_t(i)))<<(8*i);return v;} PendingOfferDeskRequest request(const GameState& g,int position=0, PendingOfferDeskRuntimeMode mode=PendingOfferDeskRuntimeMode::normal_interactive){ diff --git a/tests/pending_offer_tests.cpp b/tests/pending_offer_tests.cpp index 6ab7174..f52eec1 100644 --- a/tests/pending_offer_tests.cpp +++ b/tests/pending_offer_tests.cpp @@ -15,12 +15,13 @@ #include "game/pending_offer.hpp" #include "game/save.hpp" #include "game/season.hpp" +#include "testing/check.hpp" using namespace bmh; namespace { constexpr uint32_t offers=::bmh::layout::OfferSlots, list40=::bmh::layout::EditorList+40*0x58; constexpr size_t pool40=0xb70+40, board5=5*0x58; -void check(bool v,const char* what){if(!v)throw std::runtime_error(what);} +using bmh::test_support::check; uint32_t read(const std::vector& b,size_t at){uint32_t v=0;for(int i=0;i<4;++i)v|=uint32_t(b.at(at+size_t(i)))<<(8*i);return v;} void write(std::vector& b,size_t at,uint32_t v){for(int i=0;i<4;++i)b.at(at+size_t(i))=uint8_t(v>>(8*i));} bool contains(const GameState& g,int team,int player){const auto r=squad_range(team);for(size_t i=r.first;i @@ -20,9 +21,7 @@ using namespace bmh; namespace { -void check(bool ok, const char* message) { - if (!ok) throw std::runtime_error(message); -} +using bmh::test_support::check; GameState retained_pending_context(const GameState& game) { auto national = game; diff --git a/tests/phase_results_career_tests.cpp b/tests/phase_results_career_tests.cpp index 314ca10..9ff9b71 100644 --- a/tests/phase_results_career_tests.cpp +++ b/tests/phase_results_career_tests.cpp @@ -9,12 +9,11 @@ #include "game/save.hpp" #include "ui/league_pairings.hpp" #include "ui/other_games.hpp" +#include "testing/check.hpp" using namespace bmh; namespace { -void check(bool value, const char* message) { - if (!value) throw std::runtime_error(message); -} +using bmh::test_support::check; uint64_t start(app::CareerSession& session) { ui::SetupOptions options; ui::ManagerChoice choice; diff --git a/tests/process_timer_tests.cpp b/tests/process_timer_tests.cpp index d9998af..c82956d 100644 --- a/tests/process_timer_tests.cpp +++ b/tests/process_timer_tests.cpp @@ -4,10 +4,11 @@ #include "ui/manager.hpp" #include #include +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; -static void check(bool ok, const char* why) { if (!ok) throw std::runtime_error(why); } +using bmh::test_support::check; int main(int argc,char**argv) {try { if(argc!=2)throw std::runtime_error("data directory required"); const auto exe=load_le(asset_path(argv[1],"BMH.exe")); diff --git a/tests/quit_confirmation_unit_tests.cpp b/tests/quit_confirmation_unit_tests.cpp index 9c2616f..8d84efd 100644 --- a/tests/quit_confirmation_unit_tests.cpp +++ b/tests/quit_confirmation_unit_tests.cpp @@ -4,9 +4,10 @@ #include #include #include +#include "testing/check.hpp" namespace { -void check(bool value, const char* message) { if (!value) throw std::runtime_error(message); } +using bmh::test_support::check; void push(Uint32 type) { SDL_Event event{}; event.type = type; check(SDL_PushEvent(&event) == 1, "cannot enqueue authored event"); diff --git a/tests/reality_ball_tests.cpp b/tests/reality_ball_tests.cpp index f289189..e6d18a1 100644 --- a/tests/reality_ball_tests.cpp +++ b/tests/reality_ball_tests.cpp @@ -3,10 +3,11 @@ #include #include "game/reality_ball.hpp" +#include "testing/check.hpp" using namespace bmh; namespace { -void check(bool ok,const char* text) { if (!ok) throw std::runtime_error(text); } +using bmh::test_support::check; GameState state_fixture() { GameState state;state.players.resize(22);state.player_bonus.resize(22);state.team_morale={24,24}; for (auto& player:state.players) { player.w35c=48u|(100u<<7)|(100u<<14);player.w368=3u|(3u<<4)|(3u<<6); } diff --git a/tests/reality_career_special_tests.cpp b/tests/reality_career_special_tests.cpp index 4712af1..ab3ee10 100644 --- a/tests/reality_career_special_tests.cpp +++ b/tests/reality_career_special_tests.cpp @@ -5,12 +5,11 @@ #include "app/career_session.hpp" #include "game/save.hpp" +#include "testing/check.hpp" using namespace bmh; namespace { -void check(bool value, const char* message) { - if (!value) throw std::runtime_error(message); -} +using bmh::test_support::check; struct Coverage { int scenes = 0, scene_humans = 0, ordinary_humans = 0, direct_penalties = 0; diff --git a/tests/reality_deferred_tests.cpp b/tests/reality_deferred_tests.cpp index d0bdfbf..0673ae0 100644 --- a/tests/reality_deferred_tests.cpp +++ b/tests/reality_deferred_tests.cpp @@ -1,4 +1,5 @@ #include "runtime_fixture_tables.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include @@ -9,7 +10,7 @@ #include "game/save.hpp" using namespace bmh; namespace { -void check(bool ok,const char* text){if(!ok)throw std::runtime_error(text);} +using bmh::test_support::check; MatchGroup fixture(){MatchGroup g;g.desc.resize(0xd0);g.fixtures={0,1};g.results={0};g.spectators={12000};g.records={70,70,90,90,90,90,80,60,3,70,70,90,90,90,90,80,60,3};return g;} } int main(int argc,char** argv){try{ diff --git a/tests/reality_duel_tests.cpp b/tests/reality_duel_tests.cpp index 2e60ea1..2bb368c 100644 --- a/tests/reality_duel_tests.cpp +++ b/tests/reality_duel_tests.cpp @@ -3,10 +3,11 @@ #include #include #include "game/reality_duel.hpp" +#include "testing/check.hpp" using namespace bmh; namespace { -void check(bool ok,const char* text) { if (!ok) throw std::runtime_error(text); } +using bmh::test_support::check; GameState state_fixture() { GameState s;s.players.resize(22);s.player_bonus.resize(22);s.team_morale={24,24};s.squad_slots.resize(48,kEmptySlot); for (int i=0;i<22;++i) { diff --git a/tests/reality_forced_event_tests.cpp b/tests/reality_forced_event_tests.cpp index 1615f7a..a1d46a8 100644 --- a/tests/reality_forced_event_tests.cpp +++ b/tests/reality_forced_event_tests.cpp @@ -1,4 +1,5 @@ #include "runtime_fixture_tables.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include @@ -13,7 +14,7 @@ using namespace bmh; namespace { -void check(bool ok,const char* text) { if (!ok) throw std::runtime_error(text); } +using bmh::test_support::check; MatchGroup fixture() { MatchGroup g;g.desc.resize(0xd0);g.fixtures={0,1};g.results={0};g.spectators={12000}; g.records={70,70,90,90,90,90,80,60,3,70,70,90,90,90,90,80,60,3};return g; diff --git a/tests/reality_matchday_tests.cpp b/tests/reality_matchday_tests.cpp index 261be71..247f441 100644 --- a/tests/reality_matchday_tests.cpp +++ b/tests/reality_matchday_tests.cpp @@ -1,4 +1,5 @@ #include "runtime_fixture_tables.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include @@ -9,7 +10,7 @@ #include "game/save.hpp" using namespace bmh; namespace { -void check(bool value,const char* text) { if (!value) throw std::runtime_error(text); } +using bmh::test_support::check; MatchGroup fixture() { MatchGroup g;g.desc.resize(0xd0);g.desc[1]=2;g.desc[2]=1; g.fixtures={0,1};g.results={0};g.end_minute={0};g.spectators={12000}; diff --git a/tests/reality_motion_tests.cpp b/tests/reality_motion_tests.cpp index da3134d..e1f86e9 100644 --- a/tests/reality_motion_tests.cpp +++ b/tests/reality_motion_tests.cpp @@ -9,10 +9,11 @@ #include "ui/live_reality.hpp" #include "ui/live_matchday.hpp" #include "ui/setup.hpp" +#include "testing/check.hpp" using namespace bmh; namespace { -void check(bool value, const char* message) { if (!value) throw std::runtime_error(message); } +using bmh::test_support::check; template void rejected(F f) { bool failed = false; try { f(); } catch (const FormatError&) { failed = true; } check(failed, "invalid Reality input must fail before drawing"); diff --git a/tests/reality_movement_tests.cpp b/tests/reality_movement_tests.cpp index 6cb697e..7448d8c 100644 --- a/tests/reality_movement_tests.cpp +++ b/tests/reality_movement_tests.cpp @@ -3,10 +3,11 @@ #include #include "game/reality_movement.hpp" +#include "testing/check.hpp" using namespace bmh; namespace { -void check(bool ok,const char* text) { if (!ok) throw std::runtime_error(text); } +using bmh::test_support::check; GameState players() { GameState state;state.players.resize(22); for (auto& player:state.players) { player.w35c=127u<<14;player.w368=3u<<3; } diff --git a/tests/reality_reporter_layout_tests.cpp b/tests/reality_reporter_layout_tests.cpp index 37ef12d..301fcec 100644 --- a/tests/reality_reporter_layout_tests.cpp +++ b/tests/reality_reporter_layout_tests.cpp @@ -1,4 +1,5 @@ #include "test_inputs.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include @@ -7,7 +8,7 @@ #include "ui/reality_reporter.hpp" using namespace bmh; namespace { -void check(bool ok,const char* text){if(!ok)throw std::runtime_error(text);} +using bmh::test_support::check; Image background(){Image image(320,240);for(int y=0;y<240;++y)for(int x=0;x<320;++x)image.at(x,y)=uint8_t((x+3*y)%47);return image;} } int main(int argc,char** argv){try{ diff --git a/tests/reality_reporter_tests.cpp b/tests/reality_reporter_tests.cpp index 030a6db..493de20 100644 --- a/tests/reality_reporter_tests.cpp +++ b/tests/reality_reporter_tests.cpp @@ -1,4 +1,5 @@ #include "runtime_fixture_tables.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include @@ -11,7 +12,7 @@ #include "game/save.hpp" using namespace bmh; namespace { -void check(bool ok,const char* text){if(!ok)throw std::runtime_error(text);} +using bmh::test_support::check; // Independent Source cursor interpreter. Unlike the product's parsed tree, // this walks # delimiters and skips unchosen nested expressions (legacy routine). size_t skip(std::string_view text,size_t at) { diff --git a/tests/reality_scene_tests.cpp b/tests/reality_scene_tests.cpp index 8854cbc..fdd762e 100644 --- a/tests/reality_scene_tests.cpp +++ b/tests/reality_scene_tests.cpp @@ -1,4 +1,5 @@ #include "runtime_fixture_tables.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include @@ -10,7 +11,7 @@ #include "game/save.hpp" using namespace bmh; namespace { -void check(bool ok,const char* text){if(!ok)throw std::runtime_error(text);} +using bmh::test_support::check; GameState fixture(const std::filesystem::path& data,const LeImage& exe,const TextDb& texts) { const DbCounts counts{exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField),exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField3),exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField2),exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField4)}; auto state=GameState::from_save(SaveState(load_savegame(data/"AUTOSAVE.FBM").stream,counts),counts); diff --git a/tests/reality_setup_tests.cpp b/tests/reality_setup_tests.cpp index 9229ef9..9cdd56e 100644 --- a/tests/reality_setup_tests.cpp +++ b/tests/reality_setup_tests.cpp @@ -3,10 +3,11 @@ #include #include "game/reality_setup.hpp" +#include "testing/check.hpp" using namespace bmh; namespace { -void check(bool value, const char* text) { if (!value) throw std::runtime_error(text); } +using bmh::test_support::check; void put16(Bytes& bytes,size_t at,uint16_t value) { bytes.at(at)=uint8_t(value);bytes.at(at+1)=uint8_t(value>>8); } diff --git a/tests/reality_space_tests.cpp b/tests/reality_space_tests.cpp index e9c50f2..c5c1675 100644 --- a/tests/reality_space_tests.cpp +++ b/tests/reality_space_tests.cpp @@ -4,10 +4,11 @@ #include #include "game/reality_space.hpp" +#include "testing/check.hpp" using namespace bmh; namespace { -void check(bool value,const char* text) { if (!value) throw std::runtime_error(text); } +using bmh::test_support::check; void player(RealitySetup& scene,int id,int x,int y) { check(scene.grid.place(id,x,y,id/11),"fixture player placement"); scene.motion.figures[size_t(id)]={true,x,y,x,y,0}; diff --git a/tests/season_cup_draw_tests.cpp b/tests/season_cup_draw_tests.cpp index 7e23eff..bdbd7a8 100644 --- a/tests/season_cup_draw_tests.cpp +++ b/tests/season_cup_draw_tests.cpp @@ -1,4 +1,5 @@ #include "runtime_fixture_tables.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include @@ -20,7 +21,7 @@ using namespace bmh; namespace { -void check(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); } +using bmh::test_support::check; GameState load(const std::filesystem::path& path, const LeImage& exe, const TextDb& texts) { const auto file=load_savegame(path); check(file.checksum_ok && file.version=="V2.24", "native fixture checksum/version"); diff --git a/tests/season_end_desk_tests.cpp b/tests/season_end_desk_tests.cpp index 60f2dd6..45b0930 100644 --- a/tests/season_end_desk_tests.cpp +++ b/tests/season_end_desk_tests.cpp @@ -7,9 +7,10 @@ #include "game/month.hpp" #include "game/save.hpp" #include "game/turn_driver.hpp" +#include "testing/check.hpp" using namespace bmh; namespace { -void check(bool ok,const char* text){if(!ok)throw std::runtime_error(text);} +using bmh::test_support::check; void install_contract_decisions(app::CareerSession& s){ s.set_contract_expiry_presenter([](GameState& g,WatcomRandom& w,int m,int row){ const auto demands=contract_demands(g,m,row,false,w); diff --git a/tests/season_player_reset_tests.cpp b/tests/season_player_reset_tests.cpp index 67b0849..35a2dae 100644 --- a/tests/season_player_reset_tests.cpp +++ b/tests/season_player_reset_tests.cpp @@ -5,9 +5,10 @@ #include #include #include +#include "testing/check.hpp" namespace { -void check(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); } +using bmh::test_support::check; bmh::GameState fixture(int slot, int age, bool foreign = false) { bmh::GameState g; constexpr uint32_t data_begin = 0xa0000; diff --git a/tests/season_promotion_tests.cpp b/tests/season_promotion_tests.cpp index 120f03a..b2d6056 100644 --- a/tests/season_promotion_tests.cpp +++ b/tests/season_promotion_tests.cpp @@ -1,4 +1,5 @@ #include "runtime_fixture_tables.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include @@ -19,7 +20,7 @@ using namespace bmh; namespace { -void check(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); } +using bmh::test_support::check; GameState load(const std::filesystem::path& path, const LeImage& exe, const TextDb& texts) { const auto file=load_savegame(path); check(file.checksum_ok && file.version=="V2.24", "native fixture checksum/version"); diff --git a/tests/season_tax_tests.cpp b/tests/season_tax_tests.cpp index 834e7f4..7c0b5e8 100644 --- a/tests/season_tax_tests.cpp +++ b/tests/season_tax_tests.cpp @@ -10,9 +10,10 @@ #include "game/save.hpp" #include "game/season.hpp" #include "game/messages.hpp" +#include "testing/check.hpp" using namespace bmh; -void check(bool value, const char* text) { if (!value) throw std::runtime_error(text); } +using bmh::test_support::check; void put(GameState& g, size_t at, uint32_t v) { for (size_t i=0;i<4;++i)g.manager_records.at(at+i)=uint8_t(v>>(8*i)); } diff --git a/tests/shared_desktop_actions_tests.cpp b/tests/shared_desktop_actions_tests.cpp index e534aed..1f52519 100644 --- a/tests/shared_desktop_actions_tests.cpp +++ b/tests/shared_desktop_actions_tests.cpp @@ -8,13 +8,12 @@ #include #include #include +#include "testing/check.hpp" using namespace bmh; namespace { -void check(bool condition, const char* message) { - if (!condition) throw std::runtime_error(message); -} +using bmh::test_support::check; struct Snapshot { Bytes native; diff --git a/tests/sound_settings_app_tests.cpp b/tests/sound_settings_app_tests.cpp index cc50826..5dcbe7d 100644 --- a/tests/sound_settings_app_tests.cpp +++ b/tests/sound_settings_app_tests.cpp @@ -7,10 +7,11 @@ #include "app/career_session.hpp" #include "game/save.hpp" +#include "testing/check.hpp" using namespace bmh; namespace { -void check(bool ok, const char* why) { if (!ok) throw std::runtime_error(why); } +using bmh::test_support::check; struct Snapshot { Bytes native; diff --git a/tests/sportschau_eleven_tests.cpp b/tests/sportschau_eleven_tests.cpp index 08d6e3d..04a2c1a 100644 --- a/tests/sportschau_eleven_tests.cpp +++ b/tests/sportschau_eleven_tests.cpp @@ -4,9 +4,10 @@ #include "app/career_session.hpp" #include "game/save.hpp" #include "ui/sportschau.hpp" +#include "testing/check.hpp" using namespace bmh; -static void check(bool b,const char* message) {if(!b) throw std::runtime_error(message);} +using bmh::test_support::check; static void word(Bytes& b,size_t at,uint16_t v) {b.at(at)=uint8_t(v);b.at(at+1)=uint8_t(v>>8);} static void controlled(const std::filesystem::path& data) { diff --git a/tests/sportschau_rating_tests.cpp b/tests/sportschau_rating_tests.cpp index b7c7e72..31b7d83 100644 --- a/tests/sportschau_rating_tests.cpp +++ b/tests/sportschau_rating_tests.cpp @@ -5,9 +5,10 @@ #include "game/matchday.hpp" #include "game/save.hpp" #include "game/turn.hpp" +#include "testing/check.hpp" using namespace bmh; -static void check(bool b, const char* message) { if (!b) throw std::runtime_error(message); } +using bmh::test_support::check; static void put16(Bytes& b,size_t at,uint16_t value) {b.at(at)=uint8_t(value);b.at(at+1)=uint8_t(value>>8);} static void controlled(const LeImage& exe) { diff --git a/tests/sportschau_scene_tests.cpp b/tests/sportschau_scene_tests.cpp index 9d96db5..125fc81 100644 --- a/tests/sportschau_scene_tests.cpp +++ b/tests/sportschau_scene_tests.cpp @@ -6,9 +6,10 @@ #include "game/save.hpp" #include "ui/live_matchday.hpp" #include "ui/sportschau.hpp" +#include "testing/check.hpp" using namespace bmh; -static void check(bool b,const char* message) { if(!b) throw std::runtime_error(message); } +using bmh::test_support::check; static void same_random(const WatcomRandom& a,const WatcomRandom& b) { check(a.seed()==b.seed()&&a.calls()==b.calls(),"Source scene draw sequence matches existing animation functions"); } diff --git a/tests/sportschau_teaminfo_tests.cpp b/tests/sportschau_teaminfo_tests.cpp index 6428f5a..2b23fc9 100644 --- a/tests/sportschau_teaminfo_tests.cpp +++ b/tests/sportschau_teaminfo_tests.cpp @@ -4,9 +4,10 @@ #include "app/career_session.hpp" #include "game/save.hpp" #include "ui/sportschau.hpp" +#include "testing/check.hpp" using namespace bmh; -static void check(bool b, const char* why) { if (!b) throw std::runtime_error(why); } +using bmh::test_support::check; static void dword(Bytes& b, size_t at, uint32_t v) { for (size_t i = 0; i < 4; ++i) b.at(at+i) = uint8_t(v >> (8*i)); } diff --git a/tests/sportschau_ui_tests.cpp b/tests/sportschau_ui_tests.cpp index 988b0b3..392e97a 100644 --- a/tests/sportschau_ui_tests.cpp +++ b/tests/sportschau_ui_tests.cpp @@ -10,14 +10,13 @@ #include "formats/binary.hpp" #include "formats/font.hpp" #include "formats/le.hpp" +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; namespace { -void check(bool condition, const char* message) { - if (!condition) throw std::runtime_error(message); -} +using bmh::test_support::check; uint8_t pixel(const Image& image, int x, int y) { return image.pixels.at(size_t(y) * size_t(image.width) + size_t(x)); diff --git a/tests/stadium_block_app_tests.cpp b/tests/stadium_block_app_tests.cpp index 4f34b17..7f78ae4 100644 --- a/tests/stadium_block_app_tests.cpp +++ b/tests/stadium_block_app_tests.cpp @@ -19,13 +19,12 @@ #include "game/schedule.hpp" #include "ui/settings.hpp" #include "ui/flow.hpp" +#include "testing/check.hpp" using namespace bmh; namespace { -void check(bool ok,const char* message) { - if(!ok) throw std::runtime_error(message); -} +using bmh::test_support::check; void start_career(const std::filesystem::path& data,ui::StartupFlow& flow, std::unique_ptr& session,uint64_t& revision, diff --git a/tests/stadium_block_ui_tests.cpp b/tests/stadium_block_ui_tests.cpp index 2747bcb..eec78b8 100644 --- a/tests/stadium_block_ui_tests.cpp +++ b/tests/stadium_block_ui_tests.cpp @@ -11,14 +11,13 @@ #include #include #include +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; namespace { -void check(bool ok, const char* message) { - if (!ok) throw std::runtime_error(message); -} +using bmh::test_support::check; void copy_crop(Image& dst, const Image& src, int sx, int sy, int x, int y, int w, int h) { for (int row = 0; row < h; ++row) for (int col = 0; col < w; ++col) { diff --git a/tests/stadium_extended_limits_tests.cpp b/tests/stadium_extended_limits_tests.cpp index c7ffa3e..12f15e9 100644 --- a/tests/stadium_extended_limits_tests.cpp +++ b/tests/stadium_extended_limits_tests.cpp @@ -6,8 +6,9 @@ #include #include #include +#include "testing/check.hpp" namespace { -void check(bool value,const char* message){if(!value)throw std::runtime_error(message);} +using bmh::test_support::check; } int main()try{ using namespace bmh; diff --git a/tests/start_screen_tests.cpp b/tests/start_screen_tests.cpp index 75de032..8774b6f 100644 --- a/tests/start_screen_tests.cpp +++ b/tests/start_screen_tests.cpp @@ -10,8 +10,9 @@ #include #include #include +#include "testing/check.hpp" namespace { -void check(bool value,const char* message){if(!value)throw std::runtime_error(message);} +using bmh::test_support::check; void frame(int width,int height,const std::filesystem::path& output) { const std::unique_ptr surface( SDL_CreateRGBSurfaceWithFormat(0,width,height,32,SDL_PIXELFORMAT_RGBA32),SDL_FreeSurface); diff --git a/tests/statistics_case2_app_tests.cpp b/tests/statistics_case2_app_tests.cpp index 2cf3a7c..b659b14 100644 --- a/tests/statistics_case2_app_tests.cpp +++ b/tests/statistics_case2_app_tests.cpp @@ -11,12 +11,13 @@ #include "game/save.hpp" #include "game/messages.hpp" #include "ui/world_cup_statistics.hpp" +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; namespace { -void check(bool condition, const char* text) { if (!condition) throw std::runtime_error(text); } +using bmh::test_support::check; void test_national_friendly_calendar_deadline(const std::filesystem::path& data,const std::filesystem::path& fixture) { for(int kind=0;kind<3;++kind) { diff --git a/tests/team_statistics_tests.cpp b/tests/team_statistics_tests.cpp index ecd3af4..aae0d12 100644 --- a/tests/team_statistics_tests.cpp +++ b/tests/team_statistics_tests.cpp @@ -1,4 +1,5 @@ #include "runtime_fixture_tables.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "ui/team_statistics.hpp" @@ -14,7 +15,7 @@ #include "ui/setup.hpp" namespace { -void check(bool value, const char* message) { if (!value) throw std::runtime_error(message); } +using bmh::test_support::check; uint8_t pixel(const bmh::Image& image, int x, int y) { return image.pixels.at(size_t(y) * size_t(image.width) + size_t(x)); } diff --git a/tests/top_scorers_app_tests.cpp b/tests/top_scorers_app_tests.cpp index 113237a..070cb09 100644 --- a/tests/top_scorers_app_tests.cpp +++ b/tests/top_scorers_app_tests.cpp @@ -18,14 +18,13 @@ #include "game/national.hpp" #include "ui/flow.hpp" #include "ui/manager.hpp" +#include "testing/check.hpp" using namespace bmh; namespace { -void check(bool value, const char* message) { - if (!value) throw std::runtime_error(message); -} +using bmh::test_support::check; GameState empty_game(std::vector managers = {0}) { GameState g; diff --git a/tests/training_camp_app_tests.cpp b/tests/training_camp_app_tests.cpp index 191e1d0..4d8f3dd 100644 --- a/tests/training_camp_app_tests.cpp +++ b/tests/training_camp_app_tests.cpp @@ -9,12 +9,13 @@ #include "formats/le.hpp" #include "game/save.hpp" #include "ui/flow.hpp" +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; namespace { -void check(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); } +using bmh::test_support::check; void content_lifecycle(const std::filesystem::path& data) { const auto exe = load_le(data / "BMH.exe"); diff --git a/tests/training_dispatch_app_tests.cpp b/tests/training_dispatch_app_tests.cpp index 9745180..268445e 100644 --- a/tests/training_dispatch_app_tests.cpp +++ b/tests/training_dispatch_app_tests.cpp @@ -7,12 +7,13 @@ #include "formats/le.hpp" #include "ui/flow.hpp" #include "ui/training.hpp" +#include "testing/check.hpp" using namespace bmh; using namespace bmh::ui; namespace { -void check(bool ok, const char* message) { if (!ok) throw std::runtime_error(message); } +using bmh::test_support::check; TrainingRequest request_for(const TrainingState& state, TrainingRequestKind kind) { TrainingRequest request; diff --git a/tests/transfer_offer_player_info_tests.cpp b/tests/transfer_offer_player_info_tests.cpp index 1ebcb91..07a6acc 100644 --- a/tests/transfer_offer_player_info_tests.cpp +++ b/tests/transfer_offer_player_info_tests.cpp @@ -1,4 +1,5 @@ #include "runtime_fixture_tables.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include @@ -22,7 +23,7 @@ using namespace bmh; namespace fs=std::filesystem; namespace { -void check(bool ok,const char* why){if(!ok)throw std::runtime_error(why);} +using bmh::test_support::check; struct Snapshot { Bytes native; GameRandom game; WatcomRandom rand; uint64_t revision; Snapshot(app::CareerSession& s,uint64_t rev):native(save_stream(s.state())),game(s.game()),rand(s.rand()),revision(rev){} diff --git a/tests/transfer_offer_team_info_tests.cpp b/tests/transfer_offer_team_info_tests.cpp index 4e540f2..3e45c57 100644 --- a/tests/transfer_offer_team_info_tests.cpp +++ b/tests/transfer_offer_team_info_tests.cpp @@ -1,4 +1,5 @@ #include "runtime_fixture_tables.hpp" +#include "testing/check.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include @@ -22,7 +23,7 @@ using namespace bmh; namespace fs=std::filesystem; namespace { -void check(bool ok,const char* why){if(!ok)throw std::runtime_error(why);} +using bmh::test_support::check; struct Snapshot { Bytes native; GameRandom game; WatcomRandom rand; uint64_t revision; Snapshot(app::CareerSession& s,uint64_t rev):native(save_stream(s.state())),game(s.game()),rand(s.rand()),revision(rev){} diff --git a/tests/weekly_human_buyer_loan_tests.cpp b/tests/weekly_human_buyer_loan_tests.cpp index db65d8f..885a964 100644 --- a/tests/weekly_human_buyer_loan_tests.cpp +++ b/tests/weekly_human_buyer_loan_tests.cpp @@ -12,10 +12,11 @@ #include "game/save.hpp" #include "game/transfer_allocator.hpp" #include "game/weekly.hpp" +#include "testing/check.hpp" using namespace bmh; namespace { -void check(bool value, const char* why) { if (!value) throw std::runtime_error(why); } +using bmh::test_support::check; void write32(std::vector& bytes, size_t at, uint32_t value) { for (size_t n = 0; n < 4; ++n) bytes.at(at + n) = uint8_t(value >> (n * 8)); } diff --git a/tests/world_layout_tests.cpp b/tests/world_layout_tests.cpp index c7251ce..9ba0657 100644 --- a/tests/world_layout_tests.cpp +++ b/tests/world_layout_tests.cpp @@ -9,13 +9,12 @@ #include "game/schedule.hpp" #include "game/state.hpp" #include "game/world_layout.hpp" +#include "testing/check.hpp" using namespace bmh; namespace { -void check(bool value, const char* message) { - if (!value) throw std::runtime_error(message); -} +using bmh::test_support::check; // squad_range as it was written before the world layout existed (state.cpp up to 1.0.12). SquadRange former_squad_range(int team) {