1#![allow(non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3#![allow(non_snake_case)]
4
5use std::os::raw::c_uint;
6
7pub const EVDI_MODULE_COMPATIBILITY_VERSION_MAJOR: u32 = 1;
13pub const EVDI_MODULE_COMPATIBILITY_VERSION_MINOR: u32 = 9;
17
18pub const EVDI_STATUS_AVAILABLE: c_uint = evdi_device_status_AVAILABLE;
19pub const EVDI_STATUS_UNRECOGNIZED: c_uint = evdi_device_status_UNRECOGNIZED;
20pub const EVDI_STATUS_NOT_PRESENT: c_uint = evdi_device_status_NOT_PRESENT;
21
22include!("./bindings.rs");
23include!("./wrapper_bindings.rs");
24
25#[cfg(test)]
26mod test {
27 use super::*;
28 use std::os::raw::{c_char, c_void};
29 use std::sync::mpsc::{channel, Sender};
30 use std::mem::{transmute, forget};
31 use std::ffi::CStr;
32
33 extern "C" fn noop_wrapper_log_cb(_user_data: *mut c_void, _msg: *const c_char) {}
34
35 #[test]
36 fn can_register_wrapper_log_cb() {
37 unsafe {
38 wrapper_evdi_set_logging(wrapper_log_cb {
39 function: Some(noop_wrapper_log_cb),
40 user_data: 0 as *mut c_void,
41 })
42 }
43 }
44
45 extern "C" fn channel_wrapper_log_cb(user_data: *mut c_void, msg_ptr: *const c_char) {
46 let send: &Sender<String> = unsafe { transmute(user_data) };
47 let msg = unsafe { CStr::from_ptr(msg_ptr) }
48 .to_str().unwrap()
49 .to_owned();
50 send.send(msg).unwrap();
51 }
52
53 #[test]
54 fn wrapper_log_cb_receives_at_least_one_message() {
55 let (send, recv) = channel::<String>();
56
57 unsafe {
58 wrapper_evdi_set_logging(wrapper_log_cb {
59 function: Some(channel_wrapper_log_cb),
60 user_data: transmute(&send),
61 });
62 forget(send);
63 }
64
65 unsafe { evdi_open(0); }
67
68 let msg = recv.recv().unwrap();
70
71 assert!(msg.starts_with("Opened /dev/dri/card0"));
72 }
73
74 #[test]
75 fn evdi_check_device_for_not_present() {
76 let status = unsafe {
77 evdi_check_device(42)
78 };
79 assert_eq!(status, EVDI_STATUS_NOT_PRESENT)
80 }
81
82 #[test]
83 fn is_correct_version() {
84 let mut version = evdi_lib_version {
85 version_major: -1,
86 version_minor: -1,
87 version_patchlevel: -1
88 };
89
90 unsafe {
91 evdi_get_lib_version(&mut version)
92 }
93
94 assert_eq!(version.version_major, 1);
95 assert_eq!(version.version_minor, 9);
96 assert_eq!(version.version_patchlevel, 1);
97 }
98}