From f7ecb55def0e0724bc4c85b2fc38736d28b1b4d5 Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 16 Oct 2026 19:40:37 +0200 Subject: [PATCH] Make synthetic schedule and stadium tests independent of original defaults (by Codex) --- tests/cup_seeded_followup_tests.cpp | 2 ++ tests/fixture_table_tests.cpp | 30 ++++++++++++++++++++++++++ tests/other_games_projection_tests.cpp | 5 ++++- tests/stand_block_actions_tests.cpp | 2 +- 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/tests/cup_seeded_followup_tests.cpp b/tests/cup_seeded_followup_tests.cpp index e1c7637..68a7ac1 100644 --- a/tests/cup_seeded_followup_tests.cpp +++ b/tests/cup_seeded_followup_tests.cpp @@ -1,3 +1,4 @@ +#include "fixture_tables.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include @@ -116,6 +117,7 @@ void knockout_to_seeded_knockout() { } int main() { + bmh::set_fixture_tables(bmh::test::authored_fixture_tables()); try { group_to_seeded_linked_groups(1); group_to_seeded_linked_groups(3); diff --git a/tests/fixture_table_tests.cpp b/tests/fixture_table_tests.cpp index eb8b4e7..9501c20 100644 --- a/tests/fixture_table_tests.cpp +++ b/tests/fixture_table_tests.cpp @@ -93,6 +93,36 @@ void data(const std::filesystem::path& directory) { } } } + const auto before = generate_fixtures(4, 1, 3, 37); + const auto reject_image = [&](const LeImage& image) { + invalid([&] { install_fixture_tables(image); }); + same(before, generate_fixtures(4, 1, 3, 37)); + }; + const auto patch_pointer = [](LeImage& image, uint32_t at, uint32_t value) { + const uint8_t bytes[]{uint8_t(value), uint8_t(value >> 8), uint8_t(value >> 16), uint8_t(value >> 24)}; + image.patch(at, bytes, sizeof(bytes)); + }; + auto malformed = exe; + patch_pointer(malformed, tables.at(4) + 4, exe.base() + exe.size()); + reject_image(malformed); + malformed = exe; + patch_pointer(malformed, tables.at(4), exe.u32(tables.at(4) + 4)); + reject_image(malformed); + malformed = exe; + const uint8_t nonzero = 1; + malformed.patch(exe.u32(tables.at(4) + 4) + 4, &nonzero, 1); + reject_image(malformed); + malformed = exe; + const auto first_row = exe.u32(tables.at(4) + 4); + const auto duplicate = exe.u8(first_row + 1); + malformed.patch(first_row, &duplicate, 1); + reject_image(malformed); + // An earlier valid change must not leak when a later table is malformed. + malformed = exe; + const uint8_t swapped[]{exe.u8(first_row + 1), exe.u8(first_row)}; + malformed.patch(first_row, swapped, sizeof(swapped)); + malformed.patch(exe.u32(tables.at(20) + 4) + 20, &nonzero, 1); + reject_image(malformed); if (is_english) { invalid([] { generate_fixtures(16, 1, 15, 0); }); invalid([] { generate_fixtures(18, 1, 17, 0); }); diff --git a/tests/other_games_projection_tests.cpp b/tests/other_games_projection_tests.cpp index bc62c05..f1b460e 100644 --- a/tests/other_games_projection_tests.cpp +++ b/tests/other_games_projection_tests.cpp @@ -1,3 +1,4 @@ +#include "fixture_tables.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include @@ -104,6 +105,7 @@ bmh::TextDb texts() { } // namespace int main() { + bmh::set_fixture_tables(bmh::test::authored_fixture_tables()); bmh::GameState game = fixture(); const bmh::TextDb db = texts(); bool rejected = false; @@ -276,7 +278,8 @@ int main() { const auto group = bmh::other_games_from_game(game, db, 1, 0, 2, bmh::OtherGamesDisplayMode::compact, 0, false); check(!group.knockout && group.rows.size() == 2 && group.rows[0].home_team == 4 && - group.rows[0].away_team == 7 && group.source_participant_count == 1 && + group.rows[0].away_team == 5 && group.rows[1].home_team == 6 && + group.rows[1].away_team == 7 && group.source_participant_count == 1 && group.group_tables.size() == 1 && group.rows[0].source_second_leg == 0xcccc && !group.rows[0].second_leg_array_present && group.rows[0].source_winner == -1, "group rows retain all later-round fixtures and ignore the unused second-result pointer"); diff --git a/tests/stand_block_actions_tests.cpp b/tests/stand_block_actions_tests.cpp index 17a9492..46a55ca 100644 --- a/tests/stand_block_actions_tests.cpp +++ b/tests/stand_block_actions_tests.cpp @@ -235,7 +235,7 @@ int main() { const auto option=options(g,4).front();WatcomRandom rand(53),expected(53);expected.range(6,14); auto offer=no_tip(option,rand);const auto before=g.manager_records;auto want=before; set32(want,0x314,20000000-245000);set32(want,0x8a0,245000);want[0x171]=0; - want[0x30]=4;want[0x40]=0x10; + want[0x30]=constants.weeks[4];want[0x40]=0x10; check(build(g,4,option,offer,rand)&&g.manager_records==want&&rand.seed()==expected.seed()&&rand.calls()==1, "Source sponsor deterministic subsidy consumes share and no extra W draw"); }