Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions packages/camera/camera_avfoundation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.9.22+9

* Migrates `FLTSavePhotoDelegate`, `FLTWritableData`, and `FLTImageStreamHandler` classes to Swift.
* Migrates `CameraProperties` and `QueueUtils` helpers to Swift.

## 0.9.22+8

* Migrates `FLTPermissionServicing` and `FLTCameraPermissionManager` classes to Swift.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

import AVFoundation
import Flutter
import XCTest

@testable import camera_avfoundation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,68 +19,60 @@ final class CameraPropertiesTests: XCTestCase {
func testGetAVCaptureFlashModeForPigeonFlashMode() {
XCTAssertEqual(
AVCaptureDevice.FlashMode.off,
FCPGetAVCaptureFlashModeForPigeonFlashMode(FCPPlatformFlashMode.off))
getAVCaptureFlashMode(for: .off))
XCTAssertEqual(
AVCaptureDevice.FlashMode.auto,
FCPGetAVCaptureFlashModeForPigeonFlashMode(FCPPlatformFlashMode.auto))
getAVCaptureFlashMode(for: .auto))
XCTAssertEqual(
AVCaptureDevice.FlashMode.on,
FCPGetAVCaptureFlashModeForPigeonFlashMode(FCPPlatformFlashMode.always))

// TODO(FirentisTFW): Migrate implementation to throw Swift error in this case.
let exception = ExceptionCatcher.catchException {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be now way to test an assertionFailure. getAVCaptureFlashMode could throw a normal exception but then it would require some handling/assertion in the DefaultCamera for case that never actually happens. I don't think this part of the test provides enough value to justify more changes in this PR

_ = FCPGetAVCaptureFlashModeForPigeonFlashMode(.torch)
}
XCTAssertNotNil(exception)
getAVCaptureFlashMode(for: .always))
}

// MARK: - Video Format Tests

func testGetPixelFormatForPigeonFormat() {
XCTAssertEqual(
kCVPixelFormatType_32BGRA,
FCPGetPixelFormatForPigeonFormat(FCPPlatformImageFormatGroup.bgra8888))
getPixelFormat(for: .bgra8888))
XCTAssertEqual(
kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange,
FCPGetPixelFormatForPigeonFormat(FCPPlatformImageFormatGroup.yuv420))
getPixelFormat(for: .yuv420))
}

// MARK: - Device Orientation Tests

func testGetUIDeviceOrientationForPigeonDeviceOrientation() {
XCTAssertEqual(
UIDeviceOrientation.portraitUpsideDown,
FCPGetUIDeviceOrientationForPigeonDeviceOrientation(FCPPlatformDeviceOrientation.portraitDown)
getUIDeviceOrientation(for: .portraitDown)
)
XCTAssertEqual(
UIDeviceOrientation.landscapeLeft,
FCPGetUIDeviceOrientationForPigeonDeviceOrientation(
FCPPlatformDeviceOrientation.landscapeLeft))
getUIDeviceOrientation(for: .landscapeLeft))
XCTAssertEqual(
UIDeviceOrientation.landscapeRight,
FCPGetUIDeviceOrientationForPigeonDeviceOrientation(
FCPPlatformDeviceOrientation.landscapeRight))
getUIDeviceOrientation(for: .landscapeRight))
XCTAssertEqual(
UIDeviceOrientation.portrait,
FCPGetUIDeviceOrientationForPigeonDeviceOrientation(FCPPlatformDeviceOrientation.portraitUp))
getUIDeviceOrientation(for: .portraitUp))
}

