Files
photocraft/crates/compose/tests/it/buffer_reuse.rs
aiongg 877e23f543 Tests: one shared lock per process-wide global in each merged test binary
The scratch pool and spill configuration, simulated free memory and the global caches are locked from tests/it/main.rs instead of a mutex per file.
2026-11-18 19:19:35 +00:00

28 lines
847 B
Rust

use photocraft_compose::Buffer;
use photocraft_geom::Rect;
use photocraft_raster::scratch;
/// Restores idle release even when an assertion fails.
struct IdleReleaseOff;
impl Drop for IdleReleaseOff {
fn drop(&mut self) {
scratch::release();
scratch::set_idle_release(true);
}
}
/// Needs its own process (nextest runs every test in one) so other compositor tests cannot consume the pooled allocation.
#[test]
fn dropped_buffer_storage_is_reused() {
scratch::set_idle_release(false);
let _idle = IdleReleaseOff;
scratch::release();
let rect = Rect::from_xywh(0, 0, 256, 256);
let buf = Buffer::transparent(rect);
let ptr = buf.px.as_ptr();
drop(buf);
let reused = Buffer::transparent(rect);
assert_eq!(reused.px.as_ptr(), ptr);
assert!(reused.px.iter().all(|p| *p == [0.0; 4]));
}