// Loads real .SC2 cities from the user's install and checks the parse is sane. // Skips (does not fail) when the install isn't present, so the suite stays green anywhere. #include "sc2k/io/sc2_file.hpp" #include #include #include "test_paths.hpp" #include "test_harness.hpp" static const std::string kInstall = test_root(); int main() { using namespace sc2k; City resetTarget(MapSize::Large); CHECK(!io::load_sc2("/definitely/not/a/classic-city.sc2", resetTarget).ok); CHECK(resetTarget.map_size() == MapSize::Small); { // DEFAULT.SC2 is the fresh "New City". City c(MapSize::Large); auto r = io::load_sc2(std::string(kInstall) + "/DEFAULT.SC2", c); if (!r.ok) { std::printf("sc2_load: skipped (%s)\n", r.error.c_str()); return 0; } std::printf(" DEFAULT.SC2: name=\"%s\" funds=%d startYear=%d diff=%d\n", c.name.c_str(), c.funds(), c.start_year(), c.difficulty()); CHECK(c.name == "New City"); CHECK(c.funds() == 20000); // verified easy-difficulty new-game seed CHECK(c.start_year() == 1900); CHECK(c.difficulty() == 1); CHECK(c.map_size() == MapSize::Small); } { // A built city should have a non-empty name and some developed land. City c; auto r = io::load_sc2(std::string(kInstall) + "/CITIES/BAYVIEW.SC2", c); if (r.ok) { int built = 0; for (auto b : c.xbld.cells) if (b) ++built; std::printf(" BAYVIEW.SC2: name=\"%s\" funds=%d founded=%d builtTiles=%d\n", c.name.c_str(), c.funds(), c.start_year(), built); // Cross-validated against src/sc2k_parse.py: Founded 2050, funds $216,864. CHECK(c.name == "Bay View"); CHECK(c.funds() == 216864); CHECK(c.start_year() == 2050); CHECK(built > 100); // a real city has plenty of non-empty XBLD tiles } } if (failures == 0) { std::printf("sc2_load: all checks passed\n"); return 0; } std::printf("sc2_load: %d failure(s)\n", failures); return 1; }