mirror of
https://github.com/RetroPortingToolKit/psxrecomp
synced 2026-10-26 10:19:47 -04:00
98763d922f
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
43 lines
1.8 KiB
C++
43 lines
1.8 KiB
C++
#include "projection_scale_config.hpp"
|
|
#include "projection_scale.hpp"
|
|
#include <chrono>
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
#include <cstdio>
|
|
#include <string>
|
|
|
|
int main() {
|
|
const auto file = std::filesystem::temp_directory_path() /
|
|
("psx-projection-" + std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()) + ".toml");
|
|
struct Cleanup {
|
|
std::filesystem::path path;
|
|
~Cleanup() { std::error_code ec; std::filesystem::remove(path, ec); }
|
|
} cleanup{file};
|
|
auto load = [&](const char* text) {
|
|
{ std::ofstream out(file); out << text; }
|
|
return psx_projection_scale_load_config(file);
|
|
};
|
|
if (load("[game]\nname='fixture'\n") != 1.0 ||
|
|
load("[video]\naspect='4:3'\n") != 1.0 ||
|
|
load("[video]\nfov_scale=1.0\n") != 1.0 ||
|
|
load("[video]\nfov_scale=2.0\n") != 2.0 ||
|
|
load("[video]\nfov_scale=8.0\n") != 8.0) return 1;
|
|
/* Integer TOML values are accepted. */
|
|
if (load("[video]\nfov_scale=2\n") != 2.0 ||
|
|
load("[video]\nfov_scale=1\n") != 1.0 ||
|
|
load("[video]\nfov_scale=8\n") != 8.0) {
|
|
std::fprintf(stderr, "integer fov_scale not accepted\n");
|
|
return 1;
|
|
}
|
|
/* Bad values must not throw (a throw would stop the game starting): they
|
|
* warn on stderr and fall back to 1.0. */
|
|
for (const char* value : {"0.0", "0", "-1.0", "9.0", "9", "nan", "inf", "'wide'", "true", "[1.0]"}) {
|
|
const std::string text = std::string("[video]\nfov_scale=") + value + "\n";
|
|
double got = -1.0;
|
|
try { got = load(text.c_str()); }
|
|
catch (...) { std::fprintf(stderr, "threw on invalid scale %s\n", value); return 1; }
|
|
if (got != 1.0) { std::fprintf(stderr, "invalid scale %s gave %g\n", value, got); return 1; }
|
|
}
|
|
return 0;
|
|
}
|