Skip to content

Commit f7d2f71

Browse files
committed
fix: use Seize input for Win32 relative_move binding test
1 parent 37af161 commit f7d2f71

1 file changed

Lines changed: 39 additions & 37 deletions

File tree

maa-framework/tests/binding_test.rs

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,53 +1178,55 @@ fn test_win32_relative_move() {
11781178
return;
11791179
}
11801180

1181-
let mut controller = None;
1182-
let mut target_window = None;
1181+
let mut preferred_windows = desktop_windows;
1182+
preferred_windows.sort_by_key(|window| window.window_name.is_empty());
11831183

1184-
for window in desktop_windows {
1185-
match Controller::new_win32(
1184+
let mut target_window_name = None;
1185+
let mut ret = false;
1186+
1187+
for window in preferred_windows {
1188+
let controller = match Controller::new_win32(
11861189
window.hwnd as *mut c_void,
11871190
sys::MaaWin32ScreencapMethod_GDI as sys::MaaWin32ScreencapMethod,
1188-
sys::MaaWin32InputMethod_SendMessage as sys::MaaWin32InputMethod,
1189-
sys::MaaWin32InputMethod_SendMessage as sys::MaaWin32InputMethod,
1191+
sys::MaaWin32InputMethod_Seize as sys::MaaWin32InputMethod,
1192+
sys::MaaWin32InputMethod_Seize as sys::MaaWin32InputMethod,
11901193
) {
1191-
Ok(ctrl) => {
1192-
controller = Some(ctrl);
1193-
target_window = Some(window);
1194-
break;
1195-
}
1194+
Ok(ctrl) => ctrl,
11961195
Err(_) => continue,
1197-
}
1198-
}
1199-
1200-
let (controller, target_window) = match (controller, target_window) {
1201-
(Some(controller), Some(target_window)) => (controller, target_window),
1202-
_ => {
1203-
println!(" SKIP: failed to create Win32 controller");
1204-
return;
1205-
}
1206-
};
1196+
};
12071197

1208-
let ret = controller
1209-
.post_connection()
1210-
.map(|id| controller.wait(id).succeeded())
1211-
.unwrap_or(false)
1212-
&& controller
1213-
.post_relative_move(0, 0)
1198+
let current_ret = controller
1199+
.post_connection()
12141200
.map(|id| controller.wait(id).succeeded())
1215-
.unwrap_or(false);
1201+
.unwrap_or(false)
1202+
&& controller
1203+
.post_relative_move(0, 0)
1204+
.map(|id| controller.wait(id).succeeded())
1205+
.unwrap_or(false);
1206+
1207+
let window_name = if window.window_name.is_empty() {
1208+
"(no name)".to_string()
1209+
} else if window.window_name.len() > 30 {
1210+
window.window_name[..30].to_string()
1211+
} else {
1212+
window.window_name.clone()
1213+
};
12161214

1217-
let window_name = if target_window.window_name.is_empty() {
1218-
"(no name)"
1219-
} else if target_window.window_name.len() > 30 {
1220-
&target_window.window_name[..30]
1221-
} else {
1222-
&target_window.window_name
1223-
};
1215+
println!(" try target window: {} -> {}", window_name, current_ret);
12241216

1225-
println!(" target window: {}", window_name);
1217+
if current_ret {
1218+
target_window_name = Some(window_name);
1219+
ret = true;
1220+
break;
1221+
}
1222+
}
1223+
1224+
println!(
1225+
" target window: {}",
1226+
target_window_name.as_deref().unwrap_or("(none)")
1227+
);
12261228
println!(" ret: {}", ret);
1227-
assert!(ret, "win32 relative_move should succeed");
1229+
assert!(ret, "win32 relative_move should succeed with Seize input");
12281230
println!(" PASS: win32 relative_move");
12291231
}
12301232

0 commit comments

Comments
 (0)