func testGetPigeonDeviceOrientationForUIDeviceOrientation() {
XCTAssertEqual(
FCPPlatformDeviceOrientation.portraitDown,
FCPGetPigeonDeviceOrientationForOrientation(UIDeviceOrientation.portraitUpsideDown))
getPigeonDeviceOrientation(for: .portraitUpsideDown))
XCTAssertEqual(
FCPPlatformDeviceOrientation.landscapeLeft,
FCPGetPigeonDeviceOrientationForOrientation(UIDeviceOrientation.landscapeLeft))
getPigeonDeviceOrientation(for: .landscapeLeft))
XCTAssertEqual(
FCPPlatformDeviceOrientation.landscapeRight,
FCPGetPigeonDeviceOrientationForOrientation(UIDeviceOrientation.landscapeRight))
getPigeonDeviceOrientation(for: .landscapeRight))
XCTAssertEqual(
FCPPlatformDeviceOrientation.portraitUp,
FCPGetPigeonDeviceOrientationForOrientation(UIDeviceOrientation.portrait))
getPigeonDeviceOrientation(for: .portrait))
// Test default case.
XCTAssertEqual(
FCPPlatformDeviceOrientation.portraitUp,
FCPGetPigeonDeviceOrientationForOrientation(UIDeviceOrientation.unknown))
getPigeonDeviceOrientation(for: .unknown))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import AVFoundation
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used to get AVFoundation and Flutter via camera_avfoundation


@testable import camera_avfoundation

// Import Objective-C part of the implementation when SwiftPM is used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import AVFoundation

@testable import camera_avfoundation

// Import Objective-C part of the implementation when SwiftPM is used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import AVFoundation

@testable import camera_avfoundation

// Import Objective-C part of the implementation when SwiftPM is used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import AVFoundation
import Flutter

@testable import camera_avfoundation

// Import Objective-C part of the implementation when SwiftPM is used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import AVFoundation

@testable import camera_avfoundation

// Import Objective-C part of the implementation when SwiftPM is used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import AVFoundation

@testable import camera_avfoundation

// Import Objective-C part of the implementation when SwiftPM is used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import AVFoundation

@testable import camera_avfoundation

// Import Objective-C part of the implementation when SwiftPM is used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import AVFoundation

@testable import camera_avfoundation

// Import Objective-C part of the implementation when SwiftPM is used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import AVFoundation

@testable import camera_avfoundation

// Import Objective-C part of the implementation when SwiftPM is used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import AVFoundation

@testable import camera_avfoundation

// Import Objective-C part of the implementation when SwiftPM is used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import AVFoundation

@testable import camera_avfoundation

// Import Objective-C part of the implementation when SwiftPM is used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import AVFoundation

@testable import camera_avfoundation

// Import Objective-C part of the implementation when SwiftPM is used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import camera_avfoundation
import Flutter

// Import Objective-C part of the implementation when SwiftPM is used.
#if canImport(camera_avfoundation_objc)
import camera_avfoundation_objc
#endif
@testable import camera_avfoundation

