Check device id in audiounit_get_sub_devices

This commit is contained in:
Chun-Min Chang 2019-05-01 16:03:02 -07:00
Родитель 60e463b1fd
Коммит 653ce8d350
3 изменённых файлов: 58 добавлений и 19 удалений

Просмотреть файл

@ -924,9 +924,7 @@ fn audiounit_set_channel_layout(
}
fn audiounit_get_sub_devices(device_id: AudioDeviceID) -> Vec<AudioObjectID> {
// FIXIT: Add a check ? We will fail to get data size if `device_id`
// is `kAudioObjectUnknown`!
// assert_ne!(device_id, kAudioObjectUnknown);
assert_ne!(device_id, kAudioObjectUnknown);
let mut sub_devices = Vec::new();
let property_address = AudioObjectPropertyAddress {

Просмотреть файл

@ -213,6 +213,7 @@ fn test_aggregate_create_blank_aggregate_device() {
// ------------------------------------
#[test]
#[ignore]
#[should_panic]
fn test_aggregate_set_aggregate_sub_device_list_for_unknown_input_output_devices() {
let mut plugin_id = kAudioObjectUnknown;
let mut aggregate_device_id = kAudioObjectUnknown;
@ -237,8 +238,25 @@ fn test_aggregate_set_aggregate_sub_device_list_for_unknown_input_output_devices
.unwrap_err(),
Error::error()
);
}
#[test]
#[ignore]
#[should_panic]
fn test_aggregate_set_aggregate_sub_device_list_for_unknown_input_devices() {
let mut plugin_id = kAudioObjectUnknown;
let mut aggregate_device_id = kAudioObjectUnknown;
assert!(
audiounit_create_blank_aggregate_device(&mut plugin_id, &mut aggregate_device_id).is_ok()
);
assert_ne!(plugin_id, kAudioObjectUnknown);
assert_ne!(aggregate_device_id, kAudioObjectUnknown);
// NOTE: We will get errors and pass the test here since get_device_name()
// return a NULL CFStringRef for a unknown devicie. Instead of
// replying on get_device_name(). We should check this in the
// beginning of the audiounit_set_aggregate_sub_device_list().
let input_id = audiounit_get_default_device_id(DeviceType::INPUT);
let output_id = audiounit_get_default_device_id(DeviceType::OUTPUT);
// Only input is unknown.
@ -254,6 +272,28 @@ fn test_aggregate_set_aggregate_sub_device_list_for_unknown_input_output_devices
);
}
assert!(audiounit_destroy_aggregate_device(plugin_id, &mut aggregate_device_id).is_ok());
}
#[test]
#[ignore]
#[should_panic]
fn test_aggregate_set_aggregate_sub_device_list_for_unknown_output_devices() {
let mut plugin_id = kAudioObjectUnknown;
let mut aggregate_device_id = kAudioObjectUnknown;
assert!(
audiounit_create_blank_aggregate_device(&mut plugin_id, &mut aggregate_device_id).is_ok()
);
assert_ne!(plugin_id, kAudioObjectUnknown);
assert_ne!(aggregate_device_id, kAudioObjectUnknown);
// NOTE: We will get errors and pass the test here since get_device_name()
// return a NULL CFStringRef for a unknown devicie. Instead of
// replying on get_device_name(). We should check this in the
// beginning of the audiounit_set_aggregate_sub_device_list().
let input_id = audiounit_get_default_device_id(DeviceType::INPUT);
// Only output is unknown.
if valid_id(input_id) {
assert_eq!(

Просмотреть файл

@ -1186,11 +1186,8 @@ fn test_get_sub_devices() {
}
}
// FIXIT: It doesn't make any sense to return the sub devices for an unknown
// device! It should either get a panic or return an empty list!
#[test]
#[should_panic]
#[ignore]
fn test_get_sub_devices_for_a_unknown_device() {
let devices = audiounit_get_sub_devices(kAudioObjectUnknown);
assert!(devices.is_empty());
@ -1226,18 +1223,7 @@ fn test_get_device_name() {
// ------------------------------------
#[test]
fn test_set_aggregate_sub_device_list_for_an_unknown_aggregate_device() {
// If aggregate device id is kAudioObjectUnknown, we won't be able to
// set device list.
assert_eq!(
audiounit_set_aggregate_sub_device_list(
kAudioObjectUnknown,
kAudioObjectUnknown,
kAudioObjectUnknown
)
.unwrap_err(),
Error::error()
);
// If aggregate device id is kAudioObjectUnknown, we are unable to set device list.
let default_input = test_get_default_device(Scope::Input);
let default_output = test_get_default_device(Scope::Output);
if default_input.is_none() || default_output.is_none() {
@ -1254,6 +1240,21 @@ fn test_set_aggregate_sub_device_list_for_an_unknown_aggregate_device() {
);
}
#[test]
#[should_panic]
fn test_set_aggregate_sub_device_list_for_unknown_devices() {
// If aggregate device id is kAudioObjectUnknown, we are unable to set device list.
assert_eq!(
audiounit_set_aggregate_sub_device_list(
kAudioObjectUnknown,
kAudioObjectUnknown,
kAudioObjectUnknown
)
.unwrap_err(),
Error::error()
);
}
// set_master_aggregate_device
// ------------------------------------
#[test]