From b45edcd4fe673b2c622b4a30094851285974ca62 Mon Sep 17 00:00:00 2001 From: Dorota Czaplejewicz Date: Wed, 9 Oct 2019 15:54:06 +0000 Subject: [PATCH] tests: Emulate clicking all submitting buttons --- examples/test_layout.rs | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/examples/test_layout.rs b/examples/test_layout.rs index 95659545..b8fe0a1b 100644 --- a/examples/test_layout.rs +++ b/examples/test_layout.rs @@ -14,14 +14,37 @@ fn check_layout(name: &str) { .expect("layout broken"); let context = xkb::Context::new(xkb::CONTEXT_NO_FLAGS); - xkb::Keymap::new_from_string( + + let keymap_str = layout.keymap_str + .clone() + .into_string().expect("Failed to decode keymap string"); + + let keymap = xkb::Keymap::new_from_string( &context, - layout.keymap_str - .clone() - .into_string().expect("Failed to decode keymap string"), + keymap_str.clone(), xkb::KEYMAP_FORMAT_TEXT_V1, xkb::KEYMAP_COMPILE_NO_FLAGS, ).expect("Failed to create keymap"); + + let state = xkb::State::new(&keymap); + + // "Press" each button with keysyms + for view in layout.views.values() { + for row in &view.rows { + for button in &row.buttons { + let keystate = button.state.borrow(); + for keycode in &keystate.keycodes { + match state.key_get_one_sym(*keycode) { + xkb::KEY_NoSymbol => { + eprintln!("{}", keymap_str); + panic!("Keysym {} on key {:?} can't be resolved", keycode, button.name); + }, + _ => {}, + } + } + } + } + } } fn main() -> () {