diff --git a/crates/molotov-core/tests/input_haptics_test.rs b/crates/molotov-core/tests/input_haptics_test.rs new file mode 100644 index 0000000..3dbfced --- /dev/null +++ b/crates/molotov-core/tests/input_haptics_test.rs @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +use molotov_core::input::gamepad::{translate_button_to_android, AndroidKeyCode, GamepadButton, GamepadType}; +use molotov_core::input::ime::Rect; +use molotov_core::input::manager::InputManager; + +#[test] +fn test_end_to_end_ime_and_gamepad_rumble() { + let mut manager = InputManager::new(); + + // 1. Text Chat IME Preedit flow + manager.ime.start_text_input(Rect { x: 50, y: 100, width: 300, height: 30 }); + manager.ime.update_preedit("nihao", 5); + assert_eq!(manager.ime.preedit_text(), "nihao"); + + let committed = manager.ime.commit_text("你好"); + assert_eq!(committed, "你好"); + assert_eq!(manager.ime.preedit_text(), ""); + + // 2. Controller Input Translation + let key = translate_button_to_android(GamepadButton::South, GamepadType::Xbox); + assert_eq!(key, AndroidKeyCode::ButtonA); + + // 3. Controller Haptic Actuation + manager.haptics.rumble(0, 0.75, 0.25, 150); + let state = manager.haptics.get_state(0).unwrap(); + assert_eq!(state.low_freq_motor, (0.75 * 65535.0) as u16); + assert_eq!(state.high_freq_motor, (0.25 * 65535.0) as u16); + assert_eq!(state.duration_ms, 150); +}