#![cfg(feature = "theme")]
use oxiui_render_soft::{Framebuffer, ShadowSpec, SoftBackend};
#[test]
fn test_shadow_spec_new_fields() {
let spec = ShadowSpec::new(3.0, 4.0, 5.0, [10, 20, 30, 200]);
assert!((spec.offset_x - 3.0).abs() < f32::EPSILON);
assert!((spec.offset_y - 4.0).abs() < f32::EPSILON);
assert!((spec.blur - 5.0).abs() < f32::EPSILON);
assert_eq!(spec.color.0, 10);
assert_eq!(spec.color.1, 20);
assert_eq!(spec.color.2, 30);
assert_eq!(spec.color.3, 200);
}
#[test]
fn test_shadow_spec_drop_shadow() {
let spec = ShadowSpec::drop_shadow(2.0, 3.0, 6.0);
assert!((spec.offset_x - 2.0).abs() < f32::EPSILON);
assert!((spec.offset_y - 3.0).abs() < f32::EPSILON);
assert!((spec.blur - 6.0).abs() < f32::EPSILON);
assert!(!spec.is_invisible(), "drop_shadow must have non-zero alpha");
assert!(!spec.inset);
}
#[test]
fn test_shadow_spec_inset_flag() {
let spec = ShadowSpec::drop_shadow(0.0, 2.0, 4.0).with_inset(true);
assert!(spec.inset, "inset flag must be true after with_inset(true)");
}
#[test]
fn test_shadow_spec_with_spread() {
let spec = ShadowSpec::drop_shadow(0.0, 0.0, 2.0).with_spread(5.0);
assert!((spec.spread - 5.0).abs() < f32::EPSILON);
}
#[test]
fn test_elevation_to_shadow_zero() {
use oxiui_theme::elevation_to_shadow;
let s = elevation_to_shadow(0.0);
assert!(s.is_invisible(), "elevation 0 must be invisible");
}
#[test]
fn test_elevation_to_shadow_positive() {
use oxiui_theme::elevation_to_shadow;
let s = elevation_to_shadow(4.0);
assert!(
s.blur > 0.0,
"elevation 4 must produce blur > 0, got {}",
s.blur
);
}
#[test]
fn test_apply_shadow_spec_deposits_pixels() {
let mut backend = SoftBackend::new(100, 100);
let spec = ShadowSpec::new(0.0, 0.0, 3.0, [0, 0, 0, 200]);
backend.apply_shadow_spec((20.0, 20.0, 40.0, 40.0), &spec);
let fb: &Framebuffer = backend.frame();
let mut found_shadow = false;
for y in 17u32..63 {
for x in 17u32..63 {
if let Some((_r, _g, _b, a)) = fb.get_rgba(x, y) {
if a > 0 {
found_shadow = true;
}
}
}
}
assert!(
found_shadow,
"apply_shadow_spec must deposit at least one non-transparent pixel"
);
}
#[test]
fn test_apply_shadow_spec_spread_inflates() {
let mut backend_spread = SoftBackend::new(100, 100);
let spec_spread = ShadowSpec::new(0.0, 0.0, 0.0, [0, 0, 0, 255]).with_spread(5.0);
backend_spread.apply_shadow_spec((50.0, 50.0, 10.0, 10.0), &spec_spread);
let has_pixel = backend_spread
.frame()
.get_rgba(47, 47)
.map(|(_, _, _, a)| a > 0)
.unwrap_or(false);
assert!(has_pixel, "spread shadow must reach inflated region");
}