[raster] Toolbox: probe/decode with caps, convert, crop, rotate, resize, presets, compress to size, HEIC via WIC
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
//! HEIC/HEIF goes through the OS codec. These tests only demand clean, typed outcomes.
|
||||
|
||||
mod common;
|
||||
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use common::minimal_heic;
|
||||
use pictor_raster::{HeifSupport, Limits, RasterError, decode, heif_support};
|
||||
|
||||
#[test]
|
||||
fn heif_support_returns() {
|
||||
let start = Instant::now();
|
||||
let s = heif_support();
|
||||
eprintln!("heif_support() = {s:?} in {:?}", start.elapsed());
|
||||
#[cfg(not(windows))]
|
||||
assert_eq!(s, HeifSupport::Unavailable);
|
||||
#[cfg(windows)]
|
||||
assert_ne!(s, HeifSupport::Unavailable);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn minimal_heic_gives_a_typed_error() {
|
||||
let bytes = minimal_heic(64, 64);
|
||||
let start = Instant::now();
|
||||
let result = decode(&bytes, &Limits::default());
|
||||
let took = start.elapsed();
|
||||
eprintln!("decode(minimal heic) = {:?} in {took:?}", result.as_ref().map(|i| (i.width(), i.height())));
|
||||
assert!(took < Duration::from_secs(20), "took {took:?}");
|
||||
let err = result.expect_err("the payload is not real HEVC");
|
||||
match &err {
|
||||
RasterError::HeifCodecMissing { .. } => {
|
||||
assert!(err.to_string().contains("9NMZLZ57R3T7"), "{err}");
|
||||
}
|
||||
RasterError::Corrupt { .. } | RasterError::Os { .. } => {
|
||||
// A machine with every codec installed rejects the dummy HEVC payload instead.
|
||||
assert_eq!(heif_support(), HeifSupport::Ready, "{err:?}");
|
||||
}
|
||||
other => panic!("unexpected {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn heic_bomb_is_refused_before_the_os_codec() {
|
||||
let bytes = minimal_heic(100_000, 100_000);
|
||||
let err = decode(&bytes, &Limits::default()).unwrap_err();
|
||||
assert!(matches!(err, RasterError::TooManyPixels { width: 100_000, height: 100_000 }), "{err:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn truncated_heic_does_not_hang_or_panic() {
|
||||
let bytes = minimal_heic(64, 64);
|
||||
for cut in [12, 24, 40, bytes.len() / 2, bytes.len() - 3] {
|
||||
let start = Instant::now();
|
||||
let r = decode(&bytes[..cut], &Limits::default());
|
||||
assert!(r.is_err());
|
||||
assert!(start.elapsed() < Duration::from_secs(20));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user