Skip to content

[camera] Remove OCMock from CameraSettingsTests, CameraMethodChannelTests and CameraSessionPresetsTests #8592

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 7 commits into from
Feb 10, 2025
Merged
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
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+4

* Refactors implementations to reduce usage of OCMock in internal testing.

## 0.9.18+3

* Refactors implementations to reduce usage of OCMock in internal testing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
7FA99E592D22C75300582559 /* CameraExposureTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7FA99E582D22C75300582559 /* CameraExposureTests.m */; };
7FCEDD352D43C2B900EA1CA8 /* MockDeviceOrientationProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 7FCEDD342D43C2B900EA1CA8 /* MockDeviceOrientationProvider.m */; };
7FCEDD362D43C2B900EA1CA8 /* MockCaptureDevice.m in Sources */ = {isa = PBXBuildFile; fileRef = 7FCEDD322D43C2B900EA1CA8 /* MockCaptureDevice.m */; };
7FD582352D57D97C003B1200 /* MockCaptureDeviceFormat.m in Sources */ = {isa = PBXBuildFile; fileRef = 7FD582342D57D97C003B1200 /* MockCaptureDeviceFormat.m */; };
7FD582122D579650003B1200 /* MockWritableData.m in Sources */ = {isa = PBXBuildFile; fileRef = 7FD582112D579650003B1200 /* MockWritableData.m */; };
7FD582202D579ECC003B1200 /* MockCapturePhotoOutput.m in Sources */ = {isa = PBXBuildFile; fileRef = 7FD5821F2D579ECC003B1200 /* MockCapturePhotoOutput.m */; };
978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; };
Expand Down Expand Up @@ -104,6 +105,8 @@
7FCEDD322D43C2B900EA1CA8 /* MockCaptureDevice.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MockCaptureDevice.m; sourceTree = "<group>"; };
7FCEDD332D43C2B900EA1CA8 /* MockDeviceOrientationProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockDeviceOrientationProvider.h; sourceTree = "<group>"; };
7FCEDD342D43C2B900EA1CA8 /* MockDeviceOrientationProvider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MockDeviceOrientationProvider.m; sourceTree = "<group>"; };
7FD582342D57D97C003B1200 /* MockCaptureDeviceFormat.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MockCaptureDeviceFormat.m; sourceTree = "<group>"; };
7FD582362D57D989003B1200 /* MockCaptureDeviceFormat.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockCaptureDeviceFormat.h; sourceTree = "<group>"; };
7FD582112D579650003B1200 /* MockWritableData.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MockWritableData.m; sourceTree = "<group>"; };
7FD582132D57965A003B1200 /* MockWritableData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockWritableData.h; sourceTree = "<group>"; };
7FD5821F2D579ECC003B1200 /* MockCapturePhotoOutput.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MockCapturePhotoOutput.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -205,6 +208,8 @@
7F8FD2272D4BFA8D001AF2C1 /* MockGlobalEventApi.h */,
7FCEDD312D43C2B900EA1CA8 /* MockCaptureDevice.h */,
7FCEDD322D43C2B900EA1CA8 /* MockCaptureDevice.m */,
7FD582362D57D989003B1200 /* MockCaptureDeviceFormat.h */,
7FD582342D57D97C003B1200 /* MockCaptureDeviceFormat.m */,
7FD582212D579ED9003B1200 /* MockCapturePhotoOutput.h */,
7FD5821F2D579ECC003B1200 /* MockCapturePhotoOutput.m */,
7FCEDD332D43C2B900EA1CA8 /* MockDeviceOrientationProvider.h */,
Expand Down Expand Up @@ -516,6 +521,7 @@
7FA99E592D22C75300582559 /* CameraExposureTests.m in Sources */,
E487C86026D686A10034AC92 /* CameraPreviewPauseTests.m in Sources */,
E071CF7427B31DE4006EF3BA /* FLTCamSampleBufferTests.m in Sources */,
7FD582352D57D97C003B1200 /* MockCaptureDeviceFormat.m in Sources */,
7F29EB222D269ED500740257 /* MockEventChannel.m in Sources */,
7F8FD22F2D4D0B88001AF2C1 /* MockFlutterBinaryMessenger.m in Sources */,
E04F108627A87CA600573D0C /* FLTSavePhotoDelegateTests.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ - (void)setUp {
_mockDeviceOrientationProvider = [[MockDeviceOrientationProvider alloc] init];
_mockDevice = mockDevice;

_camera = FLTCreateCamWithCaptureSessionQueueAndMediaSettings(
nil, nil, nil,
^NSObject<FLTCaptureDevice> *(void) {
return mockDevice;
},
_mockDeviceOrientationProvider);
FLTCamConfiguration *configuration = FLTCreateTestCameraConfiguration();
configuration.captureDeviceFactory = ^NSObject<FLTCaptureDevice> *_Nonnull { return mockDevice; };
configuration.deviceOrientationProvider = _mockDeviceOrientationProvider;
_camera = FLTCreateCamWithConfiguration(configuration);
}

- (void)testSetExposurePointWithResult_SetsExposurePointOfInterest {
Expand All @@ -53,7 +51,7 @@ - (void)testSetExposurePointWithResult_SetsExposurePointOfInterest {
[completionExpectation fulfill];
}];

[self waitForExpectationsWithTimeout:1 handler:nil];
[self waitForExpectationsWithTimeout:30 handler:nil];
XCTAssertEqual(setPoint.x, 1.0);
XCTAssertEqual(setPoint.y, 1.0);
}
Expand All @@ -77,7 +75,7 @@ - (void)testSetExposurePoint_WhenNotSupported_ReturnsError {
}];

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

@end
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ - (void)setUp {
_mockDevice = mockDevice;
_mockDeviceOrientationProvider = [[MockDeviceOrientationProvider alloc] init];

_camera = FLTCreateCamWithCaptureSessionQueueAndMediaSettings(
nil, nil, nil,
^NSObject<FLTCaptureDevice> *(void) {
return mockDevice;
},
_mockDeviceOrientationProvider);
FLTCamConfiguration *configuration = FLTCreateTestCameraConfiguration();
configuration.captureDeviceFactory = ^NSObject<FLTCaptureDevice> *_Nonnull { return mockDevice; };
configuration.deviceOrientationProvider = _mockDeviceOrientationProvider;
_camera = FLTCreateCamWithConfiguration(configuration);
}

- (void)testAutoFocusWithContinuousModeSupported_ShouldSetContinuousAutoFocus {
Expand Down Expand Up @@ -175,7 +173,7 @@ - (void)testSetFocusPoint_WhenNotSupported_ReturnsError {
}];

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

@end
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,40 @@
#endif
@import XCTest;
@import AVFoundation;
#import <OCMock/OCMock.h>

#import "MockCameraDeviceDiscoverer.h"
#import "MockCaptureDevice.h"
#import "MockCaptureSession.h"
#import "MockFlutterBinaryMessenger.h"
#import "MockFlutterTextureRegistry.h"
#import "MockGlobalEventApi.h"

@interface CameraMethodChannelTests : XCTestCase
@end

@implementation CameraMethodChannelTests

- (CameraPlugin *)createCameraPlugin {
- (CameraPlugin *)createCameraPluginWithSession:(MockCaptureSession *)mockSession {
return [[CameraPlugin alloc] initWithRegistry:[[MockFlutterTextureRegistry alloc] init]
messenger:[[MockFlutterBinaryMessenger alloc] init]];
messenger:[[MockFlutterBinaryMessenger alloc] init]
globalAPI:[[MockGlobalEventApi alloc] init]
deviceDiscoverer:[[MockCameraDeviceDiscoverer alloc] init]
deviceFactory:^NSObject<FLTCaptureDevice> *(NSString *name) {
return [[MockCaptureDevice alloc] init];
}
captureSessionFactory:^NSObject<FLTCaptureSession> *_Nonnull {
return mockSession;
}
captureDeviceInputFactory:[[MockCaptureDeviceInputFactory alloc] init]];
}

- (void)testCreate_ShouldCallResultOnMainThread {
CameraPlugin *camera = [self createCameraPlugin];
MockCaptureSession *avCaptureSessionMock = [[MockCaptureSession alloc] init];
avCaptureSessionMock.canSetSessionPreset = YES;

XCTestExpectation *expectation = [self expectationWithDescription:@"Result finished"];

// Set up mocks for initWithCameraName method
id avCaptureDeviceInputMock = OCMClassMock([AVCaptureDeviceInput class]);
OCMStub([avCaptureDeviceInputMock deviceInputWithDevice:[OCMArg any] error:[OCMArg anyObjectRef]])
.andReturn([AVCaptureInput alloc]);
CameraPlugin *camera = [self createCameraPluginWithSession:avCaptureSessionMock];

id avCaptureSessionMock = OCMClassMock([AVCaptureSession class]);
OCMStub([avCaptureSessionMock alloc]).andReturn(avCaptureSessionMock);
OCMStub([avCaptureSessionMock canSetSessionPreset:[OCMArg any]]).andReturn(YES);
XCTestExpectation *expectation = [self expectationWithDescription:@"Result finished"];

// Set up method call
__block NSNumber *resultValue;
Expand All @@ -59,15 +65,10 @@ - (void)testCreate_ShouldCallResultOnMainThread {
}

- (void)testDisposeShouldDeallocCamera {
CameraPlugin *camera = [self createCameraPlugin];

id avCaptureDeviceInputMock = OCMClassMock([AVCaptureDeviceInput class]);
OCMStub([avCaptureDeviceInputMock deviceInputWithDevice:[OCMArg any] error:[OCMArg anyObjectRef]])
.andReturn([AVCaptureInput alloc]);
MockCaptureSession *avCaptureSessionMock = [[MockCaptureSession alloc] init];
avCaptureSessionMock.canSetSessionPreset = YES;

id avCaptureSessionMock = OCMClassMock([AVCaptureSession class]);
OCMStub([avCaptureSessionMock alloc]).andReturn(avCaptureSessionMock);
OCMStub([avCaptureSessionMock canSetSessionPreset:[OCMArg any]]).andReturn(YES);
CameraPlugin *camera = [self createCameraPluginWithSession:avCaptureSessionMock];

XCTestExpectation *createExpectation =
[self expectationWithDescription:@"create's result block must be called"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ - (void)testOrientationUpdateMustBeOnCaptureSessionQueue {

[plugin orientationChanged:
[self createMockNotificationForOrientation:UIDeviceOrientationLandscapeLeft]];
[self waitForExpectationsWithTimeout:1 handler:nil];
[self waitForExpectationsWithTimeout:30 handler:nil];
}

- (void)testOrientationChanged_noRetainCycle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ - (void)testRequestCameraPermission_completeWithoutErrorIfPreviouslyAuthorized {
[expectation fulfill];
}
}];
[self waitForExpectationsWithTimeout:1 handler:nil];
[self waitForExpectationsWithTimeout:30 handler:nil];
}
- (void)testRequestCameraPermission_completeWithErrorIfPreviouslyDenied {
XCTestExpectation *expectation =
Expand All @@ -82,7 +82,7 @@ - (void)testRequestCameraPermission_completeWithErrorIfPreviouslyDenied {
[expectation fulfill];
}
}];
[self waitForExpectationsWithTimeout:1 handler:nil];
[self waitForExpectationsWithTimeout:30 handler:nil];
}

- (void)testRequestCameraPermission_completeWithErrorIfRestricted {
Expand All @@ -102,7 +102,7 @@ - (void)testRequestCameraPermission_completeWithErrorIfRestricted {
[expectation fulfill];
}
}];
[self waitForExpectationsWithTimeout:1 handler:nil];
[self waitForExpectationsWithTimeout:30 handler:nil];
}

- (void)testRequestCameraPermission_completeWithoutErrorIfUserGrantAccess {
Expand All @@ -125,7 +125,7 @@ - (void)testRequestCameraPermission_completeWithoutErrorIfUserGrantAccess {
[grantedExpectation fulfill];
}
}];
[self waitForExpectationsWithTimeout:1 handler:nil];
[self waitForExpectationsWithTimeout:30 handler:nil];
}

- (void)testRequestCameraPermission_completeWithErrorIfUserDenyAccess {
Expand Down Expand Up @@ -153,7 +153,7 @@ - (void)testRequestCameraPermission_completeWithErrorIfUserDenyAccess {
}
}];

[self waitForExpectationsWithTimeout:1 handler:nil];
[self waitForExpectationsWithTimeout:30 handler:nil];
}

#pragma mark - audio permissions
Expand All @@ -173,7 +173,7 @@ - (void)testRequestAudioPermission_completeWithoutErrorIfPrevoiuslyAuthorized {
[expectation fulfill];
}
}];
[self waitForExpectationsWithTimeout:1 handler:nil];
[self waitForExpectationsWithTimeout:30 handler:nil];
}

- (void)testRequestAudioPermission_completeWithErrorIfPreviouslyDenied {
Expand All @@ -196,7 +196,7 @@ - (void)testRequestAudioPermission_completeWithErrorIfPreviouslyDenied {
[expectation fulfill];
}
}];
[self waitForExpectationsWithTimeout:1 handler:nil];
[self waitForExpectationsWithTimeout:30 handler:nil];
}

- (void)testRequestAudioPermission_completeWithErrorIfRestricted {
Expand All @@ -216,7 +216,7 @@ - (void)testRequestAudioPermission_completeWithErrorIfRestricted {
[expectation fulfill];
}
}];
[self waitForExpectationsWithTimeout:1 handler:nil];
[self waitForExpectationsWithTimeout:30 handler:nil];
}

- (void)testRequestAudioPermission_completeWithoutErrorIfUserGrantAccess {
Expand All @@ -239,7 +239,7 @@ - (void)testRequestAudioPermission_completeWithoutErrorIfUserGrantAccess {
[grantedExpectation fulfill];
}
}];
[self waitForExpectationsWithTimeout:1 handler:nil];
[self waitForExpectationsWithTimeout:30 handler:nil];
}

- (void)testRequestAudioPermission_completeWithErrorIfUserDenyAccess {
Expand All @@ -265,7 +265,7 @@ - (void)testRequestAudioPermission_completeWithErrorIfUserDenyAccess {
[expectation fulfill];
}
}];
[self waitForExpectationsWithTimeout:1 handler:nil];
[self waitForExpectationsWithTimeout:30 handler:nil];
}

@end
Loading