Skip to content

Commit 8b708e9

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 e13c16f commit 8b708e9

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/backend/tests/device_change.rs

+37
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,41 @@ 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, unit, id) = if scope == Scope::Output {
126+
(
127+
AU_OUT_BUS,
128+
stm.core_stream_data.output_unit,
129+
stm.core_stream_data.output_device.id,
130+
)
131+
} else {
132+
(
133+
AU_IN_BUS,
134+
stm.core_stream_data.input_unit,
135+
stm.core_stream_data.input_device.id,
136+
)
137+
};
138+
let mut device_id: AudioDeviceID = 0;
139+
let mut size = std::mem::size_of::<AudioDeviceID>();
140+
let status = audio_unit_get_property(
141+
unit,
142+
kAudioOutputUnitProperty_CurrentDevice,
143+
kAudioUnitScope_Global,
144+
bus,
145+
&mut device_id,
146+
&mut size,
147+
);
148+
if status != NO_ERR {
149+
panic!("Could not get device ID from audiounit");
150+
}
151+
assert_eq!(id, current);
152+
assert_eq!(device_id, current);
153+
});
154+
};
155+
156+
check_devices(device_switcher.current());
157+
123158
// Pause the stream, and change the default device
124159
assert_eq!(unsafe { OPS.stream_stop.unwrap()(stream) }, ffi::CUBEB_OK);
125160

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

186+
check_devices(device_switcher.current());
187+
151188
let after = if scope == Scope::Output {
152189
stm.core_stream_data.output_unit
153190
} 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)