Skip to content

Commit f1b1eb5

Browse files
[camera_avfoundation] Test utils and mocks swift migration - part 2 (#8892)
Migrates camera test utils and mocks as part of flutter/flutter#119109 Migrates to swift following mock classes: - MockCameraDeviceDiscoverer - MockDeviceOrientationProvider - MockCapturePhotoOutput - MockCaptureDeviceFormat - MockFrameRateRange - MockCaptureConnection - MockGlobalEventApi - MockFlutterTextureRegistry - MockFlutterBinaryMessenger ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent be0e0e2 commit f1b1eb5

28 files changed

+230
-410
lines changed

packages/camera/camera_avfoundation/example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 36 additions & 48 deletions
Large diffs are not rendered by default.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ final class FLTCamExposureTests: XCTestCase {
6262
func testSetExposurePoint_setsExposurePointOfInterest() {
6363
let (camera, mockDevice, mockDeviceOrientationProvider) = createCamera()
6464
// UI is currently in landscape left orientation.
65-
mockDeviceOrientationProvider.orientation = .landscapeLeft
65+
mockDeviceOrientationProvider.orientationStub = { .landscapeLeft }
6666
// Exposure point of interest is supported.
6767
mockDevice.isExposurePointOfInterestSupported = true
6868

@@ -87,7 +87,7 @@ final class FLTCamExposureTests: XCTestCase {
8787
func testSetExposurePoint_returnsError_ifNotSupported() {
8888
let (camera, mockDevice, mockDeviceOrientationProvider) = createCamera()
8989
// UI is currently in landscape left orientation.
90-
mockDeviceOrientationProvider.orientation = .landscapeLeft
90+
mockDeviceOrientationProvider.orientationStub = { .landscapeLeft }
9191
// Exposure point of interest is not supported.
9292
mockDevice.isExposurePointOfInterestSupported = false
9393

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ final class FLTCamSetFocusModeTests: XCTestCase {
122122
func testSetFocusPointWithResult_SetsFocusPointOfInterest() {
123123
let (camera, mockDevice, mockDeviceOrientationProvider) = createCamera()
124124
// UI is currently in landscape left orientation.
125-
mockDeviceOrientationProvider.orientation = .landscapeLeft
125+
mockDeviceOrientationProvider.orientationStub = { .landscapeLeft }
126126
// Focus point of interest is supported.
127127
mockDevice.isFocusPointOfInterestSupported = true
128128

@@ -143,7 +143,7 @@ final class FLTCamSetFocusModeTests: XCTestCase {
143143
func testSetFocusPoint_WhenNotSupported_ReturnsError() {
144144
let (camera, mockDevice, mockDeviceOrientationProvider) = createCamera()
145145
// UI is currently in landscape left orientation.
146-
mockDeviceOrientationProvider.orientation = .landscapeLeft
146+
mockDeviceOrientationProvider.orientationStub = { .landscapeLeft }
147147
// Focus point of interest is not supported.
148148
mockDevice.isFocusPointOfInterestSupported = false
149149

packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCameraDeviceDiscoverer.h

Lines changed: 0 additions & 22 deletions
This file was deleted.

packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCameraDeviceDiscoverer.m

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
/// Mock implementation of `FLTCameraDeviceDiscovering` protocol which allows injecting a custom
6+
/// implementation for session discovery.
7+
final class MockCameraDeviceDiscoverer: NSObject, FLTCameraDeviceDiscovering {
8+
var discoverySessionStub:
9+
(
10+
(
11+
_ deviceTypes: [AVCaptureDevice.DeviceType],
12+
_ mediaType: AVMediaType,
13+
_ position: AVCaptureDevice.Position
14+
) -> [NSObject & FLTCaptureDevice]?
15+
)?
16+
17+
/// A stub that replaces the default implementation of
18+
/// `discoverySessionWithDeviceTypes:mediaType:position`.
19+
func discoverySession(
20+
withDeviceTypes deviceTypes: [AVCaptureDevice.DeviceType], mediaType: AVMediaType,
21+
position: AVCaptureDevice.Position
22+
) -> [FLTCaptureDevice] {
23+
return discoverySessionStub?(deviceTypes, mediaType, position) ?? []
24+
}
25+
}

packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureConnection.h

Lines changed: 0 additions & 27 deletions
This file was deleted.

packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureConnection.m

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
/// A mock implementation of `FLTCaptureConnection` that allows injecting a custom implementation.
6+
final class MockCaptureConnection: NSObject, FLTCaptureConnection {
7+
var setVideoOrientationStub: ((AVCaptureVideoOrientation) -> Void)?
8+
9+
var connection: AVCaptureConnection {
10+
preconditionFailure("Attempted to access unimplemented property: connection")
11+
}
12+
var isVideoMirrored = false
13+
var videoOrientation: AVCaptureVideoOrientation {
14+
get { AVCaptureVideoOrientation.portrait }
15+
set {
16+
setVideoOrientationStub?(newValue)
17+
}
18+
}
19+
var inputPorts: [AVCaptureInput.Port] = []
20+
var isVideoMirroringSupported = false
21+
var isVideoOrientationSupported = false
22+
}

packages/camera/camera_avfoundation/example/ios/RunnerTests/Mocks/MockCaptureDeviceFormat.h

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)