oficina / meet Public

Clone
git clone https://amadan.net/oficina/meet

Plain git — no account needed to clone.

Download

Download this file

1import AVFoundation
2import CallsKit
3import XCTest
4
5/// The Bluetooth rule, which only exists on iOS and so can only be tested
6/// here — CallsKitTests builds for macOS, where AVAudioSession does not
7/// exist at all.
8final class AudioRouteTests: XCTestCase {
9 func testBluetoothIsAllowedOnlyWhenItIsTheChosenMicrophone() {
10 // .allowBluetoothHFP is what lets a Bluetooth microphone be used, and
11 // it is also what drags the whole call to the 8 kHz hands-free
12 // profile the moment any headset connects. Left on unconditionally —
13 // as it was until this change — every pair of AirPods silently cost
14 // the call its audio quality in both directions, and nothing said so.
15 let ordinary = AudioRoutes.options(bluetoothInput: false)
16 XCTAssertFalse(
17 ordinary.contains(.allowBluetoothHFP),
18 "a call with no Bluetooth microphone chosen must not offer the hands-free profile")
19 XCTAssertTrue(
20 ordinary.contains(.allowBluetoothA2DP),
21 "output should still reach a headset, at A2DP quality")
22 XCTAssertTrue(ordinary.contains(.defaultToSpeaker))
23
24 // Picking the headset microphone is an informed trade, and then HFP
25 // is exactly what has to be allowed for it to work at all.
26 let headset = AudioRoutes.options(bluetoothInput: true)
27 XCTAssertTrue(headset.contains(.allowBluetoothHFP))
28 XCTAssertTrue(headset.contains(.defaultToSpeaker))
29 }
30
31 func testOnlyTheHandsFreePortCountsAsABluetoothMicrophone() {
32 // A2DP is output-only, so a Bluetooth device being used as a
33 // microphone is always on the hands-free port. Treating A2DP as a
34 // microphone would turn HFP back on for a headset nobody is
35 // recording from, which is the bug this rule exists to avoid.
36 XCTAssertEqual(AVAudioSession.Port.bluetoothHFP.rawValue, "BluetoothHFP")
37 XCTAssertNotEqual(AVAudioSession.Port.bluetoothA2DP, AVAudioSession.Port.bluetoothHFP)
38 }
39}
40