Skip to content

Commit 5bbc05c

Browse files
committed
[camera_avfoundation] Add test for @sendable completion handler
- Updates MockCaptureDevice to use @sendable on setExposureTargetBias, keeping it in sync with the CaptureDevice protocol requirement. - Adds testSetExposureTargetBias_completionHandlerIsInvoked to exercise the non-nil handler path and serve as a compile-time regression guard: if @sendable is removed from the protocol the mock conformance breaks.
1 parent a1ddc6f commit 5bbc05c

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraExposureTests.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,26 @@ final class CameraExposureTests: XCTestCase {
124124
XCTAssertTrue(setExposureTargetBiasCalled)
125125
}
126126

127+
func testSetExposureTargetBias_completionHandlerIsInvoked() {
128+
// Regression test: the completion handler must be @Sendable to match
129+
// AVCaptureDevice's signature (Swift 6 requirement).
130+
// MockCaptureDevice conforms to CaptureDevice, so a compilation failure
131+
// here means the protocol and mock have diverged.
132+
let (_, mockDevice, _) = createCamera()
133+
134+
let expectation = expectation(description: "completion handler invoked")
135+
136+
mockDevice.setExposureTargetBiasStub = { _, handler in
137+
handler?(CMTime(value: 1, timescale: 1))
138+
}
139+
140+
mockDevice.setExposureTargetBias(1.0) { _ in
141+
expectation.fulfill()
142+
}
143+
144+
waitForExpectations(timeout: 1.0)
145+
}
146+
127147
func testMaximumExposureOffset_returnsDeviceMaxExposureTargetBias() {
128148
let (camera, mockDevice, _) = createCamera()
129149

packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureDevice.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class MockCaptureDevice: NSObject, CaptureDevice {
1818
var setFocusPointOfInterestStub: ((CGPoint) -> Void)?
1919
var setExposureModeStub: ((AVCaptureDevice.ExposureMode) -> Void)?
2020
var setExposurePointOfInterestStub: ((CGPoint) -> Void)?
21-
var setExposureTargetBiasStub: ((Float, ((CMTime) -> Void)?) -> Void)?
21+
var setExposureTargetBiasStub: ((Float, (@Sendable (CMTime) -> Void)?) -> Void)?
2222
var isExposureModeSupportedStub: ((AVCaptureDevice.ExposureMode) -> Bool)?
2323
var setVideoZoomFactorStub: ((CGFloat) -> Void)?
2424
var lockForConfigurationStub: (() throws -> Void)?
@@ -99,7 +99,7 @@ class MockCaptureDevice: NSObject, CaptureDevice {
9999
set { setExposurePointOfInterestStub?(newValue) }
100100
}
101101

102-
func setExposureTargetBias(_ bias: Float, completionHandler handler: ((CMTime) -> Void)? = nil) {
102+
func setExposureTargetBias(_ bias: Float, completionHandler handler: (@Sendable (CMTime) -> Void)? = nil) {
103103
setExposureTargetBiasStub?(bias, handler)
104104
}
105105

0 commit comments

Comments
 (0)