Skip to content

Commit 88b1802

Browse files
committed
Tighten the device-switch-while-paused test: check that the devices are the ones we expect before and after switching
1 parent 5b0f369 commit 88b1802

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/backend/tests/device_change.rs

+39
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,43 @@ fn test_switch_device_in_scope_while_paused(scope: Scope) {
120120
stm.core_stream_data.input_unit
121121
};
122122

123+
let check_devices = |current| {
124+
stm.queue.run_sync(|| {
125+
let bus = if scope == Scope::Output {
126+
AU_OUT_BUS
127+
} else {
128+
AU_IN_BUS
129+
};
130+
let unit = if scope == Scope::Output {
131+
stm.core_stream_data.output_unit
132+
} else {
133+
stm.core_stream_data.input_unit
134+
};
135+
let id = if scope == Scope::Output {
136+
stm.core_stream_data.output_device.id
137+
} else {
138+
stm.core_stream_data.input_device.id
139+
};
140+
let mut device_id: AudioDeviceID = 0;
141+
let mut size = std::mem::size_of::<AudioDeviceID>();
142+
let status = audio_unit_get_property(
143+
unit,
144+
kAudioOutputUnitProperty_CurrentDevice,
145+
kAudioUnitScope_Global,
146+
bus,
147+
&mut device_id,
148+
&mut size,
149+
);
150+
if status != NO_ERR {
151+
panic!("Could not get device ID from audiounit");
152+
}
153+
assert_eq!(id, current);
154+
assert_eq!(device_id, current);
155+
});
156+
};
157+
158+
check_devices(device_switcher.current());
159+
123160
// Pause the stream, and change the default device
124161
assert_eq!(unsafe { OPS.stream_stop.unwrap()(stream) }, ffi::CUBEB_OK);
125162

@@ -148,6 +185,8 @@ fn test_switch_device_in_scope_while_paused(scope: Scope) {
148185
// Start the stream, and check that the device in use isn't the same as before pausing
149186
assert_eq!(unsafe { OPS.stream_start.unwrap()(stream) }, ffi::CUBEB_OK);
150187

188+
check_devices(device_switcher.current());
189+
151190
let after = if scope == Scope::Output {
152191
stm.core_stream_data.output_unit
153192
} else {

src/backend/tests/utils.rs

+3
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,9 @@ impl TestDeviceSwitcher {
780780
}
781781
}
782782
}
783+
pub fn current(&self) -> AudioObjectID {
784+
self.devices[self.current_device_index]
785+
}
783786

784787
fn set_device(&self, device: AudioObjectID) -> std::result::Result<AudioObjectID, OSStatus> {
785788
test_set_default_device(device, self.scope.clone())

0 commit comments

Comments
 (0)