Skip to content
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

[camera] Remove OCMock from AvailableCamerasTests, CameraOrientationTests and ThreadSafeEventChannelTests #8363

Merged
Merged
Show file tree
Hide file tree
Changes from 32 commits
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
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+2

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

## 0.9.18+1

* Refactors implementations to reduce usage of OCMock in internal testing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@
788A065A27B0E02900533D74 /* StreamingTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 788A065927B0E02900533D74 /* StreamingTest.m */; };
78A318202AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage in Frameworks */ = {isa = PBXBuildFile; productRef = 78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */; };
7D5FCCD42AEF9D0200FB7108 /* CameraSettingsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D5FCCD32AEF9D0200FB7108 /* CameraSettingsTests.m */; };
7F29EB222D269ED500740257 /* MockEventChannel.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F29EB212D269ED500740257 /* MockEventChannel.m */; };
7F29EB292D26A59000740257 /* MockCameraDeviceDiscoverer.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F29EB282D26A59000740257 /* MockCameraDeviceDiscoverer.m */; };
7F29EB412D281C7E00740257 /* MockCaptureSession.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F29EB402D281C7E00740257 /* MockCaptureSession.m */; };
7F56D0382D1EDDCE005676A5 /* CameraPermissionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E0B0D2BA27DFF2AF00E71E4B /* CameraPermissionTests.m */; };
7F87E8022D01FD6F00A3549C /* MockCaptureDeviceController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F87E8012D01FD5600A3549C /* MockCaptureDeviceController.m */; };
7F87E80C2D0325D900A3549C /* MockDeviceOrientationProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F87E80B2D0325D700A3549C /* MockDeviceOrientationProvider.m */; };
7F8FD2292D4BFABF001AF2C1 /* MockGlobalEventApi.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F8FD2282D4BFABF001AF2C1 /* MockGlobalEventApi.m */; };
7F8FD22C2D4D07DD001AF2C1 /* MockFlutterTextureRegistry.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F8FD22B2D4D07DD001AF2C1 /* MockFlutterTextureRegistry.m */; };
7F8FD22F2D4D0B88001AF2C1 /* MockFlutterBinaryMessenger.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F8FD22E2D4D0B88001AF2C1 /* MockFlutterBinaryMessenger.m */; };
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 */; };
978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; };
97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; };
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
Expand Down Expand Up @@ -79,11 +85,23 @@
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
7D5FCCD32AEF9D0200FB7108 /* CameraSettingsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CameraSettingsTests.m; sourceTree = "<group>"; };
7F87E8012D01FD5600A3549C /* MockCaptureDeviceController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MockCaptureDeviceController.m; sourceTree = "<group>"; };
7F87E8032D02FF8C00A3549C /* MockCaptureDeviceController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockCaptureDeviceController.h; sourceTree = "<group>"; };
7F87E80A2D0325B200A3549C /* MockDeviceOrientationProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockDeviceOrientationProvider.h; sourceTree = "<group>"; };
7F87E80B2D0325D700A3549C /* MockDeviceOrientationProvider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MockDeviceOrientationProvider.m; sourceTree = "<group>"; };
7F29EB202D269E4300740257 /* MockEventChannel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockEventChannel.h; sourceTree = "<group>"; };
7F29EB212D269ED500740257 /* MockEventChannel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MockEventChannel.m; sourceTree = "<group>"; };
7F29EB272D26A55300740257 /* MockCameraDeviceDiscoverer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockCameraDeviceDiscoverer.h; sourceTree = "<group>"; };
7F29EB282D26A59000740257 /* MockCameraDeviceDiscoverer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MockCameraDeviceDiscoverer.m; sourceTree = "<group>"; };
7F29EB3E2D281C5800740257 /* MockCaptureSession.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockCaptureSession.h; sourceTree = "<group>"; };
7F29EB402D281C7E00740257 /* MockCaptureSession.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MockCaptureSession.m; sourceTree = "<group>"; };
7F8FD2272D4BFA8D001AF2C1 /* MockGlobalEventApi.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockGlobalEventApi.h; sourceTree = "<group>"; };
7F8FD2282D4BFABF001AF2C1 /* MockGlobalEventApi.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MockGlobalEventApi.m; sourceTree = "<group>"; };
7F8FD22A2D4D07A6001AF2C1 /* MockFlutterTextureRegistry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockFlutterTextureRegistry.h; sourceTree = "<group>"; };
7F8FD22B2D4D07DD001AF2C1 /* MockFlutterTextureRegistry.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MockFlutterTextureRegistry.m; sourceTree = "<group>"; };
7F8FD22D2D4D0B73001AF2C1 /* MockFlutterBinaryMessenger.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockFlutterBinaryMessenger.h; sourceTree = "<group>"; };
7F8FD22E2D4D0B88001AF2C1 /* MockFlutterBinaryMessenger.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MockFlutterBinaryMessenger.m; sourceTree = "<group>"; };
7FA99E582D22C75300582559 /* CameraExposureTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CameraExposureTests.m; sourceTree = "<group>"; };
7FCEDD312D43C2B900EA1CA8 /* MockCaptureDevice.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockCaptureDevice.h; sourceTree = "<group>"; };
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>"; };
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -136,10 +154,7 @@
03BB76692665316900CE5A93 /* RunnerTests */ = {
isa = PBXGroup;
children = (
7F87E80B2D0325D700A3549C /* MockDeviceOrientationProvider.m */,
7F87E80A2D0325B200A3549C /* MockDeviceOrientationProvider.h */,
7F87E8032D02FF8C00A3549C /* MockCaptureDeviceController.h */,
7F87E8012D01FD5600A3549C /* MockCaptureDeviceController.m */,
7F29EB3F2D281C6D00740257 /* Mocks */,
7D5FCCD32AEF9D0200FB7108 /* CameraSettingsTests.m */,
03BB766A2665316900CE5A93 /* CameraFocusTests.m */,
7FA99E582D22C75300582559 /* CameraExposureTests.m */,
Expand Down Expand Up @@ -173,6 +188,29 @@
name = Frameworks;
sourceTree = "<group>";
};
7F29EB3F2D281C6D00740257 /* Mocks */ = {
isa = PBXGroup;
children = (
7F8FD22D2D4D0B73001AF2C1 /* MockFlutterBinaryMessenger.h */,
7F8FD22E2D4D0B88001AF2C1 /* MockFlutterBinaryMessenger.m */,
7F8FD22A2D4D07A6001AF2C1 /* MockFlutterTextureRegistry.h */,
7F8FD22B2D4D07DD001AF2C1 /* MockFlutterTextureRegistry.m */,
7F8FD2282D4BFABF001AF2C1 /* MockGlobalEventApi.m */,
7F8FD2272D4BFA8D001AF2C1 /* MockGlobalEventApi.h */,
7FCEDD312D43C2B900EA1CA8 /* MockCaptureDevice.h */,
7FCEDD322D43C2B900EA1CA8 /* MockCaptureDevice.m */,
7FCEDD332D43C2B900EA1CA8 /* MockDeviceOrientationProvider.h */,
7FCEDD342D43C2B900EA1CA8 /* MockDeviceOrientationProvider.m */,
7F29EB282D26A59000740257 /* MockCameraDeviceDiscoverer.m */,
7F29EB272D26A55300740257 /* MockCameraDeviceDiscoverer.h */,
7F29EB202D269E4300740257 /* MockEventChannel.h */,
7F29EB212D269ED500740257 /* MockEventChannel.m */,
7F29EB3E2D281C5800740257 /* MockCaptureSession.h */,
7F29EB402D281C7E00740257 /* MockCaptureSession.m */,
);
path = Mocks;
sourceTree = "<group>";
};
9740EEB11CF90186004384FC /* Flutter */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -463,21 +501,27 @@
7F56D0382D1EDDCE005676A5 /* CameraPermissionTests.m in Sources */,
E0F95E3D27A32AB900699390 /* CameraPropertiesTests.m in Sources */,
03BB766B2665316900CE5A93 /* CameraFocusTests.m in Sources */,
7F87E8022D01FD6F00A3549C /* MockCaptureDeviceController.m in Sources */,
7D5FCCD42AEF9D0200FB7108 /* CameraSettingsTests.m in Sources */,
7F8FD2292D4BFABF001AF2C1 /* MockGlobalEventApi.m in Sources */,
7FA99E592D22C75300582559 /* CameraExposureTests.m in Sources */,
E487C86026D686A10034AC92 /* CameraPreviewPauseTests.m in Sources */,
7F87E80C2D0325D900A3549C /* MockDeviceOrientationProvider.m in Sources */,
E071CF7427B31DE4006EF3BA /* FLTCamSampleBufferTests.m in Sources */,
7F29EB222D269ED500740257 /* MockEventChannel.m in Sources */,
7F8FD22F2D4D0B88001AF2C1 /* MockFlutterBinaryMessenger.m in Sources */,
E04F108627A87CA600573D0C /* FLTSavePhotoDelegateTests.m in Sources */,
43ED1537282570DE00EB00DE /* AvailableCamerasTest.m in Sources */,
E0CDBAC227CD9729002561D9 /* CameraTestUtils.m in Sources */,
334733EA2668111C00DCC49E /* CameraOrientationTests.m in Sources */,
CEF6611A2B5E36A500D33FD4 /* CameraSessionPresetsTests.m in Sources */,
E032F250279F5E94009E9028 /* CameraCaptureSessionQueueRaceConditionTests.m in Sources */,
7F29EB292D26A59000740257 /* MockCameraDeviceDiscoverer.m in Sources */,
788A065A27B0E02900533D74 /* StreamingTest.m in Sources */,
E0C6E2022770F01A00EA6AA3 /* ThreadSafeEventChannelTests.m in Sources */,
7F29EB412D281C7E00740257 /* MockCaptureSession.m in Sources */,
E01EE4A82799F3A5008C1950 /* QueueUtilsTests.m in Sources */,
7FCEDD352D43C2B900EA1CA8 /* MockDeviceOrientationProvider.m in Sources */,
7FCEDD362D43C2B900EA1CA8 /* MockCaptureDevice.m in Sources */,
7F8FD22C2D4D07DD001AF2C1 /* MockFlutterTextureRegistry.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,57 @@
#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 AvailableCamerasTest : XCTestCase

@end

@implementation AvailableCamerasTest

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

- (void)testAvailableCamerasShouldReturnAllCamerasOnMultiCameraIPhone {
CameraPlugin *camera = [[CameraPlugin alloc] initWithRegistry:nil messenger:nil];
MockCameraDeviceDiscoverer *mockDeviceDiscoverer = [[MockCameraDeviceDiscoverer alloc] init];
CameraPlugin *cameraPlugin = [self createCameraPluginWithDeviceDiscoverer:mockDeviceDiscoverer];

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

// iPhone 13 Cameras:
AVCaptureDevice *wideAngleCamera = OCMClassMock([AVCaptureDevice class]);
OCMStub([wideAngleCamera uniqueID]).andReturn(@"0");
OCMStub([wideAngleCamera position]).andReturn(AVCaptureDevicePositionBack);
MockCaptureDevice *wideAngleCamera = [[MockCaptureDevice alloc] init];
wideAngleCamera.uniqueID = @"0";
wideAngleCamera.position = AVCaptureDevicePositionBack;

AVCaptureDevice *frontFacingCamera = OCMClassMock([AVCaptureDevice class]);
OCMStub([frontFacingCamera uniqueID]).andReturn(@"1");
OCMStub([frontFacingCamera position]).andReturn(AVCaptureDevicePositionFront);
MockCaptureDevice *frontFacingCamera = [[MockCaptureDevice alloc] init];
frontFacingCamera.uniqueID = @"1";
frontFacingCamera.position = AVCaptureDevicePositionFront;

AVCaptureDevice *ultraWideCamera = OCMClassMock([AVCaptureDevice class]);
OCMStub([ultraWideCamera uniqueID]).andReturn(@"2");
OCMStub([ultraWideCamera position]).andReturn(AVCaptureDevicePositionBack);
MockCaptureDevice *ultraWideCamera = [[MockCaptureDevice alloc] init];
ultraWideCamera.uniqueID = @"2";
ultraWideCamera.position = AVCaptureDevicePositionBack;

AVCaptureDevice *telephotoCamera = OCMClassMock([AVCaptureDevice class]);
OCMStub([telephotoCamera uniqueID]).andReturn(@"3");
OCMStub([telephotoCamera position]).andReturn(AVCaptureDevicePositionBack);
MockCaptureDevice *telephotoCamera = [[MockCaptureDevice alloc] init];
telephotoCamera.uniqueID = @"3";
telephotoCamera.position = AVCaptureDevicePositionBack;

NSMutableArray *requiredTypes =
[@[ AVCaptureDeviceTypeBuiltInWideAngleCamera, AVCaptureDeviceTypeBuiltInTelephotoCamera ]
Expand All @@ -43,21 +67,23 @@ - (void)testAvailableCamerasShouldReturnAllCamerasOnMultiCameraIPhone {
[requiredTypes addObject:AVCaptureDeviceTypeBuiltInUltraWideCamera];
}

id discoverySessionMock = OCMClassMock([AVCaptureDeviceDiscoverySession class]);
OCMStub([discoverySessionMock discoverySessionWithDeviceTypes:requiredTypes
mediaType:AVMediaTypeVideo
position:AVCaptureDevicePositionUnspecified])
.andReturn(discoverySessionMock);

NSMutableArray *cameras = [NSMutableArray array];
[cameras addObjectsFromArray:@[ wideAngleCamera, frontFacingCamera, telephotoCamera ]];
if (@available(iOS 13.0, *)) {
[cameras addObject:ultraWideCamera];
}
OCMStub([discoverySessionMock devices]).andReturn([NSArray arrayWithArray:cameras]);

mockDeviceDiscoverer.discoverySessionStub = ^NSArray<NSObject<FLTCaptureDevice> *> *_Nullable(
NSArray<AVCaptureDeviceType> *_Nonnull deviceTypes, AVMediaType _Nonnull mediaType,
AVCaptureDevicePosition position) {
XCTAssertEqualObjects(deviceTypes, requiredTypes);
XCTAssertEqual(mediaType, AVMediaTypeVideo);
XCTAssertEqual(position, AVCaptureDevicePositionUnspecified);
return cameras;
};

__block NSArray<FCPPlatformCameraDescription *> *resultValue;
[camera
[cameraPlugin
availableCamerasWithCompletion:^(NSArray<FCPPlatformCameraDescription *> *_Nullable result,
FlutterError *_Nullable error) {
XCTAssertNil(error);
Expand All @@ -74,17 +100,19 @@ - (void)testAvailableCamerasShouldReturnAllCamerasOnMultiCameraIPhone {
}
}
- (void)testAvailableCamerasShouldReturnOneCameraOnSingleCameraIPhone {
CameraPlugin *camera = [[CameraPlugin alloc] initWithRegistry:nil messenger:nil];
MockCameraDeviceDiscoverer *mockDeviceDiscoverer = [[MockCameraDeviceDiscoverer alloc] init];
CameraPlugin *cameraPlugin = [self createCameraPluginWithDeviceDiscoverer:mockDeviceDiscoverer];

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

// iPhone 8 Cameras:
AVCaptureDevice *wideAngleCamera = OCMClassMock([AVCaptureDevice class]);
OCMStub([wideAngleCamera uniqueID]).andReturn(@"0");
OCMStub([wideAngleCamera position]).andReturn(AVCaptureDevicePositionBack);
MockCaptureDevice *wideAngleCamera = [[MockCaptureDevice alloc] init];
wideAngleCamera.uniqueID = @"0";
wideAngleCamera.position = AVCaptureDevicePositionBack;

AVCaptureDevice *frontFacingCamera = OCMClassMock([AVCaptureDevice class]);
OCMStub([frontFacingCamera uniqueID]).andReturn(@"1");
OCMStub([frontFacingCamera position]).andReturn(AVCaptureDevicePositionFront);
MockCaptureDevice *frontFacingCamera = [[MockCaptureDevice alloc] init];
frontFacingCamera.uniqueID = @"1";
frontFacingCamera.position = AVCaptureDevicePositionFront;

NSMutableArray *requiredTypes =
[@[ AVCaptureDeviceTypeBuiltInWideAngleCamera, AVCaptureDeviceTypeBuiltInTelephotoCamera ]
Expand All @@ -93,18 +121,20 @@ - (void)testAvailableCamerasShouldReturnOneCameraOnSingleCameraIPhone {
[requiredTypes addObject:AVCaptureDeviceTypeBuiltInUltraWideCamera];
}

id discoverySessionMock = OCMClassMock([AVCaptureDeviceDiscoverySession class]);
OCMStub([discoverySessionMock discoverySessionWithDeviceTypes:requiredTypes
mediaType:AVMediaTypeVideo
position:AVCaptureDevicePositionUnspecified])
.andReturn(discoverySessionMock);

NSMutableArray *cameras = [NSMutableArray array];
[cameras addObjectsFromArray:@[ wideAngleCamera, frontFacingCamera ]];
OCMStub([discoverySessionMock devices]).andReturn([NSArray arrayWithArray:cameras]);

mockDeviceDiscoverer.discoverySessionStub = ^NSArray<NSObject<FLTCaptureDevice> *> *_Nullable(
NSArray<AVCaptureDeviceType> *_Nonnull deviceTypes, AVMediaType _Nonnull mediaType,
AVCaptureDevicePosition position) {
XCTAssertEqualObjects(deviceTypes, requiredTypes);
XCTAssertEqual(mediaType, AVMediaTypeVideo);
XCTAssertEqual(position, AVCaptureDevicePositionUnspecified);
return cameras;
};

__block NSArray<FCPPlatformCameraDescription *> *resultValue;
[camera
[cameraPlugin
availableCamerasWithCompletion:^(NSArray<FCPPlatformCameraDescription *> *_Nullable result,
FlutterError *_Nullable error) {
XCTAssertNil(error);
Expand Down
Loading