Skip to content

[camera_avfoundation] Migrate tests to Swift - part 2 #8613

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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5de2587
Migrate CameraCaptureSessionQueueRaceConditionTests to Swift
FirentisTFW Feb 11, 2025
a7b3c02
Migrate CameraMethodChannelTests to Swift
FirentisTFW Feb 11, 2025
c91bbae
Migrate CameraOrientationTests to Swift
FirentisTFW Feb 12, 2025
2608e45
Migrate CameraSettingsTests to Swift
FirentisTFW Feb 12, 2025
f261951
Migrate CameraSessionPresetsTests to Swift
FirentisTFW Feb 12, 2025
effbaae
Bump version and update changelog
FirentisTFW Feb 11, 2025
145ccd2
Remove redundant "any" keywords
FirentisTFW Feb 12, 2025
0f7eada
Merge branch 'main' into feature/camera-swift-test-migration-part2
FirentisTFW Feb 13, 2025
5464d73
Remove duplicated test file
FirentisTFW Feb 13, 2025
39334e1
Inlcude missing test file
FirentisTFW Feb 13, 2025
6989e86
Bump version and update changelog
FirentisTFW Feb 13, 2025
6725409
Resolve conflicts in bridging-header file
FirentisTFW Feb 13, 2025
0b51e01
Revert "Inlcude missing test file"
FirentisTFW Feb 13, 2025
ff8fd05
Migrate SavePhotoDelegateTests to Swift
FirentisTFW Feb 13, 2025
974e728
Clean up - Swift tests migration
FirentisTFW Feb 13, 2025
612c425
Sort imports
FirentisTFW Feb 13, 2025
29870d5
Clean up code
FirentisTFW Feb 13, 2025
828f73e
Remove shared state from CameraOrientationTests
FirentisTFW Feb 13, 2025
aa7c223
Merge branch 'main' into feature/camera-swift-test-migration-part2
FirentisTFW Feb 13, 2025
4b74842
Bump version
FirentisTFW Feb 13, 2025
3b2b4a9
Adjust code to the new API after merge
FirentisTFW Feb 13, 2025
75a58a0
Fix a comment
FirentisTFW Feb 13, 2025
b5743e7
Merge branch 'main' into feature/camera-swift-test-migration-part2
FirentisTFW Feb 17, 2025
4237804
Adjust code after merge
FirentisTFW Feb 17, 2025
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
4 changes: 4 additions & 0 deletions packages/camera/camera_avfoundation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.9.18+8

* Migrates unit tests to Swift.

## 0.9.18+7

* Fixes crash when setting `activeFormat` on `FLTCaptureDevice`.
Expand Down

Large diffs are not rendered by default.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// 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 CameraCaptureSessionQueueRaceConditionTests: XCTestCase {
private func createCameraPlugin() -> CameraPlugin {
return CameraPlugin(
registry: MockFlutterTextureRegistry(),
messenger: MockFlutterBinaryMessenger(),
globalAPI: MockGlobalEventApi(),
deviceDiscoverer: MockCameraDeviceDiscoverer(),
deviceFactory: { _ in MockCaptureDevice() },
captureSessionFactory: { MockCaptureSession() },
captureDeviceInputFactory: MockCaptureDeviceInputFactory()
)
}

func testFixForCaptureSessionQueueNullPointerCrashDueToRaceCondition() {
let cameraPlugin = createCameraPlugin()
let disposeExpectation = expectation(description: "dispose's result block must be called")
let createExpectation = expectation(description: "create's result block must be called")

// Mimic a dispose call followed by a create call, which can be triggered by slightly dragging the
// home bar, causing the app to be inactive, and immediately regain active.
cameraPlugin.disposeCamera(0) { error in
disposeExpectation.fulfill()
}

cameraPlugin.createCameraOnSessionQueue(
withName: "acamera",
settings: FCPPlatformMediaSettings.make(
with: .medium,
framesPerSecond: nil,
videoBitrate: nil,
audioBitrate: nil,
enableAudio: true
)
) { result, error in
createExpectation.fulfill()
}

waitForExpectations(timeout: 30, handler: nil)

// `captureSessionQueue` must not be nil after `create` call. Otherwise a nil
// `captureSessionQueue` passed into `AVCaptureVideoDataOutput::setSampleBufferDelegate:queue:`
// API will cause a crash.
XCTAssertNotNil(
cameraPlugin.captureSessionQueue, "captureSessionQueue must not be nil after create method.")
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// 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 XCTest

@testable import camera_avfoundation

final class CameraMethodChannelTests: XCTestCase {
private func createCameraPlugin(with session: MockCaptureSession) -> CameraPlugin {
return CameraPlugin(
registry: MockFlutterTextureRegistry(),
messenger: MockFlutterBinaryMessenger(),
globalAPI: MockGlobalEventApi(),
deviceDiscoverer: MockCameraDeviceDiscoverer(),
deviceFactory: { _ in MockCaptureDevice() },
captureSessionFactory: { session },
captureDeviceInputFactory: MockCaptureDeviceInputFactory()
)
}

func testCreate_ShouldCallResultOnMainThread() {
let avCaptureSessionMock = MockCaptureSession()
avCaptureSessionMock.canSetSessionPreset = true
let camera = createCameraPlugin(with: avCaptureSessionMock)
let expectation = self.expectation(description: "Result finished")

var resultValue: NSNumber?
camera.createCameraOnSessionQueue(
withName: "acamera",
settings: FCPPlatformMediaSettings.make(
with: FCPPlatformResolutionPreset.medium,
framesPerSecond: nil,
videoBitrate: nil,
audioBitrate: nil,
enableAudio: true
)
) { result, error in
resultValue = result
expectation.fulfill()
}

waitForExpectations(timeout: 30, handler: nil)
XCTAssertNotNil(resultValue)
}

func testDisposeShouldDeallocCamera() {
let avCaptureSessionMock = MockCaptureSession()
avCaptureSessionMock.canSetSessionPreset = true
let camera = createCameraPlugin(with: avCaptureSessionMock)
let createExpectation = self.expectation(description: "create's result block must be called")

camera.createCameraOnSessionQueue(
withName: "acamera",
settings: FCPPlatformMediaSettings.make(
with: .medium,
framesPerSecond: nil,
videoBitrate: nil,
audioBitrate: nil,
enableAudio: true
)
) { result, error in
createExpectation.fulfill()
}

waitForExpectations(timeout: 30, handler: nil)
XCTAssertNotNil(camera.camera)

let disposeExpectation = self.expectation(description: "dispose's result block must be called")
camera.disposeCamera(0) { error in
disposeExpectation.fulfill()
}

waitForExpectations(timeout: 30, handler: nil)
XCTAssertNil(camera.camera, "camera should be deallocated after dispose")
}
}
Loading