Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5070536
Introduce protocols and remove OCMock from CameraFocusTests
mchudy Dec 27, 2024
335deed
Migrate CameraExposureTests
mchudy Dec 6, 2024
ca581d7
Format code
mchudy Dec 27, 2024
2e3c8e7
Use DI for mocking dependencies
mchudy Dec 30, 2024
c96e9da
Fix CI
mchudy Dec 30, 2024
7155838
Fix imports
mchudy Dec 30, 2024
3cd5341
Fix imports
mchudy Dec 30, 2024
8256579
Another try to fix imports
mchudy Dec 30, 2024
27f31c0
Change order in modulemap
mchudy Dec 30, 2024
7a25909
Add FLTCamMediaSettingsAVWrapper to module map
mchudy Dec 30, 2024
cdb1578
Remove new protocols from modulemap
mchudy Dec 31, 2024
486686a
Add header search path
mchudy Dec 31, 2024
2a070ca
Fix formatting
mchudy Dec 31, 2024
04f1e8b
Flatten the structure
mchudy Jan 2, 2025
0d81c7f
Remove OCMock from CameraOrientationTests
mchudy Jan 2, 2025
bb1cf1a
Add protocol for event channel
mchudy Jan 2, 2025
de26f9c
Remove OCMock from ThreadSafeEventChannelTests
mchudy Jan 2, 2025
4b45f30
Introduce FLTCameraDeviceDiscovering
mchudy Jan 2, 2025
abb1fdb
Update changelog
mchudy Jan 2, 2025
96e300a
Make default implementations for protocols and clean up the DI to mak…
mchudy Jan 3, 2025
88f9fe6
Introduce new protocol for creating capture inputs
mchudy Jan 6, 2025
0063b6f
Fix DI and tests
mchudy Jan 7, 2025
327233d
Rename FLTCaptureDeviceControlling to FLTCaptureDevice
mchudy Jan 9, 2025
8235080
Merge remote-tracking branch 'upstream/main' into feature/camera-ocmo…
mchudy Jan 14, 2025
37bb576
Merge remote-tracking branch 'upstream/main' into feature/camera-ocmo…
mchudy Jan 24, 2025
6cdf473
Fix conflicts
mchudy Jan 24, 2025
469bc8e
Add doc comments
mchudy Jan 24, 2025
5ea3480
Rename property
mchudy Jan 24, 2025
7f20088
Fix formatting
mchudy Jan 24, 2025
64c3d1f
Code cleanup
mchudy Jan 30, 2025
1ad5966
Fix warning with nils being passed in tests by introducing new mocks
mchudy Jan 31, 2025
40cce59
Reintroduce default protocol wrappers and rely on NSObject for safer …
mchudy Feb 2, 2025
fc0e826
Fix nits
mchudy Feb 6, 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
Prev Previous commit
Next Next commit
Migrate CameraExposureTests
  • Loading branch information
mchudy committed Dec 30, 2024
commit 335deed5335a51a50f0ecc28c624f77059381c18

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,73 @@
@import camera_avfoundation;
@import XCTest;
@import AVFoundation;
#import <OCMock/OCMock.h>

@interface FLTCam : NSObject <FlutterTexture,
AVCaptureVideoDataOutputSampleBufferDelegate,
AVCaptureAudioDataOutputSampleBufferDelegate>

- (void)setExposurePointWithResult:(FlutterResult)result x:(double)x y:(double)y;
@end
#import "MockCaptureDeviceController.h"
#import "MockDeviceOrientationProvider.h"

@interface CameraExposureTests : XCTestCase
@property(readonly, nonatomic) FLTCam *camera;
@property(readonly, nonatomic) id mockDevice;
@property(readonly, nonatomic) id mockUIDevice;
@property(readonly, nonatomic) MockCaptureDeviceController *mockDevice;
@property(readonly, nonatomic) MockDeviceOrientationProvider *mockDeviceOrientationProvider;
@end

@implementation CameraExposureTests

- (void)setUp {
_camera = [[FLTCam alloc] init];
_mockDevice = OCMClassMock([AVCaptureDevice class]);
_mockUIDevice = OCMPartialMock([UIDevice currentDevice]);
}

- (void)tearDown {
[_mockDevice stopMocking];
[_mockUIDevice stopMocking];
_mockDevice = [[MockCaptureDeviceController alloc] init];
_mockDeviceOrientationProvider = [[MockDeviceOrientationProvider alloc] init];

[_camera setValue:_mockDevice forKey:@"captureDevice"];
[_camera setValue:_mockDeviceOrientationProvider forKey:@"deviceOrientationProvider"];
}

