cue_sdk/device/
capabilities.rs1use cue_sdk_sys as ffi;
2
3#[derive(Debug, Clone, PartialEq)]
5pub struct DeviceCapabilities {
6 pub lighting: bool,
7 pub property_lookup: bool,
8}
9
10impl DeviceCapabilities {
11 pub(crate) fn from_ffi(bitmask: i32) -> Self {
12 let lighting_val = bitmask & ffi::CorsairDeviceCaps_CDC_Lighting as i32;
13 let property_lookup_val = bitmask & ffi::CorsairDeviceCaps_CDC_PropertyLookup as i32;
14 DeviceCapabilities {
15 lighting: lighting_val != 0,
16 property_lookup: property_lookup_val != 0,
17 }
18 }
19}
20
21#[cfg(test)]
22mod tests {
23 use cue_sdk_sys as ffi;
24
25 use super::DeviceCapabilities;
26
27 #[test]
28 pub fn from_ffi_both_enabled() {
29 let bitmask = 0i32
30 | ffi::CorsairDeviceCaps_CDC_Lighting as i32
31 | ffi::CorsairDeviceCaps_CDC_PropertyLookup as i32;
32 assert_eq!(
33 DeviceCapabilities::from_ffi(bitmask),
34 DeviceCapabilities {
35 property_lookup: true,
36 lighting: true
37 }
38 )
39 }
40
41 #[test]
42 pub fn from_ffi_neither_enabled() {
43 let bitmask = 0i32;
44 assert_eq!(
45 DeviceCapabilities::from_ffi(bitmask),
46 DeviceCapabilities {
47 property_lookup: false,
48 lighting: false
49 }
50 )
51 }
52
53 #[test]
54 pub fn from_ffi_just_lighting() {
55 let bitmask = 0i32 | ffi::CorsairDeviceCaps_CDC_Lighting as i32;
56 assert_eq!(
57 DeviceCapabilities::from_ffi(bitmask),
58 DeviceCapabilities {
59 property_lookup: false,
60 lighting: true
61 }
62 )
63 }
64
65 #[test]
66 pub fn from_ffi_just_property_lookup() {
67 let bitmask = 0i32 | ffi::CorsairDeviceCaps_CDC_PropertyLookup as i32;
68 assert_eq!(
69 DeviceCapabilities::from_ffi(bitmask),
70 DeviceCapabilities {
71 property_lookup: true,
72 lighting: false
73 }
74 )
75 }
76}