brainwires_audio/
device.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct AudioDevice {
6 pub id: String,
8 pub name: String,
10 pub is_default: bool,
12 pub direction: DeviceDirection,
14}
15
16#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
18pub enum DeviceDirection {
19 Input,
21 Output,
23}
24
25#[cfg(test)]
26mod tests {
27 use super::*;
28
29 #[test]
30 fn audio_device_creation_and_field_access() {
31 let dev = AudioDevice {
32 id: "hw:0".to_string(),
33 name: "Built-in Microphone".to_string(),
34 is_default: true,
35 direction: DeviceDirection::Input,
36 };
37 assert_eq!(dev.id, "hw:0");
38 assert_eq!(dev.name, "Built-in Microphone");
39 assert!(dev.is_default);
40 assert_eq!(dev.direction, DeviceDirection::Input);
41 }
42
43 #[test]
44 fn audio_device_non_default_output() {
45 let dev = AudioDevice {
46 id: "hw:1".to_string(),
47 name: "HDMI Output".to_string(),
48 is_default: false,
49 direction: DeviceDirection::Output,
50 };
51 assert!(!dev.is_default);
52 assert_eq!(dev.direction, DeviceDirection::Output);
53 }
54
55 #[test]
56 fn device_direction_variants_are_distinct() {
57 assert_ne!(DeviceDirection::Input, DeviceDirection::Output);
58 }
59}