- (void)testSetExpsourePointWithResult_SetsExposurePointOfInterest {
- (void)testSetExposurePointWithResult_SetsExposurePointOfInterest {
// UI is currently in landscape left orientation
OCMStub([(UIDevice *)_mockUIDevice orientation]).andReturn(UIDeviceOrientationLandscapeLeft);
_mockDeviceOrientationProvider.orientation = UIDeviceOrientationLandscapeLeft;
// Exposure point of interest is supported
OCMStub([_mockDevice isExposurePointOfInterestSupported]).andReturn(true);
// Set mock device as the current capture device
[_camera setValue:_mockDevice forKey:@"captureDevice"];
_mockDevice.isExposurePointOfInterestSupported = YES;

// Verify the focus point of interest has been set
__block CGPoint setPoint = CGPointZero;
_mockDevice.setExposurePointOfInterestStub = ^(CGPoint point) {
if (CGPointEqualToPoint(CGPointMake(1, 1), point)) {
setPoint = point;
}
};

// Run test
[_camera
setExposurePointWithResult:^void(id _Nullable result) {
}
x:1
y:1];
XCTestExpectation *completionExpectation = [self expectationWithDescription:@"Completion called"];
[_camera setExposurePoint:[FCPPlatformPoint makeWithX:1 y:1]
withCompletion:^(FlutterError * _Nullable error) {
XCTAssertNil(error);
[completionExpectation fulfill];
}];

// Verify the focus point of interest has been set
OCMVerify([_mockDevice setExposurePointOfInterest:CGPointMake(1, 1)]);
[self waitForExpectationsWithTimeout:1 handler:nil];
XCTAssertEqual(setPoint.x, 1.0);
XCTAssertEqual(setPoint.y, 1.0);
}

- (void)testSetExposurePoint_WhenNotSupported_ReturnsError {
// UI is currently in landscape left orientation
_mockDeviceOrientationProvider.orientation = UIDeviceOrientationLandscapeLeft;
// Exposure point of interest is not supported
_mockDevice.isExposurePointOfInterestSupported = NO;

XCTestExpectation *expectation = [self expectationWithDescription:@"Completion with error"];

// Run
[_camera setExposurePoint:[FCPPlatformPoint makeWithX:1 y:1]
withCompletion:^(FlutterError *_Nullable error) {
XCTAssertNotNil(error);
XCTAssertEqualObjects(error.code, @"setExposurePointFailed");
XCTAssertEqualObjects(error.message, @"Device does not have exposure point capabilities");
[expectation fulfill];
}];

// Verify
[self waitForExpectationsWithTimeout:1 handler:nil];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ - (void)setUp {
_camera = [[FLTCam alloc] init];
_mockDevice = [[MockCaptureDeviceController alloc] init];
_mockDeviceOrientationProvider = [[MockDeviceOrientationProvider alloc] init];

[_camera setValue:_mockDevice forKey:@"captureDevice"];
[_camera setValue:_mockDeviceOrientationProvider forKey:@"deviceOrientationProvider"];
}

- (void)testAutoFocusWithContinuousModeSupported_ShouldSetContinuousAutoFocus {
Expand Down Expand Up @@ -127,15 +130,11 @@ - (void)testLockedFocusWithModeNotSupported_ShouldSetNothing {
[_camera applyFocusMode:FCPPlatformFocusModeLocked onDevice:_mockDevice];
}

// TODO(mchudy): replace setValue with proper DI
- (void)testSetFocusPointWithResult_SetsFocusPointOfInterest {
// UI is currently in landscape left orientation
[_camera setValue:_mockDeviceOrientationProvider forKey:@"deviceOrientationProvider"];
_mockDeviceOrientationProvider.orientation = UIDeviceOrientationLandscapeLeft;
// Focus point of interest is supported
_mockDevice.isFocusPointOfInterestSupported = YES;
// Set mock device as the current capture device
[_camera setValue:_mockDevice forKey:@"captureDevice"];

__block BOOL setFocusPointOfInterestCalled = NO;
_mockDevice.setFocusPointOfInterestStub = ^(CGPoint point) {
Expand All @@ -153,4 +152,25 @@ - (void)testSetFocusPointWithResult_SetsFocusPointOfInterest {
XCTAssertTrue(setFocusPointOfInterestCalled);
}

- (void)testSetFocusPoint_WhenNotSupported_ReturnsError {
// UI is currently in landscape left orientation
_mockDeviceOrientationProvider.orientation = UIDeviceOrientationLandscapeLeft;
// Exposure point of interest is not supported
_mockDevice.isFocusPointOfInterestSupported = NO;

XCTestExpectation *expectation = [self expectationWithDescription:@"Completion with error"];

// Run
[_camera setFocusPoint:[FCPPlatformPoint makeWithX:1 y:1]
withCompletion:^(FlutterError *_Nullable error) {
XCTAssertNotNil(error);
XCTAssertEqualObjects(error.code, @"setFocusPointFailed");
XCTAssertEqualObjects(error.message, @"Device does not have focus point capabilities");
[expectation fulfill];
}];

// Verify
[self waitForExpectationsWithTimeout:1 handler:nil];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#import <OCMock/OCMock.h>

#import "MockCaptureDeviceController.h"

@interface StubGlobalEventApi : FCPCameraGlobalEventApi
@property(nonatomic) BOOL called;
@property(nonatomic) FCPPlatformDeviceOrientation lastOrientation;
Expand All @@ -35,10 +37,21 @@ - (FlutterBinaryMessengerConnection)setMessageHandlerOnChannel:(nonnull NSString
#pragma mark -

@interface CameraOrientationTests : XCTestCase
@property(readonly, nonatomic) FLTCam *camera;
@property(readonly, nonatomic) MockCaptureDeviceController *mockDevice;
@property(readonly, nonatomic) StubGlobalEventApi *eventAPI;
@end

@implementation CameraOrientationTests

- (void)setUp {
[super setUp];
_mockDevice = [[MockCaptureDeviceController alloc] init];
_camera = [[FLTCam alloc] init];

[_camera setValue:_mockDevice forKey:@"captureDevice"];
}

// Ensure that the given queue and then the main queue have both cycled, to wait for any pending
// async events that may have been bounced between them.
- (void)waitForRoundTripWithQueue:(dispatch_queue_t)queue {
Expand Down Expand Up @@ -97,13 +110,13 @@ - (void)testOrientationNotificationsNotCalledForFaceDown {
- (void)testOrientationUpdateMustBeOnCaptureSessionQueue {
XCTestExpectation *queueExpectation = [self
expectationWithDescription:@"Orientation update must happen on the capture session queue"];

CameraPlugin *camera = [[CameraPlugin alloc] initWithRegistry:nil messenger:nil];
const char *captureSessionQueueSpecific = "capture_session_queue";
dispatch_queue_set_specific(camera.captureSessionQueue, captureSessionQueueSpecific,
(void *)captureSessionQueueSpecific, NULL);
FLTCam *mockCam = OCMClassMock([FLTCam class]);
camera.camera = mockCam;

OCMStub([mockCam setDeviceOrientation:UIDeviceOrientationLandscapeLeft])
.andDo(^(NSInvocation *invocation) {
if (dispatch_get_specific(captureSessionQueueSpecific)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ - (void)testCaptureToFile_mustReportFileExtensionWithJpgWhenHEVCNotAvailableAndF
});
[self waitForExpectationsWithTimeout:1 handler:nil];
}
//

- (void)testCaptureToFile_handlesTorchMode {
XCTestExpectation *pathExpectation =
[self expectationWithDescription:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, assign) BOOL flashModeSupported;

// Focus
@property(nonatomic, assign) BOOL focusPointOfInterestSupported;
@property(nonatomic, assign) BOOL isFocusPointOfInterestSupported;
@property(nonatomic, copy) BOOL (^isFocusModeSupportedStub)(AVCaptureFocusMode mode);
@property(nonatomic, assign) AVCaptureFocusMode focusMode;
@property(nonatomic, copy) void (^setFocusModeStub)(AVCaptureFocusMode mode);
@property(nonatomic, assign) CGPoint focusPointOfInterest;
@property(nonatomic, copy) void (^setFocusPointOfInterestStub)(CGPoint point);

// Exposure
@property(nonatomic, assign) BOOL exposurePointOfInterestSupported;
@property(nonatomic, assign) BOOL isExposurePointOfInterestSupported;
@property(nonatomic, assign) AVCaptureExposureMode exposureMode;
@property(nonatomic, assign) BOOL exposureModeSupported;
@property(nonatomic, copy) void (^setExposureModeStub)(AVCaptureExposureMode mode);
Expand Down Expand Up @@ -72,9 +72,6 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, strong) AVCaptureInput *inputToReturn;
@property(nonatomic, copy) void (^createInputStub)(NSError **error);

@property(nonatomic, assign) BOOL isExposurePointOfInterestSupported;
@property(nonatomic, assign) BOOL isFocusPointOfInterestSupported;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ - (void)setExposurePointOfInterest:(CGPoint)point {
- (void)setExposureTargetBias:(float)bias completionHandler:(void (^)(CMTime))handler {
if (self.setExposureTargetBiasStub) {
self.setExposureTargetBiasStub(bias, handler);
} else if (handler) {
handler(kCMTimeZero);
}
}

Expand Down Expand Up @@ -123,5 +125,4 @@ - (AVCaptureInput *)createInput:(NSError *_Nullable *_Nullable)error {
return self.inputToReturn;
}


@end

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ - (BOOL)isFlashModeSupported:(AVCaptureFlashMode)mode {

// Focus
- (BOOL)isFocusPointOfInterestSupported {
return self.device.isFocusPointOfInterestSupported;
return self.device.isFocusPointOfInterestSupported;
}

- (BOOL)isFocusModeSupported:(AVCaptureFocusMode)mode {
Expand Down