Something went wrong. Try again.
[Mirror] Libreopolis is a cross-platform city simulation game fully compatible with SimCity 2000. gitlab.com/conasg/libreopolis
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667// .SC2 save round-trip KAT (io/sc2_file.hpp save_sc2): load a real city, save it, load the saved file,// and assert every tracked layer / array / MISC / name is byte-identical. This is the verifiable bar for// File → Save (real-game loadability would need the game itself). Skips without the cities.#include "sc2k/io/sc2_file.hpp"#include <cstdio>#include <filesystem>#include <fstream>#include <string>
#include "test_harness.hpp"#include "test_paths.hpp"int main() { using namespace sc2k; const std::string rejected = "/tmp/sc2k_non_small_rejected.sc2"; std::error_code ec; std::filesystem::remove(rejected, ec); CHECK(!io::save_sc2(rejected, City(MapSize::Large)).ok); CHECK(!std::filesystem::exists(rejected));
const std::string src = city_file("TOKYO.SC2"); if (!std::filesystem::exists(src)) { std::printf("save: SKIP (no TOKYO.SC2)\n"); return 0; }
City a; CHECK(io::load_sc2(src, a).ok); const std::string tmp = "/tmp/sc2k_roundtrip.sc2"; CHECK(io::save_sc2(tmp, a).ok); City b; CHECK(io::load_sc2(tmp, b).ok);
// Every tracked field must survive the round-trip exactly. CHECK(a.name == b.name); CHECK(a.misc == b.misc); CHECK(a.altm.cells == b.altm.cells); CHECK(a.xter.cells == b.xter.cells); CHECK(a.xbld.cells == b.xbld.cells); CHECK(a.xzon.cells == b.xzon.cells); CHECK(a.xund.cells == b.xund.cells); CHECK(a.xtxt.cells == b.xtxt.cells); CHECK(a.xbit.cells == b.xbit.cells); CHECK(a.xtrf.cells == b.xtrf.cells); CHECK(a.xplt.cells == b.xplt.cells); CHECK(a.xval.cells == b.xval.cells); CHECK(a.xcrm.cells == b.xcrm.cells); CHECK(a.xplc.cells == b.xplc.cells); CHECK(a.xfir.cells == b.xfir.cells); CHECK(a.xpop.cells == b.xpop.cells); CHECK(a.xrog.cells == b.xrog.cells); CHECK(a.xlab == b.xlab); CHECK(a.xmic == b.xmic); CHECK(a.xthg == b.xthg); CHECK(a.xgrp == b.xgrp); CHECK(!a.xgrp.empty()); // graph history preserved verbatim // Key MISC-derived values, as a sanity cross-check. CHECK(a.funds() == b.funds()); CHECK(a.ordinances() == b.ordinances());
if (failures == 0) { std::printf("save: round-trip exact (TOKYO, %zu MISC bytes)\n", a.misc.size()); return 0; } std::printf("save: %d failure(s)\n", failures); return 1;}