// tests/test_paths.hpp — locate the SC2K install that data-driven tests read reference cities from. // Honours SC2K_DATA_DIR, else finds original-cd/WIN95/SC2K above cwd (see render/asset_loader.hpp). // Tests that need a real city skip gracefully when the install is absent. #pragma once #include #include #include #include "sc2k/render/asset_loader.hpp" // Does a file exist / is it readable? Two dozen data-driven tests each carried a private copy of this // (open an ifstream, report good()); it lives here now. Used to gate asset/city presence before a test // that needs the install, so the test skips cleanly when a file is missing. inline bool exists(const std::string& p) { std::ifstream f(p); return f.good(); } inline std::string test_root() { return sc2k::render::sc2k_root(); } // The bundled reference cities live in /CITIES. These two build the paths every data-driven // test used to spell out by hand (`test_root() + "/CITIES/NAME.SC2"`), so the join lives in one place // and tests stop reaching past the harness to render::sc2k_root() directly. When no install is found // test_root() is empty, the path won't resolve, and the caller's own load-failed guard skips the test. inline std::string cities_dir() { return test_root() + "/CITIES/"; } inline std::string city_file(const std::string& name) { return cities_dir() + name; } // The scenario (.SCN) cities live alongside CITIES in /SCENARIO. inline std::string scenario_dir() { return test_root() + "/SCENARIO/"; } // "Pick whichever well-known reference city is installed" — several render/geometry tests aren't tied // to one city, they just need any real terrain; each spelled out its own candidate loop. Returns the // path of the first present city from `names` (base names like "TOKYO.SC2"), or "" when none is found // (the caller then skips). Order in the list is the preference order. inline std::string first_present_city(std::initializer_list names) { for (const char* n : names) { std::string p = city_file(n); if (exists(p)) return p; } return ""; } // Are the extracted render assets present? The sprite-drawing tests gate on representative close PNGs // (which carry the embedded master palette) before composing a frame; when either is missing they skip // with a "run extract_assets.py" note. Kept here so that gate reads the same everywhere. inline bool have_render_assets() { return exists(sc2k::render::classic_asset_path("sprites/sprite_1001.pal.png")) && exists(sc2k::render::classic_asset_path("sprites/sprite_1256.pal.png")); } // The CD image root (for the WIN31/DOS city variants) — the layout above the WIN95 install. inline std::string original_cd_root() { const std::string d = sc2k::render::find_upwards("original-cd", "WIN95"); return d.empty() ? std::string("original-cd") : d; }