#![allow(clippy::unwrap_used)]
mod fixtures;
use ff_encode::SpriteSheet;
fn test_video_path() -> std::path::PathBuf {
let manifest_dir = env!("CARGO_MANIFEST_DIR");
std::path::PathBuf::from(format!("{manifest_dir}/../../assets/video/gameplay.mp4"))
}
fn read_file_prefix(path: &std::path::Path, n: usize) -> std::io::Result<Vec<u8>> {
use std::io::Read as _;
let mut buf = vec![0u8; n];
let mut f = std::fs::File::open(path)?;
f.read_exact(&mut buf)?;
Ok(buf)
}
#[test]
fn sprite_sheet_should_produce_correct_pixel_dimensions() {
let input = test_video_path();
if !input.exists() {
println!("Skipping: test video not found at {}", input.display());
return;
}
let output = fixtures::test_output_path("preview_sprite_sheet_dimensions.png");
let _guard = fixtures::FileGuard::new(output.clone());
let result = SpriteSheet::new(&input)
.cols(5)
.rows(4)
.frame_width(160)
.frame_height(90)
.output(&output)
.run();
match result {
Ok(()) => {}
Err(e) => {
println!("Skipping: SpriteSheet::run failed ({e})");
return;
}
}
let header = read_file_prefix(&output, 24).expect("output file must be readable");
assert_eq!(
&header[0..4],
b"\x89PNG",
"output file does not begin with PNG magic bytes"
);
let width = u32::from_be_bytes(header[16..20].try_into().unwrap());
let height = u32::from_be_bytes(header[20..24].try_into().unwrap());
assert_eq!(
width, 800,
"expected PNG width 800 (5 cols × 160 px), got {width}"
);
assert_eq!(
height, 360,
"expected PNG height 360 (4 rows × 90 px), got {height}"
);
}