Skip to content

Commit

Permalink
Remove logic from mock methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mchudy committed Jan 17, 2025
1 parent f58fb9b commit e3f1afd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,60 @@ NS_ASSUME_NONNULL_BEGIN
// Format/Configuration
@property(nonatomic, strong) AVCaptureDeviceFormat *activeFormat;
@property(nonatomic, strong) NSArray<AVCaptureDeviceFormat *> *formats;
/// Overrides the default implementation of setting active format.
/// @param format The format being set
@property(nonatomic, copy) void (^setActiveFormatStub)(AVCaptureDeviceFormat *format);

// Flash/Torch
@property(nonatomic, assign) BOOL hasFlash;
@property(nonatomic, assign) BOOL hasTorch;
@property(nonatomic, assign) BOOL isTorchAvailable;
@property(nonatomic, assign) AVCaptureTorchMode torchMode;
/// Overrides the default implementation of setting torch mode.
/// @param mode The torch mode being set
@property(nonatomic, copy) void (^setTorchModeStub)(AVCaptureTorchMode mode);
@property(nonatomic, assign) BOOL flashModeSupported;

// Focus
@property(nonatomic, assign) BOOL focusPointOfInterestSupported;
/// Overrides the default implementation of checking if focus mode is supported.
/// @param mode The focus mode to check
/// @return Whether the focus mode is supported
@property(nonatomic, copy) BOOL (^isFocusModeSupportedStub)(AVCaptureFocusMode mode);
@property(nonatomic, assign) AVCaptureFocusMode focusMode;
/// Overrides the default implementation of setting focus mode.
/// @param mode The focus mode being set
@property(nonatomic, copy) void (^setFocusModeStub)(AVCaptureFocusMode mode);
@property(nonatomic, assign) CGPoint focusPointOfInterest;
/// Overrides the default implementation of setting focus point of interest.
/// @param point The focus point being set
@property(nonatomic, copy) void (^setFocusPointOfInterestStub)(CGPoint point);

// Exposure
@property(nonatomic, assign) BOOL exposurePointOfInterestSupported;
@property(nonatomic, assign) AVCaptureExposureMode exposureMode;
@property(nonatomic, assign) BOOL exposureModeSupported;
/// Overrides the default implementation of setting exposure mode.
/// @param mode The exposure mode being set
@property(nonatomic, copy) void (^setExposureModeStub)(AVCaptureExposureMode mode);
@property(nonatomic, assign) CGPoint exposurePointOfInterest;
/// Override the default implementation of setting exposure point of interest.
/// @param point The exposure point being set
@property(nonatomic, copy) void (^setExposurePointOfInterestStub)(CGPoint point);
@property(nonatomic, assign) float minExposureTargetBias;
@property(nonatomic, assign) float maxExposureTargetBias;
/// Overrides the default implementation of setting exposure target bias.
/// @param bias The exposure bias being set
/// @param handler The completion handler to be called
@property(nonatomic, copy) void (^setExposureTargetBiasStub)
(float bias, void (^_Nullable handler)(CMTime));

// Zoom
@property(nonatomic, assign) float maxAvailableVideoZoomFactor;
@property(nonatomic, assign) float minAvailableVideoZoomFactor;
@property(nonatomic, assign) float videoZoomFactor;
/// Overrides the default implementation of setting video zoom factor.
/// @param factor The zoom factor being set
@property(nonatomic, copy) void (^setVideoZoomFactorStub)(float factor);

// Camera Properties
Expand All @@ -60,17 +80,26 @@ NS_ASSUME_NONNULL_BEGIN

// Configuration Lock
@property(nonatomic, assign) BOOL shouldFailConfiguration;
/// Overrides the default implementation of locking device for configuration.
/// @param error Error pointer to be set if lock fails
@property(nonatomic, copy) void (^lockForConfigurationStub)(NSError **error);
/// Overrides the default implementation of unlocking device configuration.
@property(nonatomic, copy) void (^unlockForConfigurationStub)(void);

