Skip to content

Commit 8e87a9c

Browse files
committed
core-graphics: event: Add tests to CGEventTap
1 parent 4bbe257 commit 8e87a9c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

core-graphics/src/event.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,3 +782,37 @@ extern {
782782
fn CGEventTapEnable(tap: CFMachPortRef, enable: bool);
783783

784784
}
785+
786+
#[cfg(test)]
787+
mod test {
788+
use core_foundation::runloop::{kCFRunLoopCommonModes, CFRunLoop};
789+
790+
use super::{
791+
CGEventTap, CGEventTapLocation, CGEventTapOptions, CGEventTapPlacement, CGEventType,
792+
};
793+
794+
#[test]
795+
fn test_event_tap() {
796+
let current = CFRunLoop::get_current();
797+
match CGEventTap::new(
798+
CGEventTapLocation::HID,
799+
CGEventTapPlacement::HeadInsertEventTap,
800+
CGEventTapOptions::Default,
801+
vec![CGEventType::MouseMoved],
802+
|_a, _b, d| {
803+
println!("{:?}", d.location());
804+
None
805+
},
806+
) {
807+
Ok(tap) => unsafe {
808+
let loop_source = tap
809+
.mach_port
810+
.create_runloop_source(0)
811+
.expect("Somethings is bad ");
812+
current.add_source(&loop_source, kCFRunLoopCommonModes);
813+
tap.enable();
814+
},
815+
Err(_) => (assert!(false)),
816+
}
817+
}
818+
}

0 commit comments

Comments
 (0)