-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[camera_avfoundation] Migrate tests to Swift - part 1 #8603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
auto-submit
merged 25 commits into
flutter:main
from
leancodepl:feature/camera-swift-test-migration
Feb 12, 2025
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
f476931
Add bridging header file
FirentisTFW b0decfb
Migrate CameraPreviewPauseTests to Swift
FirentisTFW 75dca24
Migrate CameraPropertiesTests to Swift, format code
FirentisTFW 4a98112
Migrate QueueUtilsTests to Swift
FirentisTFW 2a4168c
Migrate CameraExposureTests to Swift
FirentisTFW 164095e
Migrate CameraFocusTests and AvailableCamerasTest to Swift
FirentisTFW ef0c0c0
Migrate CameraPermissionTests to Swift
FirentisTFW aab1d5e
Format file
FirentisTFW 06a7bd6
Bump version and update changelog
FirentisTFW cb937d6
Format Swift files
FirentisTFW 8d10061
Handle catching Objective-C errors in Swift tests
FirentisTFW a314c5b
Fix expectation timeout after rebase
FirentisTFW 6d4bf8d
Remove redundant comments
FirentisTFW fc34006
Add more context to changelog entry
FirentisTFW 2f7c9fd
Refactor code according to style guide
FirentisTFW 8701be9
Start changelog message with a verb
FirentisTFW 85ef5a1
Make method private
FirentisTFW 5ba3781
Compare CGPoints directly
FirentisTFW cacdf4c
Make helper class fileprivate
FirentisTFW 7c589d1
Do not use setUp for a file with only two tests
FirentisTFW 605b4df
Remove shared state from tests
FirentisTFW 1453630
Remove redundant empty lines
FirentisTFW 4f9cbdd
Add a todo to use errors when migrating to Swift
FirentisTFW a10c4ac
Format files
FirentisTFW 20682dc
Add more information to a todo
FirentisTFW File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Migrate CameraExposureTests to Swift
- Loading branch information
commit 2a4168c3acac6c3e440207efbf4cf95e5c92dfee
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraExposureTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import AVFoundation | ||
| import camera_avfoundation | ||
| import XCTest | ||
|
|
||
| class CameraExposureTests: XCTestCase { | ||
| var camera: FLTCam! | ||
| var mockDevice: MockCaptureDevice! | ||
| var mockDeviceOrientationProvider: MockDeviceOrientationProvider! | ||
|
|
||
| override func setUp() { | ||
| mockDevice = MockCaptureDevice() | ||
| mockDeviceOrientationProvider = MockDeviceOrientationProvider() | ||
|
|
||
| camera = FLTCreateCamWithCaptureSessionQueueAndMediaSettings( | ||
| nil, nil, nil, | ||
| { self.mockDevice }, | ||
| mockDeviceOrientationProvider | ||
| ) | ||
| let configuration = FLTCreateTestCameraConfiguration() | ||
| configuration.captureDeviceFactory = { self.mockDevice } | ||
| configuration.deviceOrientationProvider = mockDeviceOrientationProvider | ||
| camera = FLTCreateCamWithConfiguration(configuration) | ||
| } | ||
|
|
||
| func testSetExposurePointWithResult_SetsExposurePointOfInterest() { | ||
| // UI is currently in landscape left orientation. | ||
| mockDeviceOrientationProvider.orientation = .landscapeLeft | ||
| // Exposure point of interest is supported. | ||
| mockDevice.exposurePointOfInterestSupported = true | ||
|
|
||
| // Verify the focus point of interest has been set. | ||
| var setPoint = CGPoint.zero | ||
| mockDevice.setExposurePointOfInterestStub = { point in | ||
| if point == CGPoint(x: 1, y: 1) { | ||
| setPoint = point | ||
| } | ||
| } | ||
|
|
||
| let completionExpectation = expectation(description: "Completion called") | ||
| camera.setExposurePoint(FCPPlatformPoint.makeWith(x: 1, y: 1)) { error in | ||
| XCTAssertNil(error) | ||
| completionExpectation.fulfill() | ||
| } | ||
|
|
||
| waitForExpectations(timeout: 30, handler: nil) | ||
| XCTAssertEqual(setPoint.x, 1.0) | ||
| XCTAssertEqual(setPoint.y, 1.0) | ||
FirentisTFW marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| func testSetExposurePoint_WhenNotSupported_ReturnsError() { | ||
| // UI is currently in landscape left orientation. | ||
| mockDeviceOrientationProvider.orientation = .landscapeLeft | ||
| // Exposure point of interest is not supported. | ||
| mockDevice.exposurePointOfInterestSupported = false | ||
|
|
||
| let expectation = self.expectation(description: "Completion with error") | ||
|
|
||
| camera.setExposurePoint(FCPPlatformPoint.makeWith(x: 1, y: 1)) { error in | ||
| XCTAssertNotNil(error) | ||
| XCTAssertEqual(error?.code, "setExposurePointFailed") | ||
| XCTAssertEqual(error?.message, "Device does not have exposure point capabilities") | ||
| expectation.fulfill() | ||
| } | ||
|
|
||
| waitForExpectations(timeout: 30, handler: nil) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.