// Frame Duration
@property(nonatomic, assign) CMTime activeVideoMinFrameDuration;
@property(nonatomic, assign) CMTime activeVideoMaxFrameDuration;
/// Overrides the default implementation of setting minimum frame duration.
/// @param duration The minimum frame duration being set
@property(nonatomic, copy) void (^setActiveVideoMinFrameDurationStub)(CMTime duration);
/// Overrides the default implementation of setting maximum frame duration.
/// @param duration The maximum frame duration being set
@property(nonatomic, copy) void (^setActiveVideoMaxFrameDurationStub)(CMTime duration);

// Input Creation
@property(nonatomic, strong) AVCaptureInput *inputToReturn;
/// Overrides the default implementation of creating capture input.
/// @param error Error pointer to be set if creation fails
@property(nonatomic, copy) void (^createInputStub)(NSError **error);

@end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

// 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.
Expand All @@ -13,7 +14,6 @@
@implementation MockCaptureDeviceController

- (void)setActiveFormat:(AVCaptureDeviceFormat *)format {
_activeFormat = format;
if (self.setActiveFormatStub) {
self.setActiveFormatStub(format);
}
Expand All @@ -24,7 +24,6 @@ - (BOOL)isFlashModeSupported:(AVCaptureFlashMode)mode {
}

- (void)setTorchMode:(AVCaptureTorchMode)mode {
_torchMode = mode;
if (self.setTorchModeStub) {
self.setTorchModeStub(mode);
}
Expand All @@ -38,21 +37,18 @@ - (BOOL)isFocusModeSupported:(AVCaptureFocusMode)mode {
}

- (void)setFocusMode:(AVCaptureFocusMode)mode {
_focusMode = mode;
if (self.setFocusModeStub) {
self.setFocusModeStub(mode);
}
}

- (void)setFocusPointOfInterest:(CGPoint)point {
_focusPointOfInterest = point;
if (self.setFocusPointOfInterestStub) {
self.setFocusPointOfInterestStub(point);
}
}

- (void)setExposureMode:(AVCaptureExposureMode)mode {
_exposureMode = mode;
if (self.setExposureModeStub) {
self.setExposureModeStub(mode);
}
Expand All @@ -68,13 +64,10 @@ - (void)setExposurePointOfInterest:(CGPoint)point {
- (void)setExposureTargetBias:(float)bias completionHandler:(void (^)(CMTime))handler {
if (self.setExposureTargetBiasStub) {
self.setExposureTargetBiasStub(bias, handler);
} else if (handler) {
handler(kCMTimeZero);
}
}

- (void)setVideoZoomFactor:(float)factor {
_videoZoomFactor = factor;
if (self.setVideoZoomFactorStub) {
self.setVideoZoomFactorStub(factor);
}
Expand All @@ -101,14 +94,12 @@ - (void)unlockForConfiguration {
}

- (void)setActiveVideoMinFrameDuration:(CMTime)duration {
_activeVideoMinFrameDuration = duration;
if (self.setActiveVideoMinFrameDurationStub) {
self.setActiveVideoMinFrameDurationStub(duration);
}
}

- (void)setActiveVideoMaxFrameDuration:(CMTime)duration {
_activeVideoMaxFrameDuration = duration;
if (self.setActiveVideoMaxFrameDurationStub) {
self.setActiveVideoMaxFrameDurationStub(duration);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ NS_ASSUME_NONNULL_BEGIN
@end

/// A default implementation of FLTCaptureDeviceControlling protocol which
/// wraps an instance of AVCaptureDevice.
/// wraps an instance of AVCaptureDevice.
@interface FLTDefaultCaptureDeviceController : NSObject <FLTCaptureDeviceControlling>

/// Initializes the controller with the given device.
Expand Down

0 comments on commit e3f1afd

Please sign in to comment.