#[cfg(test)]
mod grab_tests {
use std::{thread, time::Duration};
use raw_input::{Core, Display, Event, Grab, Point, Simulate};
fn start_core() {
thread::spawn(|| {
let _ = Core::start();
});
thread::sleep(Duration::from_millis(500));
}
fn stop_core() {
Grab::stop();
Core::stop();
thread::sleep(Duration::from_millis(300));
}
#[test]
fn test_grab_simulate_move_interception() {
start_core();
Grab::stop();
let initial_pos = Display::get_cursor_pos_physical();
Grab::start();
Simulate::simulate(Event::MouseMove {
delta: Point { x: 100, y: 100 },
});
thread::sleep(Duration::from_millis(200));
let current_pos = Display::get_cursor_pos_physical();
assert_eq!(
initial_pos, current_pos,
"Simulate::simulate move should be blocked by Grab"
);
stop_core();
}
#[test]
fn test_grab_mouse_move_interception() {
start_core();
Grab::stop();
let initial_pos = Display::get_cursor_pos_physical();
Grab::mouse_move(true);
Grab::resume();
Simulate::mouse_move(50, 50);
thread::sleep(Duration::from_millis(200));
let current_pos = Display::get_cursor_pos_physical();
assert_eq!(
initial_pos, current_pos,
"Simulate::mouse_move should be blocked by Grab"
);
stop_core();
}
#[test]
fn test_grab_mouse_move_to_interception() {
start_core();
Grab::stop();
let initial_pos = Display::get_cursor_pos_physical();
Grab::start();
let target_x = initial_pos.0 + 100;
let target_y = initial_pos.1 + 100;
Simulate::mouse_move_to(target_x, target_y);
thread::sleep(Duration::from_millis(200));
let current_pos = Display::get_cursor_pos_physical();
assert_eq!(
initial_pos, current_pos,
"Simulate::mouse_move_to should be blocked by Grab"
);
stop_core();
}
}