102 lines
4.2 KiB
Rust
102 lines
4.2 KiB
Rust
//! Golden tests against the designer's sample outputs in docs/examples/.
|
|||
|
|
|
||
|
|
use sfzenith_core::hrz::{export_hrz, parse_hrz, HrzOptions};
|
||
|
|
use sfzenith_core::session::{parse_sensors, Session};
|
||
|
|
use sfzenith_core::stellarium::{
|
||
|
|
export_polygonal, export_spherical, horizon_txt, polygonal_ini, spherical_ini, LandscapeMeta,
|
||
|
|
Location, PanoramaBand, SphericalOptions,
|
||
|
|
};
|
||
|
|
use sfzenith_core::zip::zip;
|
||
|
|
use std::path::PathBuf;
|
||
|
|
|
||
|
|
fn example(rel: &str) -> String {
|
||
|
|
let p = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../docs/examples").join(rel);
|
||
|
|
std::fs::read_to_string(&p).unwrap_or_else(|e| panic!("{}: {e}", p.display()))
|
||
|
|
}
|
||
|
|
|
||
|
|
fn meta() -> LandscapeMeta {
|
||
|
|
LandscapeMeta {
|
||
|
|
name: "Backyard pier".into(),
|
||
|
|
author: "[AUTHOR]".into(),
|
||
|
|
app_name: "[APP NAME]".into(),
|
||
|
|
location: Some(Location { lat_deg: 47.4979, lon_deg: 19.0402, elev_m: Some(112.0) }),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn hrz_matches_example() {
|
||
|
|
// horizon.txt is the plain edge; the NINA file is the same edge + 2°.
|
||
|
|
let edge = parse_hrz(&example("stellarium-spherical/horizon.txt")).unwrap();
|
||
|
|
let hrz = export_hrz(&edge, HrzOptions::default());
|
||
|
|
assert_eq!(hrz, example("nina/backyard-pier.hrz"));
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn horizon_txt_matches_example() {
|
||
|
|
let text = example("stellarium-spherical/horizon.txt");
|
||
|
|
let edge = parse_hrz(&text).unwrap();
|
||
|
|
assert_eq!(horizon_txt(&edge, "Backyard pier"), text);
|
||
|
|
assert_eq!(example("stellarium-polygonal/horizon.txt"), text);
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn landscape_inis_match_examples() {
|
||
|
|
assert_eq!(spherical_ini(&meta(), 42.0, -22.0), example("stellarium-spherical/landscape.ini"));
|
||
|
|
assert_eq!(polygonal_ini(&meta()), example("stellarium-polygonal/landscape.ini"));
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn polygonal_export_layout() {
|
||
|
|
let edge = parse_hrz(&example("stellarium-polygonal/horizon.txt")).unwrap();
|
||
|
|
let files = export_polygonal(&edge, &meta(), 0.0);
|
||
|
|
let names: Vec<&str> = files.iter().map(|f| f.0.as_str()).collect();
|
||
|
|
assert_eq!(names, ["backyard_pier_outline/landscape.ini", "backyard_pier_outline/horizon.txt"]);
|
||
|
|
assert_eq!(files[1].1, example("stellarium-polygonal/horizon.txt").into_bytes());
|
||
|
|
let z = zip(&files);
|
||
|
|
assert_eq!(z, zip(&export_polygonal(&edge, &meta(), 0.0)), "zip must be byte-stable");
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn spherical_export_layout() {
|
||
|
|
let edge = parse_hrz(&example("stellarium-spherical/horizon.txt")).unwrap();
|
||
|
|
let (w, h) = (360u32, 120u32);
|
||
|
|
let px = vec![128u8; (w * h * 4) as usize];
|
||
|
|
let band = PanoramaBand { rgba: &px, width: w, height: h, top_deg: 90.0, bottom_deg: -30.0, sky_mask: None };
|
||
|
|
let opts = SphericalOptions { width_px: 512, height_px: 128, ..SphericalOptions::default() };
|
||
|
|
let files = export_spherical(&band, &edge, &meta(), &opts).unwrap();
|
||
|
|
let names: Vec<&str> = files.iter().map(|f| f.0.as_str()).collect();
|
||
|
|
assert_eq!(
|
||
|
|
names,
|
||
|
|
["backyard_pier/landscape.ini", "backyard_pier/panorama.png", "backyard_pier/horizon.txt"]
|
||
|
|
);
|
||
|
|
assert_eq!(files[0].1, example("stellarium-spherical/landscape.ini").into_bytes());
|
||
|
|
assert_eq!(&files[1].1[1..4], b"PNG");
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn fitted_band_tracks_the_profile() {
|
||
|
|
let edge = parse_hrz(&example("stellarium-spherical/horizon.txt")).unwrap();
|
||
|
|
let o = SphericalOptions::fitted(&edge, -30.0);
|
||
|
|
assert_eq!((o.top_deg, o.bottom_deg), (31.0, -30.0)); // max edge 26.0 + 5
|
||
|
|
assert_eq!((o.width_px, o.height_px), (8192, 2048));
|
||
|
|
}
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
fn session_example_roundtrips() {
|
||
|
|
let text = example("session/session.json");
|
||
|
|
let s = Session::from_json(&text).unwrap();
|
||
|
|
assert_eq!(s.site.name, "Backyard pier");
|
||
|
|
assert_eq!(s.frames.len(), 2);
|
||
|
|
assert_eq!(s.device.camera.fov_source, "assumed");
|
||
|
|
assert_eq!(Session::from_json(&s.to_json()).unwrap(), s);
|
||
|
|
// Every top-level key of the example survives a save.
|
||
|
|
let a: serde_json::Value = serde_json::from_str(&text).unwrap();
|
||
|
|
let b: serde_json::Value = serde_json::from_str(&s.to_json()).unwrap();
|
||
|
|
let keys = |v: &serde_json::Value| v.as_object().unwrap().keys().cloned().collect::<Vec<_>>();
|
||
|
|
assert_eq!(keys(&a), keys(&b));
|
||
|
|
|
||
|
|
let sensors = parse_sensors(&example("session/sensors.jsonl")).unwrap();
|
||
|
|
assert_eq!(sensors.len(), 2);
|
||
|
|
assert_eq!(sensors[1].mag_heading_deg, Some(354.5));
|
||
|
|
}
|