Port environment, advertising and Toto menus to native Modern UI (by Codex)

This commit is contained in:
Codex committed 2026-10-24 11:12:25 +02:00
1 parent 0aa0ed68ca
commit d92cfc3110
36 files changed
+1805 -13

No files matched your search

+155
View File
@@ -0,0 +1,155 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "modern/ui/demo_advertising.hpp"
#include <chrono>
#include <fstream>
#include <iostream>
#include <stdexcept>
using namespace bmh::modern_ui;
namespace {
void require(bool condition, const char *message) {
if (!condition) throw std::runtime_error(message);
}
struct Fixture {
fs::path root;
std::shared_ptr<const Catalog> world;
explicit Fixture(Json precision) {
root = fs::temp_directory_path() / ("openbmh-advertising-ui-" +
std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
fs::create_directories(root / "world");
const auto write = [&](const fs::path &file, const Json &value) {
std::ofstream out(file); out << value.dump();
require(bool(out), "Cannot write synthetic catalogue");
};
write(root / "manifest.json", {{"format", "openbmh-world"}, {"kind", "world"},
{"format_version", "1.1"}, {"id", "world:synthetic-advertising"},
{"currency", {{"code", "EUR"}, {"minor_units", precision}}},
{"requires", {"editor:world-v1"}}, {"x-editor", {{"profile", "editor-world-v1"}}}});
for (const auto *table : {"clubs", "players", "competitions"})
write(root / "world" / (std::string(table) + ".json"), {{"items", Json::array()}});
world = Catalog::open(root);
}
~Fixture() { std::error_code ec; fs::remove_all(root, ec); }
};
void reject(Json &state, const Json &action, const Catalog &world) {
const auto before = state;
require(!edit_demo_advertising(state, action, world).empty() && state == before,
"Rejected advertising action mutated state or was accepted");
}
void edit(Json &state, const Json &action, const Catalog &world) {
const auto error = edit_demo_advertising(state, action, world);
if (!error.empty()) throw std::runtime_error("Unexpected advertising rejection: " + error);
require(valid_demo_advertising(state, world), "Accepted action produced invalid advertising state");
}
Json without_ads(Json state) { state.erase("advertising"); return state; }
void check_currency(int precision) {
Fixture fixture(precision);
const auto &world = *fixture.world;
const int64_t factor = precision == 2 ? 100 : 1;
Json state = {{"cash", 12450000 * factor}, {"deposit", 600000 * factor}, {"debt", 0}, {"ticket", 13},
{"training", {{"untouched", true}}}, {"contracts", {{"unrelated", {4, 5, 6}}}}};
const auto original = state, manifest = world.manifest(), clubs = world.rows("clubs");
require(!valid_demo_advertising(state, world) && migrate_demo_advertising(state, world) &&
valid_demo_advertising(state, world) && without_ads(state) == original,
"Migration lost unrelated fields or failed to add defaults");
const auto defaults = state;
const auto view = demo_advertising_view(state, world);
require(view.at("slots").size() == 16 && view.at("spending").size() == 3 &&
view.at("income") == 0 && view.at("expenses") == 75000 * factor &&
view.at("balance") == -75000 * factor && view.at("spending")[0].at("suggestion_step") == 50000 &&
view.at("spending")[1].at("suggestion_step") == 5000, "Default budgets or aggregate projection incorrect");
const auto board = demo_advertising_quote(state, 0, 0, world), shirt = demo_advertising_quote(state, 14, 2, world), tv = demo_advertising_quote(state, 15, 1, world);
require(board.at("amount") == 7000 * factor && board.at("name") == "MAINWERK" && board.at("months") == 12 &&
shirt.at("amount") == 158000 * factor && shirt.at("months") == 36 && shirt.at("sponsor") == 4 &&
tv.at("amount") == 104200 * factor && tv.at("name") == "FUSSBALL TV" && tv.at("months") == 24 &&
demo_advertising_quote(state, 13, 2, world).at("amount") == 17800 * factor,
"Pinned fictional offer prices, issuer or terms changed");
auto copied = board; copied["amount"] = 1;
require(demo_advertising_quote(state, 0, 0, world) == board && state == defaults,
"Query result aliases state or projection mutates state");
for (const auto &pair : {std::pair{-1, 0}, {16, 0}, {0, -1}, {0, 3}})
require(demo_advertising_quote(state, pair.first, pair.second, world).at("ok") == false && state == defaults,
"Out-of-range offer query accepted or mutated state");
edit(state, {{"kind", "accept"}, {"slot", 15}, {"offer", 1}}, world);
require(state.at("advertising").at("contracts")[15] == Json({{"sponsor", 1}, {"months", 24}, {"amount", 104200 * factor}}) &&
demo_advertising_view(state, world).at("income") == 104200 * factor && without_ads(state) == original,
"Acceptance booked cash, stored the wrong offer or failed totals");
const auto active = demo_advertising_quote(state, 15, 2, world);
require(active.at("active") == true && active.at("amount") == tv.at("amount") && active.at("months") == 24,
"Viewing another offer replaced an active contract");
reject(state, {{"kind", "accept"}, {"slot", 15}, {"offer", 2}}, world);
for (int slot = 0; slot < 15; ++slot) edit(state, {{"kind", "accept"}, {"slot", slot}, {"offer", slot % 3}}, world);
int64_t sum = 0;
for (const auto &c : state.at("advertising").at("contracts")) sum += c.at("amount").get<int64_t>();
require(demo_advertising_view(state, world).at("income") == sum && without_ads(state) == original,
"Full contract projection lost an income or changed wallet");
edit(state, {{"kind", "spending"}, {"index", 0}, {"value", 0}}, world);
edit(state, {{"kind", "spending"}, {"index", 1}, {"value", 12345}}, world);
edit(state, {{"kind", "spending"}, {"index", 2}, {"value", 99999999}}, world);
require(state["advertising"]["spending"][0] == 0 && state["advertising"]["spending"][1] == 12345 * factor &&
demo_advertising_view(state, world).at("expenses") == (99999999LL + 12345) * factor && without_ads(state) == original,
"Budget editor unit conversion or monetary isolation failed");
const auto preserved = state;
require(migrate_demo_advertising(state, world) && state == preserved &&
valid_demo_advertising(Json::parse(state.dump()), world), "Migration changed a valid saved agreement");
for (const auto &action : std::vector<Json>{nullptr, Json::array(), "bad", Json::object(), {{"kind", 1}},
{{"kind", "unknown"}}, {{"kind", "accept"}}, {{"kind", "accept"}, {"slot", 16}, {"offer", 0}},
{{"kind", "accept"}, {"slot", 0}, {"offer", 3}}, {{"kind", "accept"}, {"slot", 0}, {"offer", true}},
{{"kind", "accept"}, {"slot", uint64_t(-1)}, {"offer", 0}},
{{"kind", "accept"}, {"slot", 0}, {"offer", 0}, {"amount", 1}},
{{"kind", "spending"}}, {{"kind", "spending"}, {"index", 3}, {"value", 1}},
{{"kind", "spending"}, {"index", 0}, {"value", -1}}, {{"kind", "spending"}, {"index", 0}, {"value", 100000000}},
{{"kind", "spending"}, {"index", 0}, {"value", uint64_t(-1)}},
{{"kind", "spending"}, {"index", 0}, {"value", 1.0}}, {{"kind", "spending"}, {"index", 0}, {"value", true}},
{{"kind", "spending"}, {"index", 0}, {"value", 1}, {"cash", 0}}}) reject(state, action, world);
std::vector<Json> invalid;
auto bad = state; bad["advertising"] = nullptr; invalid.push_back(bad);
bad = state; bad["advertising"]["selected"] = 0; invalid.push_back(bad);
bad = state; bad["advertising"].erase("spending"); invalid.push_back(bad);
bad = state; bad["advertising"]["spending"].push_back(0); invalid.push_back(bad);
bad = state; bad["advertising"]["spending"][0] = uint64_t(-1); invalid.push_back(bad);
bad = state; bad["advertising"]["spending"][0] = 100000000LL * factor; invalid.push_back(bad);
bad = state; bad["advertising"]["contracts"][0]["sponsor"] = uint64_t(-1); invalid.push_back(bad);
bad = state; bad["advertising"]["contracts"][0]["sponsor"] = 10; invalid.push_back(bad);
bad = state; bad["advertising"]["contracts"][15]["sponsor"] = 5; invalid.push_back(bad);
bad = state; bad["advertising"]["contracts"][0]["months"] = 6; invalid.push_back(bad);
bad = state; bad["advertising"]["contracts"][0]["amount"] = 0; invalid.push_back(bad);
bad = state; bad["advertising"]["contracts"][0]["extra"] = true; invalid.push_back(bad);
bad = defaults; bad["advertising"]["contracts"][0]["months"] = 12; invalid.push_back(bad);
bad = defaults; bad["advertising"]["contracts"][0]["amount"] = 1; invalid.push_back(bad);
bad = defaults; bad["advertising"]["contracts"].erase(bad["advertising"]["contracts"].end() - 1); invalid.push_back(bad);
for (auto &v : invalid) {
require(!valid_demo_advertising(v, world), "Malformed stored advertising accepted");
const auto before = v;
require(!migrate_demo_advertising(v, world) && before == v, "Migration repaired present malformed data");
reject(v, {{"kind", "spending"}, {"index", 0}, {"value", 0}}, world);
require(demo_advertising_view(v, world).at("ok") == false, "Malformed state projected as valid");
}
auto maximum = state;
for (auto &c : maximum["advertising"]["contracts"]) c["amount"] = 99999999LL * factor;
for (auto &s : maximum["advertising"]["spending"]) s = 99999999LL * factor;
const auto totals = demo_advertising_view(maximum, world);
require(totals.at("income") == 16 * 99999999LL * factor && totals.at("expenses") == 3 * 99999999LL * factor &&
totals.at("balance") == 13 * 99999999LL * factor, "Aggregate overflow or unsafe money scaling");
auto cents = defaults;
if (precision == 2) {
cents["advertising"]["spending"][0] = 12345;
const auto original_cents = cents;
require(migrate_demo_advertising(cents, world) && cents == original_cents,
"Migration silently changed saved fractional currency values");
}
require(world.manifest() == manifest && world.rows("clubs") == clubs, "Advertising altered immutable world");
}
} // namespace
int main() try {
check_currency(0); check_currency(2);
for (const auto &precision : std::vector<Json>{1, 3, true, "2", nullptr, uint64_t(-1)}) {
Fixture invalid_currency(precision); Json state = {{"cash", 5}}; const auto before = state;
require(!migrate_demo_advertising(state, *invalid_currency.world) && state == before,
"Unsupported precision was silently substituted");
}
std::cout << "Modern UI advertising checks passed\n";
return 0;
} catch (const std::exception &error) {
std::cerr << error.what() << '\n'; return 1;
}
+1 -1
View File
@@ -100,7 +100,7 @@ int main(int argc, char **argv) try {
std::ostringstream css;
for (const auto *name : {"theme.rcss", "ticket.rcss", "sports.rcss",
"calendar.rcss", "reports.rcss", "report_details.rcss",
"report_pickers.rcss", "indoor.rcss", "planning.rcss", "almanac.rcss", "finance.rcss", "bank.rcss", "contracts.rcss", "amount.rcss"}) {
"report_pickers.rcss", "indoor.rcss", "planning.rcss", "almanac.rcss", "finance.rcss", "bank.rcss", "contracts.rcss", "amount.rcss", "environment.rcss", "advertising.rcss", "toto.rcss"}) {
std::ifstream input(root / name);
require(bool(input), "Production stylesheet missing");
css << input.rdbuf() << '\n';
+128
View File
@@ -0,0 +1,128 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "modern/ui/demo_environment.hpp"
#include <array>
#include <chrono>
#include <iostream>
#include <stdexcept>
using namespace bmh::modern_ui;
namespace {
void require(bool value, const char *message) {
if (!value) throw std::runtime_error(message);
}
struct Fixture {
fs::path root;
std::shared_ptr<const Catalog> world;
explicit Fixture(Json precision = 0) {
root = fs::temp_directory_path() / ("openbmh-environment-ui-" +
std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
fs::create_directories(root / "world");
bmh::editor::write_atomic(root / "manifest.json", Json({{"format", "openbmh-world"},
{"kind", "world"}, {"format_version", "1.1"}, {"id", "world:synthetic-environment"},
{"requires", {"editor:world-v1"}}, {"x-editor", {{"profile", "editor-world-v1"}}},
{"currency", {{"code", "EUR"}, {"minor_units", precision}}}}).dump());
for (const auto *table : {"nations", "clubs", "players", "competitions"})
bmh::editor::write_atomic(root / "world" / (std::string(table) + ".json"),
Json({{"items", Json::array()}}).dump());
bmh::editor::write_atomic(root / "world/staff.json", Json({{"items", Json::array({
{{"id", "staff:synthetic"}, {"name", "Synthetic catalogue staff"}, {"role", "doctor"}}})}}).dump());
world = Catalog::open(root);
}
~Fixture() { std::error_code ec; fs::remove_all(root, ec); }
};
void currency_case(int precision, int64_t factor) {
Fixture f(precision);
const auto staff = f.world->rows("staff");
const auto staff_file = bmh::editor::read_file(f.root / "world/staff.json");
Json state = {{"cash", 123456 * factor}, {"deposit", 750 * factor}, {"debt", 0},
{"staff", {{"unrelated_legacy_marker", "preserved"}}}, {"edits", {{"other", 17}}}};
const auto legacy = state;
require(migrate_demo_environment(state, *f.world) && valid_demo_environment(state, *f.world),
"Missing environment budgets did not migrate");
require(state.at("environment").at("levels") == Json::array({2,3,4,3,4,2}),
"Diamond 3.6 initial budgets changed");
auto without_environment = state;
without_environment.erase("environment");
require(without_environment == legacy, "Migration changed wallet, staff or unrelated legacy fields");
const auto initial = state;
require(migrate_demo_environment(state, *f.world) && state == initial,
"Environment migration is not idempotent");
const auto projection = demo_environment_rows(state, *f.world);
require(projection.value("ok", false) && projection.at("rows").size() == 6 &&
projection.at("total") == 88500 * factor && state == initial,
"Default monthly preview or read-only projection changed");
const std::array<int64_t, 6> rates{2000,3000,5000,7500,6000,4500};
for (size_t i = 0; i < rates.size(); ++i) {
const auto &row = projection.at("rows")[i];
require(row.at("rate") == rates[i] * factor &&
row.at("cost") == rates[i] * factor * initial.at("environment").at("levels")[i].get<int>(),
"Environment preview double-converted currency or changed its Gold rate");
require(i < 3 ? row.at("rank").is_number_integer() && row.at("league").is_number_integer()
: row.at("rank").is_null() && row.at("league").is_null(),
"Staff inherited a fictional youth standing");
}
for (int i = 0; i < 6; ++i)
require(edit_demo_environment(state, {{"kind", "level"}, {"index", i}, {"value", 0}}, *f.world).empty(),
"Zero budget was rejected");
require(demo_environment_rows(state, *f.world).at("total") == 0,
"Disabled budgets invented ongoing preview costs");
for (int i = 0; i < 6; ++i)
require(edit_demo_environment(state, {{"kind", "level"}, {"index", i}, {"value", 6}}, *f.world).empty(),
"Sixth star was unavailable");
require(demo_environment_rows(state, *f.world).at("total") == 168000 * factor,
"Six-star monthly total or raw currency precision is wrong");
const auto funded = state;
require(edit_demo_environment(state, {{"kind", "level"}, {"index", 0}, {"value", 6}}, *f.world).empty() && state == funded,
"Selecting the current budget toggled it off");
require(migrate_demo_environment(state, *f.world) && state == funded,
"Checkpoint migration reset existing budget choices");
auto unrelated = state;
unrelated.erase("environment");
require(unrelated == legacy && f.world->rows("staff") == staff &&
bmh::editor::read_file(f.root / "world/staff.json") == staff_file,
"Environment selection booked cash or modified catalogue staff");
const std::vector<Json> invalid_actions = {nullptr, Json::array(), Json::object(),
{{"kind", "other"}, {"index", 0}, {"value", 1}},
{{"kind", "level"}, {"index", -1}, {"value", 1}},
{{"kind", "level"}, {"index", 6}, {"value", 1}},
{{"kind", "level"}, {"index", true}, {"value", 1}},
{{"kind", "level"}, {"index", 0}, {"value", -1}},
{{"kind", "level"}, {"index", 0}, {"value", 7}},
{{"kind", "level"}, {"index", 0}, {"value", 6.0}},
{{"kind", "level"}, {"index", 0}, {"value", false}},
{{"kind", "level"}, {"index", 0}, {"value", uint64_t(-1)}},
{{"kind", "level"}, {"index", 0}, {"value", 2}, {"cash", 0}}};
for (const auto &action : invalid_actions) {
const auto before = state;
require(!edit_demo_environment(state, action, *f.world).empty() && state == before,
"Invalid environment action threw or changed state");
}
std::vector<Json> invalid_states{nullptr, Json::array(), Json{{"environment", nullptr}},
Json{{"environment", {{"levels", {0,0,0,0,0}}}}},
Json{{"environment", {{"levels", {0,0,0,0,0,7}}}}},
Json{{"environment", {{"levels", {0,0,0,0,0,true}}}}},
Json{{"environment", {{"levels", {0,0,0,0,0,1.0}}}}},
Json{{"environment", {{"levels", {0,0,0,0,0,0}}, {"extra", 1}}}}};
for (auto invalid : invalid_states) {
const auto before = invalid;
require(!valid_demo_environment(invalid, *f.world) &&
!migrate_demo_environment(invalid, *f.world) && invalid == before &&
!edit_demo_environment(invalid, {{"kind", "level"}, {"index", 0}, {"value", 1}}, *f.world).empty() &&
invalid == before && !demo_environment_rows(invalid, *f.world).value("ok", true),
"Malformed environment data was partially repaired or projected");
}
}
} // namespace
int main() try {
currency_case(0, 1);
currency_case(2, 100);
Fixture unsupported(1);
Json state = Json::object();
require(!migrate_demo_environment(state, *unsupported.world) && state.empty(),
"Unsupported currency precision initialized a misleading environment budget");
std::cout << "Modern environment preview checks passed\n";
return 0;
} catch (const std::exception &error) {
std::cerr << error.what() << '\n';
return 1;
}
+109
View File
@@ -0,0 +1,109 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "modern/ui/demo_toto.hpp"
#include "modern/ui/demo_reports.hpp"
#include "modern/ui/model.hpp"
#include "modern/ui/desktop.hpp"
#include <chrono>
#include <fstream>
#include <iostream>
#include <set>
#include <stdexcept>
using namespace bmh::modern_ui;
namespace {
void require(bool ok, const char *message) { if (!ok) throw std::runtime_error(message); }
struct Fixture {
fs::path path; std::shared_ptr<const Catalog> world;
Fixture(int precision = 0, bool full = true) {
path = fs::temp_directory_path() / ("openbmh-toto-ui-" + std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
fs::create_directories(path / "world");
auto write = [&](const char *name, const Json &data) { std::ofstream out(path / name); out << data.dump(); require(bool(out), "Cannot write fixture"); };
write("manifest.json", {{"format", "openbmh-world"}, {"kind", "world"}, {"format_version", "1.1"},
{"id", "world:synthetic-toto"}, {"start_date", "2026-07-01"}, {"currency", {{"code", "EUR"}, {"minor_units", precision}}},
{"requires", {"editor:world-v1"}}, {"x-editor", {{"profile", "editor-world-v1"}}}});
write("world/nations.json", {{"items", {{{"id", "nation:de"}, {"name", "Synthetic nation"}}}}});
Json leagues = Json::array(), clubs = Json::array();
for (int tier = 1; tier <= 2; ++tier) {
auto id = "league:synthetic-" + std::to_string(tier);
leagues.push_back({{"id", id}, {"name", "Synthetic league " + std::to_string(tier)},
{"nation", "nation:de"}, {"type", "league"}, {"tier", tier}});
for (int c = 0; c < (full ? 18 : 2); ++c)
clubs.push_back({{"id", "club:synthetic-" + std::to_string(tier) + "-" + std::to_string(c)},
{"name", "Synthetic club " + std::to_string(tier) + "-" + std::to_string(c)},
{"competition", id}, {"nation", "nation:de"}, {"order", c}});
}
write("world/competitions.json", {{"items", leagues}}); write("world/clubs.json", {{"items", clubs}});
write("world/players.json", {{"items", Json::array()}});
world = Catalog::open(path);
}
~Fixture() { std::error_code ec; fs::remove_all(path, ec); }
};
void successful(Json &s, const Json &a, const Catalog &w) { require(edit_demo_toto(s, a, w).empty(), "Expected valid Toto action"); }
void rejected(Json &s, const Json &a, const Catalog &w) {
const auto before = s; require(!edit_demo_toto(s, a, w).empty(), "Invalid Toto action accepted"); require(s == before, "Rejected action mutated state");
}
void exercise(int precision) {
Fixture fixture(precision); const auto &world = *fixture.world;
const int64_t factor = precision == 2 ? 100 : 1;
Json state = {{"cash", 900000 * factor}, {"deposit", 400000 * factor}, {"other", {"untouched"}}};
require(migrate_demo_toto(state, world), "Legacy migration failed");
const auto initial = state;
require(migrate_demo_toto(state, world) && state == initial, "Migration changed existing state");
require(state["toto"]["stake"] == 1000 * factor && demo_toto_summary(state, world)["complete"] == 1, "Initial stakes/columns differ");
auto programme = demo_toto_programme(world);
require(programme["complete"] == true && programme["rows"].size() == 11, "No complete 9+2 programme");
std::set<std::string> sides;
for (size_t i = 0; i < 11; ++i) {
const auto &m = programme["rows"][i]; require(m["tier"] == (i < 9 ? 1 : 2), "Wrong league mixture");
require(m["home"] != m["away"] && world.find("clubs", m["home"]) && world.find("clubs", m["away"]), "Invented opponent");
require(sides.insert(m["home"]).second && sides.insert(m["away"]).second, "Duplicate team in programme");
}
successful(state, {{"kind", "submit"}}, world);
const auto receipt = state["toto"]["coupon"];
successful(state, {{"kind", "pick"}, {"column", 1}, {"row", 4}, {"pick", 2}}, world);
require(demo_toto_summary(state, world)["partial"] == 1 && state["toto"]["columns"][0] == initial["toto"]["columns"][0], "Columns not independent");
rejected(state, {{"kind", "submit"}}, world);
successful(state, {{"kind", "pick"}, {"column", 1}, {"row", 4}, {"pick", 2}}, world);
require(demo_toto_summary(state, world)["partial"] == 0, "Clicking cross again does not clear");
for (int c = 1; c < 6; ++c) successful(state, {{"kind", "auto"}, {"column", c}}, world);
require(demo_toto_summary(state, world)["complete"] == 6 && state["toto"]["coupon"] == receipt, "Working picks mutated receipt");
successful(state, {{"kind", "stake"}, {"value", 0}}, world); rejected(state, {{"kind", "submit"}}, world);
successful(state, {{"kind", "stake"}, {"value", 99999999}}, world);
require(state["toto"]["stake"] == 99999999 * factor, "Money precision changed twice");
successful(state, {{"kind", "submit"}}, world);
const auto full = state["toto"]["coupon"];
for (int c = 0; c < 6; ++c) successful(state, {{"kind", "clear"}, {"column", c}}, world);
rejected(state, {{"kind", "submit"}}, world);
require(state["toto"]["coupon"] == full, "Clearing picks altered the receipt");
for (auto a : {Json{{"kind", "pick"}, {"column", -1}, {"row", 0}, {"pick", 1}},
Json{{"kind", "pick"}, {"column", 0}, {"row", 11}, {"pick", 1}},
Json{{"kind", "pick"}, {"column", 0}, {"row", 0}, {"pick", 3}},
Json{{"kind", "stake"}, {"value", 100000000}}, Json{{"kind", "stake"}, {"value", 1.5}},
Json{{"kind", "auto"}, {"column", uint64_t(-1)}}, Json{{"kind", "unrecognized"}}}) rejected(state, a, world);
auto rest = state; rest.erase("toto"); auto original = initial; original.erase("toto");
require(rest == original && demo_toto_programme(world) == programme, "Toto booked money or changed programme");
auto bad = state; bad["toto"]["columns"][0].push_back(0); auto before = bad;
require(!migrate_demo_toto(bad, world) && bad == before, "Invalid existing state repaired");
bad = state; bad["toto"]["coupon"]["columns"][0][3] = -1;
require(!valid_demo_toto(bad, world), "Partial saved coupon accepted");
DemoSource source(fixture.world); const auto old = source.snapshot();
require(source.apply({old.revision, "toto", {{"kind", "stake"}, {"value", 2100}}}).ok, "DataSource cannot edit stake");
require(!source.apply({old.revision, "toto", {{"kind", "submit"}}}).ok, "Stale revision accepted");
auto accepted = source.snapshot();
require(!source.apply({accepted.revision, "toto", {{"kind", "stake"}, {"value", -1}}}).ok && source.snapshot().state == accepted.state, "Failed action partially committed");
auto file = fixture.path / "state.json"; source.save(file, default_desktop());
source.apply({source.snapshot().revision, "toto", {{"kind", "clear"}, {"column", 0}}});
source.load(file); require(source.snapshot().state == accepted.state && !source.dirty(), "Checkpoint roundtrip failed");
auto legacy = accepted.state; legacy.erase("toto"); legacy["desktop"] = default_desktop();
{ std::ofstream out(file); out << legacy.dump(); } source.load(file);
require(source.snapshot().state["toto"] == initial["toto"] && source.snapshot().state["cash"] == accepted.state["cash"], "Legacy load altered wallet");
}
} // namespace
int main() try {
exercise(0); exercise(2);
Fixture partial(0, false); Json state = Json::object();
require(migrate_demo_toto(state, *partial.world), "Incomplete world migration failed");
require(demo_toto_programme(*partial.world)["complete"] == false, "Incomplete programme masked");
rejected(state, {{"kind", "submit"}}, *partial.world);
std::cout << "Modern Toto UI tests passed\n";
return 0;
} catch (const std::exception &e) { std::cerr << e.what() << '\n'; return 1; }
+41
View File
@@ -6,7 +6,11 @@
#include "modern/ui/desktop.hpp"
#include "modern/ui/gui_assets.hpp"
#include "modern/ui/model.hpp"
#include "modern/ui/demo_environment.hpp"
#include "modern/ui/demo_advertising.hpp"
#include "modern/ui/demo_toto.hpp"
#include <chrono>
#include <fstream>
#include <iostream>
#include <stdexcept>
@@ -25,6 +29,42 @@ void table(const fs::path &root, const std::string &name, const Json &rows) {
name == "assets" ? "assets/index.json" : "world/" + name + ".json",
{{"schema", name + "@1.0"}, {"items", rows}});
}
void check_club_views(const fs::path &root, std::shared_ptr<const Catalog> world) {
DemoSource source(world);
auto initial = source.snapshot();
require(valid_demo_environment(initial.state, *world) && valid_demo_advertising(initial.state, *world) && valid_demo_toto(initial.state, *world), "Club preview initialization invalid");
require(source.apply({initial.revision, "environment", {{"kind", "level"}, {"index", 0}, {"value", 6}}}).ok, "Environment action failed");
auto changed = source.snapshot();
int slot = -1;
for (int i = 0; i < 16; ++i) if (changed.state["advertising"]["contracts"][size_t(i)]["sponsor"] == -1) {slot=i;break;}
require(slot >= 0, "No test offer slot");
const Json offer = {{"kind", "accept"}, {"slot", slot}, {"offer", 2}};
require(!source.apply({initial.revision, "advertising", offer}).ok && source.snapshot().state == changed.state && source.snapshot().revision == changed.revision, "Stale advertising quote changed source");
require(source.apply({changed.revision, "advertising", offer}).ok, "Valid advertising offer rejected");
changed = source.snapshot();
require(!source.apply({changed.revision, "advertising", offer}).ok && source.snapshot().state == changed.state, "Active advertising contract overwritten");
require(source.apply({changed.revision, "advertising", {{"kind", "spending"}, {"index", 2}, {"value", 7000}}}).ok, "Advertising budget rejected");
changed = source.snapshot();
for (const auto *key : {"cash", "deposit", "debt", "training", "tactics", "calendar", "reports", "finance", "contracts"})
require(changed.state.at(key) == initial.state.at(key), "Club previews changed unrelated state");
const auto saved = root / "club-preview-checkpoint.json";
source.save(saved, default_desktop());
source.apply({source.snapshot().revision, "environment", {{"kind", "level"}, {"index", 0}, {"value", 0}}});
source.load(saved);
require(source.snapshot().state == changed.state && !source.dirty(), "Club preview checkpoint did not roundtrip");
auto malformed = changed.state; malformed["desktop"] = default_desktop();
malformed["advertising"]["spending"][0] = "invalid";
{std::ofstream out(saved);out << malformed.dump();}
const auto before = source.snapshot(); bool threw = false;
try {source.load(saved);} catch (const std::exception &) {threw = true;}
require(threw && source.snapshot().state == before.state && source.snapshot().revision == before.revision, "Malformed club checkpoint partially loaded");
auto legacy = changed.state; legacy["desktop"] = default_desktop();
legacy.erase("environment"); legacy.erase("advertising"); legacy.erase("toto");
{std::ofstream out(saved);out << legacy.dump();}
source.load(saved); const auto migrated = source.snapshot().state;
require(migrated["environment"] == initial.state["environment"] && migrated["advertising"] == initial.state["advertising"] && migrated["toto"] == initial.state["toto"], "Legacy club fields not initialized");
require(migrated["cash"] == changed.state["cash"] && migrated["finance"] == changed.state["finance"], "Legacy migration reset wallet");
}
void check_finance_source(const fs::path &root,
const std::shared_ptr<const Catalog> &base) {
const auto folder = root / "finance-source";
@@ -579,6 +619,7 @@ int main(int argc, char **argv) try {
restored_planning.snapshot().state["reports"]["sorts"]["indoor"]["key"] == "points",
"Old checkpoint lost league preview or failed planning/indoor migration");
check_finance_source(root, world);
check_club_views(root, world);
GuiAssets absent(root / "missing-gui");
require(!absent.available(),
"World resources were mistaken for GUI resources");