From 89a5ccaf1acc7253e19a9ded3cc7bbd9c79186c5 Mon Sep 17 00:00:00 2001 From: Chun-Min Chang Date: Wed, 3 Apr 2019 14:07:40 -0700 Subject: [PATCH] rustfmt --- src/backend/tests/aggregate_device.rs | 3 +- src/backend/tests/api.rs | 67 +++++++++++++++++++-------- src/backend/tests/manual.rs | 11 +++-- src/backend/tests/utils.rs | 7 ++- 4 files changed, 63 insertions(+), 25 deletions(-) diff --git a/src/backend/tests/aggregate_device.rs b/src/backend/tests/aggregate_device.rs index 5c66c3a..107ecd5 100644 --- a/src/backend/tests/aggregate_device.rs +++ b/src/backend/tests/aggregate_device.rs @@ -435,7 +435,8 @@ fn test_aggregate_activate_clock_drift_compensation_for_a_blank_aggregate_device #[test] #[ignore] -fn test_aggregate_activate_clock_drift_compensation_for_an_aggregate_device_without_master_device() { +fn test_aggregate_activate_clock_drift_compensation_for_an_aggregate_device_without_master_device() +{ let input_id = audiounit_get_default_device_id(DeviceType::INPUT); let output_id = audiounit_get_default_device_id(DeviceType::OUTPUT); if !valid_id(input_id) || !valid_id(output_id) diff --git a/src/backend/tests/api.rs b/src/backend/tests/api.rs index 0236391..4f9b6b8 100644 --- a/src/backend/tests/api.rs +++ b/src/backend/tests/api.rs @@ -1819,7 +1819,10 @@ fn test_configure_input() { assert_eq!(description.mSampleRate, stream.input_hw_rate); } - fn check_linear_buffer(stream: &mut AudioUnitStream, array: &[T]) { + fn check_linear_buffer( + stream: &mut AudioUnitStream, + array: &[T], + ) { assert!(stream.input_linear_buffer.is_some()); let buffer_ref = stream.input_linear_buffer.as_mut().unwrap(); buffer_ref.push(array.as_ptr() as *const c_void, array.len()); @@ -1855,12 +1858,16 @@ fn test_configure_input_with_zero_latency_frames() { params.channels = 1; params.layout = ffi::CUBEB_LAYOUT_MONO; params.prefs = ffi::CUBEB_STREAM_PREF_NONE; - test_configure_scope_with_zero_latency_frames(Scope::Input, StreamParams::from(params), |stream| { - // TODO: The buffer frames size won't be 0 even it's ok to set that! - check_buffer_frame_size(stream, Scope::Input); - // TODO: The frames per slice won't be 0 even it's ok to set that! - check_frames_per_slice(stream, Scope::Input); - }); + test_configure_scope_with_zero_latency_frames( + Scope::Input, + StreamParams::from(params), + |stream| { + // TODO: The buffer frames size won't be 0 even it's ok to set that! + check_buffer_frame_size(stream, Scope::Input); + // TODO: The frames per slice won't be 0 even it's ok to set that! + check_frames_per_slice(stream, Scope::Input); + }, + ); } // configure_output @@ -1926,22 +1933,35 @@ fn test_configure_output_with_zero_latency_frames() { params.channels = 2; params.layout = ffi::CUBEB_LAYOUT_STEREO; params.prefs = ffi::CUBEB_STREAM_PREF_NONE; - test_configure_scope_with_zero_latency_frames(Scope::Output, StreamParams::from(params), |stream| { - // TODO: The buffer frames size won't be 0 even it's ok to set that! - check_buffer_frame_size(stream, Scope::Output); - // TODO: The frames per slice won't be 0 even it's ok to set that! - check_frames_per_slice(stream, Scope::Output); - }); + test_configure_scope_with_zero_latency_frames( + Scope::Output, + StreamParams::from(params), + |stream| { + // TODO: The buffer frames size won't be 0 even it's ok to set that! + check_buffer_frame_size(stream, Scope::Output); + // TODO: The frames per slice won't be 0 even it's ok to set that! + check_frames_per_slice(stream, Scope::Output); + }, + ); } // Utils for configure_{input, output} // ------------------------------------ -fn test_configure_scope(scope: Scope, params: StreamParams, callback: F) where F: FnOnce(&mut AudioUnitStream) { +fn test_configure_scope(scope: Scope, params: StreamParams, callback: F) +where + F: FnOnce(&mut AudioUnitStream), +{ if let Some(unit) = test_get_default_audiounit(scope.clone()) { test_get_empty_stream(|stream| { match scope { - Scope::Input => { stream.input_unit = unit.get_inner(); stream.input_stream_params = params; } - Scope::Output => { stream.output_unit = unit.get_inner(); stream.output_stream_params = params; } + Scope::Input => { + stream.input_unit = unit.get_inner(); + stream.input_stream_params = params; + } + Scope::Output => { + stream.output_unit = unit.get_inner(); + stream.output_stream_params = params; + } } // Set the latency_frames to a valid value so `buffer frames size` and // `frames per slice` can be set correctly! @@ -1966,12 +1986,21 @@ fn test_configure_scope(scope: Scope, params: StreamParams, callback: F) wher } } -fn test_configure_scope_with_zero_latency_frames(scope: Scope, params: StreamParams, callback: F) where F: FnOnce(&mut AudioUnitStream) { +fn test_configure_scope_with_zero_latency_frames(scope: Scope, params: StreamParams, callback: F) +where + F: FnOnce(&mut AudioUnitStream), +{ if let Some(unit) = test_get_default_audiounit(scope.clone()) { test_get_empty_stream(|stream| { match scope { - Scope::Input => { stream.input_unit = unit.get_inner(); stream.input_stream_params = params; } - Scope::Output => { stream.output_unit = unit.get_inner(); stream.output_stream_params = params; } + Scope::Input => { + stream.input_unit = unit.get_inner(); + stream.input_stream_params = params; + } + Scope::Output => { + stream.output_unit = unit.get_inner(); + stream.output_stream_params = params; + } } assert_eq!(stream.latency_frames, 0); let res = match scope { diff --git a/src/backend/tests/manual.rs b/src/backend/tests/manual.rs index f8934b1..26a6ee4 100644 --- a/src/backend/tests/manual.rs +++ b/src/backend/tests/manual.rs @@ -1,4 +1,7 @@ -use super::utils::{test_get_default_device, test_ops_stream_operation, Scope, test_get_devices_in_scope, test_set_default_device}; +use super::utils::{ + test_get_default_device, test_get_devices_in_scope, test_ops_stream_operation, + test_set_default_device, Scope, +}; use super::*; #[ignore] @@ -62,7 +65,10 @@ fn test_switch_output_device() { return; } let current = test_get_default_device(Scope::Output).unwrap(); - let mut index = devices.iter().position(|device| *device == current).unwrap(); + let mut index = devices + .iter() + .position(|device| *device == current) + .unwrap(); println!("{:?}, {}, {}", devices, current, index); // Make sure the parameters meet the requirements of AudioUnitContext::stream_init @@ -107,4 +113,3 @@ fn test_switch_output_device() { }, ); } - diff --git a/src/backend/tests/utils.rs b/src/backend/tests/utils.rs index 0f7ecae..597b120 100644 --- a/src/backend/tests/utils.rs +++ b/src/backend/tests/utils.rs @@ -400,13 +400,16 @@ pub fn test_audiounit_scope_is_enabled(unit: AudioUnit, scope: Scope) -> bool { // 2. a non-input/non-output device // 3. the current default input/output device // as the new default input/output device by apple's API. We need to check the above things by ourselves. -pub fn test_set_default_device(device: AudioObjectID, scope: Scope) -> std::result::Result { +pub fn test_set_default_device( + device: AudioObjectID, + scope: Scope, +) -> std::result::Result { let default = test_get_default_device(scope.clone()); if default.is_none() { return Ok(false); } let default = default.unwrap(); - if default == device || !test_device_in_scope(device, scope.clone()){ + if default == device || !test_device_in_scope(device, scope.clone()) { return Ok(false); } let address = AudioObjectPropertyAddress {