From a2767041d990fa3d5512627fe757a091e02fa17c Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Tue, 12 Aug 2025 22:34:13 +0300 Subject: layout/tests: Support forced test window size --- src/layout/tests.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/layout') diff --git a/src/layout/tests.rs b/src/layout/tests.rs index ae7a16c6..4275d111 100644 --- a/src/layout/tests.rs +++ b/src/layout/tests.rs @@ -24,6 +24,8 @@ struct TestWindowInner { bbox: Cell>, initial_bbox: Rectangle, requested_size: Cell>>, + // Emulates the window ignoring the compositor-provided size. + forced_size: Cell>>, min_size: Size, max_size: Size, pending_fullscreen: Cell, @@ -71,6 +73,7 @@ impl TestWindow { bbox: Cell::new(params.bbox), initial_bbox: params.bbox, requested_size: Cell::new(None), + forced_size: Cell::new(None), min_size: params.min_max_size.0, max_size: params.min_max_size.1, pending_fullscreen: Cell::new(false), @@ -86,7 +89,8 @@ impl TestWindow { fn communicate(&self) -> bool { let mut changed = false; - if let Some(size) = self.0.requested_size.get() { + let size = self.0.forced_size.get().or(self.0.requested_size.get()); + if let Some(size) = size { assert!(size.w >= 0); assert!(size.h >= 0); @@ -284,6 +288,10 @@ impl LayoutElement for TestWindow { } } +fn arbitrary_size() -> impl Strategy> { + any::<(u16, u16)>().prop_map(|(w, h)| Size::from((w.max(1).into(), h.max(1).into()))) +} + fn arbitrary_bbox() -> impl Strategy> { any::<(i16, i16, u16, u16)>().prop_map(|(x, y, w, h)| { let loc: Point = Point::from((x.into(), y.into())); @@ -592,6 +600,12 @@ enum Op { #[proptest(strategy = "prop::option::of(1..=5usize)")] new_parent_id: Option, }, + SetForcedSize { + #[proptest(strategy = "1..=5usize")] + id: usize, + #[proptest(strategy = "proptest::option::of(arbitrary_size())")] + size: Option>, + }, Communicate(#[proptest(strategy = "1..=5usize")] usize), Refresh { is_active: bool, @@ -1315,6 +1329,14 @@ impl Op { } } } + Op::SetForcedSize { id, size } => { + for (_mon, win) in layout.windows() { + if win.0.id == id { + win.0.forced_size.set(size); + return; + } + } + } Op::Communicate(id) => { let mut update = false; -- cgit