Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ final class AvailableCamerasTest: XCTestCase {
telephotoCamera.uniqueID = "3"
telephotoCamera.position = .back

var requiredTypes: [AVCaptureDevice.DeviceType] = [
let requiredTypes: [AVCaptureDevice.DeviceType] = [
.builtInWideAngleCamera, .builtInTelephotoCamera, .builtInUltraWideCamera,
]
var cameras = [wideAngleCamera, frontFacingCamera, telephotoCamera, ultraWideCamera]
let cameras = [wideAngleCamera, frontFacingCamera, telephotoCamera, ultraWideCamera]

XCTAssertEqual(deviceTypes, requiredTypes)
XCTAssertEqual(mediaType, .video)
Expand Down Expand Up @@ -83,7 +83,7 @@ final class AvailableCamerasTest: XCTestCase {
frontFacingCamera.uniqueID = "1"
frontFacingCamera.position = .front

var requiredTypes: [AVCaptureDevice.DeviceType] = [
let requiredTypes: [AVCaptureDevice.DeviceType] = [
.builtInWideAngleCamera, .builtInTelephotoCamera, .builtInUltraWideCamera,
]
let cameras = [wideAngleCamera, frontFacingCamera]
Expand Down Expand Up @@ -115,7 +115,7 @@ final class AvailableCamerasTest: XCTestCase {
unspecifiedCamera.uniqueID = "0"
unspecifiedCamera.position = .unspecified

var requiredTypes: [AVCaptureDevice.DeviceType] = [
let requiredTypes: [AVCaptureDevice.DeviceType] = [
.builtInWideAngleCamera, .builtInTelephotoCamera, .builtInUltraWideCamera,
]
let cameras = [unspecifiedCamera]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ final class CameraOrientationTests: XCTestCase {
let (_, mockCamera, mockEventAPI, mockDevice, mockDeviceDiscoverer, _) = createCameraPlugin()
let captureSessionQueue = DispatchQueue(label: "capture_session_queue")
weak var weakPlugin: CameraPlugin?
weak var weakDevice = mockDevice

autoreleasepool {
let cameraPlugin = CameraPlugin(
Expand All @@ -126,7 +125,7 @@ final class CameraOrientationTests: XCTestCase {
globalAPI: mockEventAPI,
deviceDiscoverer: mockDeviceDiscoverer,
permissionManager: MockCameraPermissionManager(),
deviceFactory: { _ in weakDevice! },
deviceFactory: { _ in mockDevice },

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bot review is right:

Capturing mockDevice weakly and force-unwrapping it is unnecessary here. Since mockDevice is a local variable in the test and does not hold any reference back to the CameraPlugin or the closure, capturing it strongly will not create a retain cycle. Simplifying this to a strong capture avoids the force-unwrap (!) and makes the code cleaner.

captureSessionFactory: { MockCaptureSession() },
captureDeviceInputFactory: MockCaptureDeviceInputFactory(),
captureSessionQueue: captureSessionQueue
Expand Down Expand Up @@ -154,12 +153,11 @@ final class CameraOrientationTests: XCTestCase {
}
}

weak var weakEventAPI = mockEventAPI
// Must check in captureSessionQueue since orientationChanged dispatches to this queue.
let expectation = self.expectation(description: "Dispatched to capture session queue")
captureSessionQueue.async {
XCTAssertFalse(setDeviceOrientationCalled)
XCTAssertFalse(weakEventAPI?.deviceOrientationChangedCalled ?? false)
XCTAssertFalse(mockEventAPI.deviceOrientationChangedCalled)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bot review is right:

Capturing mockEventAPI weakly is unnecessary because the dispatch queue will release the closure (and thus the captured reference) immediately after execution. Since there is no retain cycle, capturing it strongly simplifies the assertion and avoids the need for optional chaining and the nil-coalescing operator (?? false), which could otherwise lead to false positives if the mock were unexpectedly nil.

expectation.fulfill()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class CameraSessionPresetsTests: XCTestCase {
let captureFormatMock = MockCaptureDeviceFormat()
let captureDeviceMock = MockCaptureDevice()
captureDeviceMock.flutterFormats = [captureFormatMock]
var currentFormat: CaptureDeviceFormat = captureFormatMock
let currentFormat: CaptureDeviceFormat = captureFormatMock
captureDeviceMock.activeFormatStub = {
return currentFormat
}
Expand Down
Loading