test(input): implement end-to-end IME text editing and gamepad rumble integration test
This commit is contained in:
parent
ddf37578fb
commit
c79c3c36ec
1 changed files with 29 additions and 0 deletions
29
crates/molotov-core/tests/input_haptics_test.rs
Normal file
29
crates/molotov-core/tests/input_haptics_test.rs
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
Reference in a new issue