()
| 584 | |
| 585 | #[test] |
| 586 | fn test_abort() { |
| 587 | use crate::premade; |
| 588 | use crate::handlers::{RewriteLayer, PressReleaseMacro}; |
| 589 | use crate::UserKey; |
| 590 | use crate::test_helpers::{Checks, check_output}; |
| 591 | use crate::Modifier::Shift; |
| 592 | let mut keyboard = Keyboard::new(KeyOutCatcher::new()); |
| 593 | let mut aa = premade::ActionAbort::new(); |
| 594 | let should_enable = keyboard.add_handler(premade::one_shot_alt(0,0)); |
| 595 | const MAP: &[(u32, u32)] = &[(KeyCode::A.to_u32(), KeyCode::X.to_u32())]; |
| 596 | let should_disable = keyboard.add_handler(Box::new(RewriteLayer::new(&MAP))); |
| 597 | keyboard.output.state().enable_handler(should_disable); |
| 598 | keyboard.output.state().disable_handler(should_enable); |
| 599 | |
| 600 | aa.set_abort_status(should_enable, true); |
| 601 | aa.set_abort_status(should_disable, false); |
| 602 | |
| 603 | keyboard.add_handler( |
| 604 | Box::new(PressReleaseMacro::new(UserKey::UK0, aa)) |
| 605 | ); |
| 606 | keyboard.add_handler(Box::new(crate::handlers::USBKeyboard {})); |
| 607 | |
| 608 | assert!(!keyboard.output.state().is_handler_enabled(should_enable)); |
| 609 | assert!(keyboard.output.state().is_handler_enabled(should_disable)); |
| 610 | |
| 611 | keyboard.pc(KeyCode::LShift, &[&[KeyCode::LShift]]); |
| 612 | assert!(keyboard.output.state().modifier(Shift)); |
| 613 | keyboard.add_keypress(UserKey::UK0, 50); |
| 614 | keyboard.add_keypress(KeyCode::A, 50); |
| 615 | keyboard.handle_keys().unwrap(); |
| 616 | check_output(&keyboard, &[]); |
| 617 | |
| 618 | assert!(keyboard.output.state().is_handler_enabled(should_enable)); |
| 619 | assert!(!keyboard.output.state().is_handler_enabled(should_disable)); |
| 620 | |
| 621 | assert!(keyboard.events.is_empty()); |
| 622 | } |
| 623 | |
| 624 | } |
nothing calls this directly
no test coverage detected