MCPcopy Create free account
hub / github.com/TyberiusPrime/KeyToKey / test_abort

Function test_abort

src/premade.rs:586–622  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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}

Callers

nothing calls this directly

Calls 11

one_shot_altFunction · 0.85
check_outputFunction · 0.85
add_handlerMethod · 0.80
to_u32Method · 0.80
enable_handlerMethod · 0.80
stateMethod · 0.80
disable_handlerMethod · 0.80
set_abort_statusMethod · 0.80
pcMethod · 0.80
add_keypressMethod · 0.80
handle_keysMethod · 0.80

Tested by

no test coverage detected