mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
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.
28 lines
847 B
Rust
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]));
|
|
}
|