File: all.rs

package info (click to toggle)
rust-evdev-rs 0.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 384 kB
  • sloc: python: 211; makefile: 4; sh: 3
file content (199 lines) | stat: -rw-r--r-- 4,805 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
use evdev_rs::enums::*;
use evdev_rs::*;
use std::fs::File;
use std::os::unix::io::AsRawFd;

#[test]
fn context_create() {
    assert!(UninitDevice::new().is_some());
}

#[ignore = "broken in Debian"]
#[test]
fn context_create_with_file() {
    let f = File::open("/dev/input/event0").unwrap();
    let _d = Device::new_from_file(f).unwrap();
}

#[ignore = "broken in Debian"]
#[test]
fn context_create_with_path() {
    let _d = Device::new_from_path("/dev/input/event0").unwrap();
}

#[ignore = "broken in Debian"]
#[test]
fn context_set_file() {
    let d = UninitDevice::new().unwrap();
    let f = File::open("/dev/input/event0").unwrap();
    let _device = d.set_file(f).unwrap();
}

#[ignore = "broken in Debian"]
#[test]
fn context_change_file() {
    let d = UninitDevice::new().unwrap();
    let f1 = File::open("/dev/input/event0").unwrap();
    let f2 = File::open("/dev/input/event0").unwrap();
    let f2_fd = f2.as_raw_fd();

    let mut d = d.set_file(f1).unwrap();
    d.change_file(f2).unwrap();

    assert_eq!(d.file().as_raw_fd(), f2_fd);
}

#[ignore = "broken in Debian"]
#[test]
fn context_grab() {
    let mut d = Device::new_from_path("/dev/input/event0").unwrap();
    d.grab(GrabMode::Grab).unwrap();
    d.grab(GrabMode::Ungrab).unwrap();
}

#[test]
fn device_get_name() {
    let d = UninitDevice::new().unwrap();

    d.set_name("hello");
    assert_eq!(d.name().unwrap(), "hello");
}

#[test]
fn device_get_uniq() {
    let d = UninitDevice::new().unwrap();

    d.set_uniq("test");
    assert_eq!(d.uniq().unwrap(), "test");
}

#[test]
fn device_get_phys() {
    let d = UninitDevice::new().unwrap();

    d.set_phys("test");
    assert_eq!(d.phys().unwrap(), "test");
}

#[test]
fn device_get_product_id() {
    let d = UninitDevice::new().unwrap();

    d.set_product_id(5);
    assert_eq!(d.product_id(), 5);
}

#[test]
fn device_get_vendor_id() {
    let d = UninitDevice::new().unwrap();

    d.set_vendor_id(5);
    assert_eq!(d.vendor_id(), 5);
}

#[test]
fn device_get_bustype() {
    let d = UninitDevice::new().unwrap();

    d.set_bustype(5);
    assert_eq!(d.bustype(), 5);
}

#[test]
fn device_get_version() {
    let d = UninitDevice::new().unwrap();

    d.set_version(5);
    assert_eq!(d.version(), 5);
}

#[ignore = "broken in Debian"]
#[test]
fn device_get_absinfo() {
    let d = Device::new_from_path("/dev/input/event0").unwrap();
    for code in EventCode::EV_SYN(EV_SYN::SYN_REPORT).iter() {
        let absinfo: Option<AbsInfo> = d.abs_info(&code);

        match absinfo {
            None => ..,
            Some(_a) => ..,
        };
    }
}

#[ignore = "broken in Debian"]
#[test]
fn device_has_property() {
    let d = Device::new_from_path("/dev/input/event0").unwrap();
    for prop in InputProp::INPUT_PROP_POINTER.iter() {
        if d.has_property(&prop) {
            panic!("Prop {} is set, shouldn't be", prop);
        }
    }
}

#[test]
fn device_enable_disable() {
    #[cfg(feature = "libevdev-1-10")]
    let prop = InputProp::INPUT_PROP_POINTER;
    let ev_type = EventType::EV_KEY;
    let code = EventCode::EV_KEY(EV_KEY::KEY_LEFTSHIFT);
    let d = UninitDevice::new().unwrap();
    #[cfg(feature = "libevdev-1-10")]
    assert!(!d.has(prop));
    assert!(!d.has(ev_type));
    assert!(!d.has(code));
    #[cfg(feature = "libevdev-1-10")]
    d.enable(prop).unwrap();
    d.enable(ev_type).unwrap();
    d.enable(code).unwrap();
    #[cfg(feature = "libevdev-1-10")]
    assert!(d.has(prop));
    assert!(d.has(ev_type));
    assert!(d.has(code));
    #[cfg(feature = "libevdev-1-10")]
    d.disable(prop).unwrap();
    d.disable(ev_type).unwrap();
    d.disable(code).unwrap();
    #[cfg(feature = "libevdev-1-10")]
    assert!(!d.has(prop));
    assert!(!d.has(ev_type));
    assert!(!d.has(code));
}

#[ignore = "broken in Debian"]
#[test]
fn device_has_syn() {
    let d = UninitDevice::new().unwrap();
    let f = File::open("/dev/input/event0").unwrap();

    let d = d.set_file(f).unwrap();

    assert!(d.has(EventType::EV_SYN)); // EV_SYN
    assert!(d.has(EventCode::EV_SYN(EV_SYN::SYN_REPORT))); // SYN_REPORT
}

#[ignore = "broken in Debian"]
#[test]
fn device_get_value() {
    let d = UninitDevice::new().unwrap();
    let f = File::open("/dev/input/event0").unwrap();

    let d = d.set_file(f).unwrap();

    let v2 = d.event_value(&EventCode::EV_SYN(EV_SYN::SYN_REPORT)); // SYN_REPORT
    assert_eq!(v2, Some(0));
}

#[test]
fn check_event_name() {
    assert_eq!("EV_ABS", EventType::EV_ABS.to_string());
}

#[test]
fn test_timeval() {
    assert_eq!(TimeVal::new(1, 1_000_000), TimeVal::new(2, 0));
    assert_eq!(TimeVal::new(-1, -1_000_000), TimeVal::new(-2, 0));
    assert_eq!(TimeVal::new(1, -1_000_000), TimeVal::new(0, 0));
    assert_eq!(TimeVal::new(-100, 1_000_000 * 100), TimeVal::new(0, 0));
}