Make synthetic schedule and stadium tests independent of original defaults (by Codex)

This commit is contained in:
Codex committed 2026-10-16 19:40:37 +02:00
1 parent 558fbf166b
commit f7ecb55def
4 files changed
+37 -2

No files matched your search

+2
View File
@@ -1,3 +1,4 @@
#include "fixture_tables.hpp"
// SPDX-License-Identifier: GPL-3.0-only
#include "formats/executable_layout.hpp"
#include <algorithm>
@@ -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);
+30
View File
@@ -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); });
+4 -1
View File
@@ -1,3 +1,4 @@
#include "fixture_tables.hpp"
// SPDX-License-Identifier: GPL-3.0-only
#include "formats/executable_layout.hpp"
#include <algorithm>
@@ -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");
+1 -1
View File
@@ -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");
}