test(wm): transfer window to nonexistent monitor

Created a test for the transfer_window function.

The tests attempts to transfer a window to a monitor that doesn't exist,
and checks to see if we return an error. The test successfully gets an
error but there is a bug where the window isn't in the contiainer after
a failed transfer. I wrote a note comment to explain the bug just in
case we need to reference back to it.
This commit is contained in:
Jerry Kingsbury
2025-05-08 16:55:24 -05:00
committed by LGUG2Z
parent 76c833f661
commit 80bb7288c4

View File

@@ -4471,6 +4471,64 @@ mod tests {
}
}
#[test]
fn test_transfer_window_to_nonexistent_monitor() {
// NOTE: transfer_window is primarily used when a window is being dragged by a mouse. The
// transfer_window function does return an error when the target monitor doesn't exist but
// there is a bug where the window isn't in the container after the window fails to
// transfer. The test will test for the result of the transfer_window function but not if
// the window is in the container after the transfer fails.
let (mut wm, _context) = setup_window_manager();
{
// Create a first monitor
let mut m = monitor::new(
0,
Rect::default(),
Rect::default(),
"TestMonitor".to_string(),
"TestDevice".to_string(),
"TestDeviceID".to_string(),
Some("TestMonitorID".to_string()),
);
// Create a container
let workspace = m.focused_workspace_mut().unwrap();
let mut container = Container::default();
// Add a window to the container
container.windows_mut().push_back(Window::from(0));
workspace.add_container_to_back(container);
// Should contain 1 container
assert_eq!(workspace.containers().len(), 1);
wm.monitors_mut().push_back(m);
}
{
// Monitor 0, Workspace 0, Window 0
let origin = (0, 0, 0);
// Monitor 1, Workspace 0, Window 0
//
let target = (1, 0, 0);
// Attempt to transfer the window from monitor 0 to a non-existent monitor
let result = wm.transfer_window(origin, target);
// Result should be an error since the monitor doesn't exist
assert!(
result.is_err(),
"Expected an error when transferring to a non-existent monitor"
);
assert_eq!(wm.focused_container_idx().unwrap(), 0);
assert_eq!(wm.focused_workspace_idx().unwrap(), 0);
}
}
#[test]
fn test_transfer_container() {
let (mut wm, _context) = setup_window_manager();