diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2023-09-27 13:35:02 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2023-09-27 13:35:02 +0400 |
| commit | 31ea816d2b5cf9407f8291186e85060578251054 (patch) | |
| tree | 824973f83bf2652a0af0003005052bb8a6af1600 /src | |
| parent | f2e28f54d66bf9fff0690f366a0bbca14be6c182 (diff) | |
| download | niri-31ea816d2b5cf9407f8291186e85060578251054.tar.gz niri-31ea816d2b5cf9407f8291186e85060578251054.tar.bz2 niri-31ea816d2b5cf9407f8291186e85060578251054.zip | |
layout: Add randomized test
Diffstat (limited to 'src')
| -rw-r--r-- | src/layout.rs | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/src/layout.rs b/src/layout.rs index 31a773f1..a501c401 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -2332,6 +2332,8 @@ mod tests { use std::cell::Cell; use std::rc::Rc; + use proptest::prelude::*; + use proptest_derive::Arbitrary; use smithay::output::{Mode, PhysicalProperties, Subpixel}; use smithay::utils::IsAlive; @@ -2422,17 +2424,27 @@ mod tests { } } - #[derive(Debug, Clone, Copy)] + fn arbitrary_bbox() -> impl Strategy<Value = Rectangle<i32, Logical>> { + any::<(i16, i16, u16, u16)>().prop_map(|(x, y, w, h)| { + let loc: Point<i32, _> = Point::from((x.into(), y.into())); + let size: Size<i32, _> = Size::from((w.into(), h.into())); + Rectangle::from_loc_and_size(loc, size) + }) + } + + #[derive(Debug, Clone, Copy, Arbitrary)] enum Op { - AddOutput(usize), - RemoveOutput(usize), - FocusOutput(usize), + AddOutput(#[proptest(strategy = "1..=5usize")] usize), + RemoveOutput(#[proptest(strategy = "1..=5usize")] usize), + FocusOutput(#[proptest(strategy = "1..=5usize")] usize), AddWindow { + #[proptest(strategy = "1..=5usize")] id: usize, + #[proptest(strategy = "arbitrary_bbox()")] bbox: Rectangle<i32, Logical>, activate: bool, }, - CloseWindow(usize), + CloseWindow(#[proptest(strategy = "1..=5usize")] usize), FocusColumnLeft, FocusColumnRight, MoveColumnLeft, @@ -2441,10 +2453,10 @@ mod tests { ExpelWindowFromColumn, FocusWorkspaceDown, FocusWorkspaceUp, - FocusWorkspace(u8), + FocusWorkspace(#[proptest(strategy = "1..=5u8")] u8), MoveWindowToWorkspaceDown, MoveWindowToWorkspaceUp, - MoveWindowToWorkspace(u8), + MoveWindowToWorkspace(#[proptest(strategy = "1..=5u8")] u8), } impl Op { @@ -2632,4 +2644,22 @@ mod tests { check_ops(&ops); } + + proptest! { + #![proptest_config(ProptestConfig { + cases: if std::env::var_os("RUN_SLOW_TESTS").is_none() { + eprintln!("ignoring slow test"); + 0 + } else { + ProptestConfig::default().cases + }, + ..ProptestConfig::default() + })] + + #[test] + fn random_operations_dont_panic(ops: Vec<Op>) { + // eprintln!("{ops:?}"); + check_ops(&ops); + } + } } |