/// A mock implementation of `FLTEventChannel` that allows injecting a custom implementation
/// A mock implementation of `EventChannel` that allows injecting a custom implementation
/// for setting a stream handler.
final class MockEventChannel: NSObject, FLTEventChannel {
var setStreamHandlerStub: ((FlutterStreamHandler?) -> Void)?
final class MockEventChannel: EventChannel {
var setStreamHandlerStub: (((any FlutterStreamHandler & NSObjectProtocol)?) -> Void)?

func setStreamHandler(_ handler: (FlutterStreamHandler & NSObjectProtocol)?) {
func setStreamHandler(_ handler: (any FlutterStreamHandler & NSObjectProtocol)?) {
setStreamHandlerStub?(handler)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import Flutter

@testable import camera_avfoundation

// Import Objective-C part of the implementation when SwiftPM is used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import camera_avfoundation
import Flutter

@testable import camera_avfoundation

// Import Objective-C part of the implementation when SwiftPM is used.
#if canImport(camera_avfoundation_objc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import camera_avfoundation
@testable import camera_avfoundation

// Import Objective-C part of the implementation when SwiftPM is used.
#if canImport(camera_avfoundation_objc)
import camera_avfoundation_objc
#endif

/// A mock implementation of `FLTWritableData` that allows injecting a custom implementation
/// A mock implementation of `WritableData` that allows injecting a custom implementation
/// for writing to a file.
final class MockWritableData: NSObject, FLTWritableData {
var writeToFileStub: ((String, NSData.WritingOptions) throws -> Void)?
final class MockWritableData: WritableData {
var writeToFileStub: ((String, Data.WritingOptions) throws -> Void)?

func write(toFile path: String, options writeOptionsMask: NSData.WritingOptions) throws {
func write(to path: String, options: Data.WritingOptions) throws {
if let stub = self.writeToFileStub {
try stub(path, writeOptionsMask)
try stub(path, options)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class QueueUtilsTests: XCTestCase {
func testShouldStayOnMainQueueIfCalledFromMainQueue() {
let expectation = expectation(description: "Block must be run on the main queue")

FLTEnsureToRunOnMainQueue {
ensureToRunOnMainQueue {
if Thread.isMainThread {
expectation.fulfill()
}
Expand All @@ -28,7 +28,7 @@ final class QueueUtilsTests: XCTestCase {
let expectation = expectation(description: "Block must be run on the main queue")

DispatchQueue.global(qos: .default).async {
FLTEnsureToRunOnMainQueue {
ensureToRunOnMainQueue {
if Thread.isMainThread {
expectation.fulfill()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class SavePhotoDelegateTests: XCTestCase {
description: "Must complete with error if failed to capture photo.")
let captureError = NSError(domain: "test", code: 0, userInfo: nil)
let ioQueue = DispatchQueue(label: "test")
let delegate = FLTSavePhotoDelegate(path: "test", ioQueue: ioQueue) { path, error in
let delegate = SavePhotoDelegate(path: "test", ioQueue: ioQueue) { path, error in
XCTAssertEqual(captureError, error as NSError?)
XCTAssertNil(path)
completionExpectation.fulfill()
Expand All @@ -35,7 +35,7 @@ final class SavePhotoDelegateTests: XCTestCase {
let ioQueue = DispatchQueue(label: "test")
let ioError = NSError(
domain: "IOError", code: 0, userInfo: [NSLocalizedDescriptionKey: "Localized IO Error"])
let delegate = FLTSavePhotoDelegate(path: "test", ioQueue: ioQueue) { path, error in
let delegate = SavePhotoDelegate(path: "test", ioQueue: ioQueue) { path, error in
XCTAssertEqual(ioError, error as NSError?)
XCTAssertNil(path)
completionExpectation.fulfill()
Expand All @@ -56,7 +56,7 @@ final class SavePhotoDelegateTests: XCTestCase {
description: "Must complete with file path if succeeds to write file.")
let ioQueue = DispatchQueue(label: "test")
let filePath = "test"
let delegate = FLTSavePhotoDelegate(path: filePath, ioQueue: ioQueue) { path, error in
let delegate = SavePhotoDelegate(path: filePath, ioQueue: ioQueue) { path, error in
XCTAssertNil(error)
XCTAssertEqual(filePath, path)
completionExpectation.fulfill()
Expand Down Expand Up @@ -88,7 +88,7 @@ final class SavePhotoDelegateTests: XCTestCase {
}

let filePath = "test"
let delegate = FLTSavePhotoDelegate(path: filePath, ioQueue: ioQueue) { path, error in
let delegate = SavePhotoDelegate(path: filePath, ioQueue: ioQueue) { path, error in
completionExpectation.fulfill()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

import AVFoundation
import Flutter
import XCTest

@testable import camera_avfoundation
Expand All @@ -12,10 +13,14 @@ import XCTest
import camera_avfoundation_objc
#endif

private class MockImageStreamHandler: FLTImageStreamHandler {
private class MockImageStreamHandler: NSObject, ImageStreamHandler {
var captureSessionQueue: DispatchQueue {
preconditionFailure("Attempted to access unimplemented property: captureSessionQueue")
}

var eventSinkStub: ((Any?) -> Void)?

override var eventSink: FlutterEventSink? {
var eventSink: FlutterEventSink? {
get {
if let stub = eventSinkStub {
return { event in
Expand All @@ -29,6 +34,13 @@ private class MockImageStreamHandler: FLTImageStreamHandler {
}
}

func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink)
-> FlutterError?
{ nil }

func onCancel(withArguments arguments: Any?) -> FlutterError? {
nil
}
}

final class StreamingTests: XCTestCase {
Expand Down
Loading
Loading