MCPcopy Create free account
hub / github.com/emberian/evdev / test_virtual_device_actually_emits

Function test_virtual_device_actually_emits

tests/virtual_device.rs:12–56  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10
11#[tokio::test]
12async fn test_virtual_device_actually_emits() -> Result<(), Box<dyn Error>> {
13 let mut keys = AttributeSet::<KeyCode>::new();
14 let virtual_device_name = "fake-keyboard";
15 keys.insert(KeyCode::KEY_ESC);
16
17 let mut device = VirtualDevice::builder()?
18 .name(virtual_device_name)
19 .with_keys(&keys)?
20 .build()
21 .unwrap();
22
23 let mut maybe_device = None;
24 sleep(Duration::from_millis(500));
25 for (_i, d) in evdev::enumerate() {
26 println!("{:?}", d.name());
27 if d.name() == Some(virtual_device_name) {
28 maybe_device = Some(d);
29 break;
30 }
31 }
32 assert!(maybe_device.is_some());
33 let listen_device = maybe_device.unwrap();
34
35 let type_ = EventType::KEY;
36 let code = KeyCode::KEY_ESC.code();
37
38 // listen for events on the listen device
39 let listener = tokio::spawn(async move {
40 // try to read the key code that will be sent through virtual device
41 let mut events = listen_device.into_event_stream()?;
42 events.next_event().await
43 });
44
45 // emit a key code through virtual device
46 let down_event = InputEvent::new(type_.0, code, 10);
47 device.emit(&[down_event]).unwrap();
48
49 let event = timeout(Duration::from_secs(1), listener).await???;
50
51 assert_eq!(down_event.event_type(), event.event_type());
52 assert_eq!(down_event.code(), event.code());
53
54 // wait for listener
55 Ok(())
56}

Callers

nothing calls this directly

Calls 9

insertMethod · 0.80
buildMethod · 0.80
with_keysMethod · 0.80
emitMethod · 0.80
enumerateFunction · 0.50
nameMethod · 0.45
codeMethod · 0.45
into_event_streamMethod · 0.45
next_eventMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…