Files
photocraft/crates/engine/tests/it/path_blur_speed_clamp.rs
T
aiongg a6428d3dfb Build each crate's integration tests as one binary
Every tests/*.rs file is its own executable that links the whole crate
graph. Move each crate's test files into tests/it/ as modules of one
tests/it/main.rs; helper modules under tests/common move with them.

These keep their own binary (own process):
- engine panic_hunt: a process-wide panic hook counts every panic.
- engine text_gamma: changes the process-wide text gamma.
- engine smart_filter_stages, mask_cache_purge: assert on global caches.
- codecs pnm_peak_memory: reads the process's peak RSS.
- photocraft mac_menu_appkit: harness = false.
2026-10-22 16:55:34 +00:00

38 lines
1.7 KiB
Rust

//! Regression tests for issue #708: `filter.blurGallery.pathBlur` clamps the
//! scalar `speed`, but each entry of the documented `paths` array is
//! deserialized without a clamp. A huge finite speed saturates the
//! float-to-i32 cast in the halo and the `+ 1` overflows, which the dispatch
//! turns into an internal-error panic. The command must clamp like the scalar
//! path does and blur normally.
use photocraft_engine::Session;
use serde_json::json;
fn path_blur(speed: f64) -> Result<serde_json::Value, photocraft_engine::EngineError> {
let mut s = Session::new();
s.execute("file.new", json!({"width": 16, "height": 16, "background": "#808080"})).unwrap();
s.execute("filter.blurGallery.pathBlur", json!({"paths": [{"points": [[0.2, 0.5], [0.8, 0.5]], "speed": speed}]}))
}
#[test]
fn path_blur_huge_entry_speed_does_not_panic() {
// On main this comes back as a caught panic ("internal error" style)
// from overflow in the halo radius. After the clamp it must succeed.
let r = path_blur(1.0e20);
assert!(r.is_ok(), "huge entry speed must clamp, got error: {r:?}");
}
#[test]
fn path_blur_negative_entry_speed_does_not_panic() {
let r = path_blur(-1.0e20);
assert!(r.is_ok(), "huge negative entry speed must clamp, got error: {r:?}");
}
#[test]
fn path_blur_normal_entry_speed_still_blurs() {
// Control: a documented in-range speed keeps working.
let mut s = Session::new();
s.execute("file.new", json!({"width": 16, "height": 16, "background": "#808080"})).unwrap();
s.execute("filter.blurGallery.pathBlur", json!({"paths": [{"points": [[0.2, 0.5], [0.8, 0.5]], "speed": 120.0}]})).expect("in-range speed must succeed");
}