-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[camera_avfoundation] Tests backfilling - part 5 #8873
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 4 commits into
flutter:main
from
leancodepl:feature/camera-tests-backfilling-part5
Mar 18, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cbc5559
Add tests for setting camera exposure mode
RobertOdrowaz f98d144
Make apply focus mode methods private and adjust tests
RobertOdrowaz b535abd
Make flashMode property private
RobertOdrowaz 341d896
Add tests for setting camera zoom level
RobertOdrowaz 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
There are no files selected for viewing
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
66 changes: 0 additions & 66 deletions
66
packages/camera/camera_avfoundation/example/ios/RunnerTests/CameraExposureTests.swift
This file was deleted.
Oops, something went wrong.
141 changes: 141 additions & 0 deletions
141
packages/camera/camera_avfoundation/example/ios/RunnerTests/FLTCamExposureTests.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,141 @@ | ||
| // 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 XCTest | ||
|
|
||
| @testable import camera_avfoundation | ||
|
|
||
| final class FLTCamExposureTests: XCTestCase { | ||
| private func createCamera() -> (FLTCam, MockCaptureDevice, MockDeviceOrientationProvider) { | ||
| let mockDevice = MockCaptureDevice() | ||
| let mockDeviceOrientationProvider = MockDeviceOrientationProvider() | ||
|
|
||
| let configuration = FLTCreateTestCameraConfiguration() | ||
| configuration.captureDeviceFactory = { mockDevice } | ||
| configuration.deviceOrientationProvider = mockDeviceOrientationProvider | ||
| let camera = FLTCreateCamWithConfiguration(configuration) | ||
|
|
||
| return (camera, mockDevice, mockDeviceOrientationProvider) | ||
| } | ||
|
|
||
| func testSetExposureModeLocked_setsAuthExposeMode() { | ||
| let (camera, mockDevice, _) = createCamera() | ||
|
|
||
| mockDevice.setExposureModeStub = { mode in | ||
| // AVCaptureExposureModeAutoExpose automatically adjusts the exposure one time, and then | ||
| // locks exposure for the device | ||
| XCTAssertEqual(mode, .autoExpose) | ||
| } | ||
|
|
||
| camera.setExposureMode(.locked) | ||
| } | ||
|
|
||
| func testSetExposureModeAuto_setsContinousAutoExposureMode_ifSupported() { | ||
| let (camera, mockDevice, _) = createCamera() | ||
|
|
||
| // All exposure modes are supported | ||
| mockDevice.isExposureModeSupportedStub = { _ in true } | ||
|
|
||
| mockDevice.setExposureModeStub = { mode in | ||
| XCTAssertEqual(mode, .continuousAutoExposure) | ||
| } | ||
|
|
||
| camera.setExposureMode(.auto) | ||
| } | ||
|
|
||
| func testSetExposureModeAuto_setsAutoExposeMode_ifContinousAutoIsNotSupported() { | ||
| let (camera, mockDevice, _) = createCamera() | ||
|
|
||
| // Continous auto exposure is not supported | ||
| mockDevice.isExposureModeSupportedStub = { mode in | ||
| mode != .continuousAutoExposure | ||
| } | ||
|
|
||
| mockDevice.setExposureModeStub = { mode in | ||
| XCTAssertEqual(mode, .autoExpose) | ||
| } | ||
|
|
||
| camera.setExposureMode(.auto) | ||
| } | ||
|
|
||
| func testSetExposurePoint_setsExposurePointOfInterest() { | ||
| let (camera, mockDevice, mockDeviceOrientationProvider) = createCamera() | ||
| // 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 expectation = expectation(description: "Completion called") | ||
| camera.setExposurePoint(FCPPlatformPoint.makeWith(x: 1, y: 1)) { error in | ||
| XCTAssertNil(error) | ||
| expectation.fulfill() | ||
| } | ||
|
|
||
| waitForExpectations(timeout: 30, handler: nil) | ||
| XCTAssertEqual(setPoint, CGPoint(x: 1.0, y: 1.0)) | ||
| } | ||
|
|
||
| func testSetExposurePoint_returnsError_ifNotSupported() { | ||
| let (camera, mockDevice, mockDeviceOrientationProvider) = createCamera() | ||
| // UI is currently in landscape left orientation. | ||
| mockDeviceOrientationProvider.orientation = .landscapeLeft | ||
| // Exposure point of interest is not supported. | ||
| mockDevice.exposurePointOfInterestSupported = false | ||
|
|
||
| let expectation = 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) | ||
| } | ||
|
|
||
| func testSetExposureOffset_setsExposureTargetBias() { | ||
| let (camera, mockDevice, _) = createCamera() | ||
|
|
||
| let targetOffset = CGFloat(1.0) | ||
|
|
||
| var setExposureTargetBiasCalled = false | ||
| mockDevice.setExposureTargetBiasStub = { bias, handler in | ||
| XCTAssertEqual(bias, Float(targetOffset)) | ||
| setExposureTargetBiasCalled = true | ||
| } | ||
|
|
||
| camera.setExposureOffset(targetOffset) | ||
|
|
||
| XCTAssertTrue(setExposureTargetBiasCalled) | ||
| } | ||
|
|
||
| func testMaximumExposureOffset_returnsDeviceMaxExposureTargetBias() { | ||
| let (camera, mockDevice, _) = createCamera() | ||
|
|
||
| let targetOffset = CGFloat(1.0) | ||
|
|
||
| mockDevice.maxExposureTargetBias = Float(targetOffset) | ||
|
|
||
| XCTAssertEqual(camera.maximumExposureOffset, targetOffset) | ||
| } | ||
|
|
||
| func testMinimumExposureOffset_returnsDeviceMinExposureTargetBias() { | ||
| let (camera, mockDevice, _) = createCamera() | ||
|
|
||
| let targetOffset = CGFloat(1.0) | ||
|
|
||
| mockDevice.minExposureTargetBias = Float(targetOffset) | ||
|
|
||
| XCTAssertEqual(camera.minimumExposureOffset, targetOffset) | ||
| } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice