Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.9k
[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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
5de2587a7b3c02c91bbae2608e45f261951effbaae145ccd20f7eada5464d7339334e16989e8667254090b51e01ff8fd05974e728612c42529870d5828f73eaa7c2234b748423b2b4a975a58a0b5743e74237804File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| 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.
Uh oh!
There was an error while loading. Please reload this page.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| 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") | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.