@@ -19,13 +19,15 @@ final class FLTCamSetDeviceOrientationTests: XCTestCase {
19
19
let mockCapturePhotoOutput = MockCapturePhotoOutput ( )
20
20
let mockPhotoCaptureConnection = MockCaptureConnection ( )
21
21
mockPhotoCaptureConnection. isVideoOrientationSupported = true
22
+ mockPhotoCaptureConnection. isVideoRotationAngleSupported = true
22
23
23
24
mockCapturePhotoOutput. connectionWithMediaTypeStub = { _ in mockPhotoCaptureConnection }
24
25
camera. capturePhotoOutput = mockCapturePhotoOutput
25
26
26
27
let mockCaptureVideoDataOutput = MockCaptureVideoDataOutput ( )
27
28
let mockVideoCaptureConnection = MockCaptureConnection ( )
28
29
mockVideoCaptureConnection. isVideoOrientationSupported = true
30
+ mockVideoCaptureConnection. isVideoRotationAngleSupported = true
29
31
30
32
mockCaptureVideoDataOutput. connectionWithMediaTypeStub = { _ in mockVideoCaptureConnection }
31
33
camera. captureVideoOutput = mockCaptureVideoDataOutput
@@ -35,72 +37,72 @@ final class FLTCamSetDeviceOrientationTests: XCTestCase {
35
37
36
38
func testSetDeviceOrientation_setsOrientationsOfCaptureConnections( ) {
37
39
let ( camera, mockPhotoCaptureConnection, mockVideoCaptureConnection) = createCamera ( )
38
- var photoSetVideoOrientationCalled = false
39
- mockPhotoCaptureConnection. setVideoOrientationStub = { orientation in
40
+
41
+ let photoSetVideoOrientationExpectation = expectation ( description: " photo setVideoRotationAngle called " )
42
+ mockPhotoCaptureConnection. setVideoRotationAngleStub = { orientation in
40
43
// Device orientation is flipped compared to video orientation. When UIDeviceOrientation
41
44
// is landscape left the video orientation should be landscape right.
42
- XCTAssertEqual ( orientation, . landscapeRight )
43
- photoSetVideoOrientationCalled = true
45
+ XCTAssertEqual ( orientation, 180 )
46
+ photoSetVideoOrientationExpectation . fulfill ( )
44
47
}
45
-
46
- var videoSetVideoOrientationCalled = false
47
- mockVideoCaptureConnection. setVideoOrientationStub = { orientation in
48
+
49
+ let videoSetVideoOrientationExpectation = expectation ( description : " video setVideoRotationAngle called " )
50
+ mockVideoCaptureConnection. setVideoRotationAngleStub = { orientation in
48
51
// Device orientation is flipped compared to video orientation. When UIDeviceOrientation
49
52
// is landscape left the video orientation should be landscape right.
50
- XCTAssertEqual ( orientation, . landscapeRight )
51
- videoSetVideoOrientationCalled = true
53
+ XCTAssertEqual ( orientation, 180 )
54
+ videoSetVideoOrientationExpectation . fulfill ( )
52
55
}
53
56
54
57
camera. deviceOrientation = . landscapeLeft
55
-
56
- XCTAssertTrue ( photoSetVideoOrientationCalled)
57
- XCTAssertTrue ( videoSetVideoOrientationCalled)
58
+
59
+ waitForExpectations ( timeout: 30 , handler: nil )
58
60
}
59
61
60
62
func
61
63
testSetDeviceOrientation_setsLockedOrientationsOfCaptureConnection_ifCaptureOrientationIsLocked( )
62
64
{
63
65
let ( camera, mockPhotoCaptureConnection, mockVideoCaptureConnection) = createCamera ( )
64
- var photoSetVideoOrientationCalled = false
65
- mockPhotoCaptureConnection. setVideoOrientationStub = { orientation in
66
- XCTAssertEqual ( orientation, . portraitUpsideDown)
67
- photoSetVideoOrientationCalled = true
66
+ let photoSetVideoOrientationExpectation = expectation ( description: " photo setVideoRotationAngle called " )
67
+ photoSetVideoOrientationExpectation. expectedFulfillmentCount = 2
68
+ mockPhotoCaptureConnection. setVideoRotationAngleStub = { orientation in
69
+ XCTAssertEqual ( orientation, 270 )
70
+ photoSetVideoOrientationExpectation. fulfill ( )
68
71
}
69
-
70
- var videoSetVideoOrientationCalled = false
71
- mockVideoCaptureConnection. setVideoOrientationStub = { orientation in
72
- XCTAssertEqual ( orientation, . portraitUpsideDown)
73
- videoSetVideoOrientationCalled = true
72
+
73
+ let videoSetVideoOrientationExpectation = expectation ( description: " video setVideoRotationAngle called " )
74
+ videoSetVideoOrientationExpectation. expectedFulfillmentCount = 2
75
+ mockVideoCaptureConnection. setVideoRotationAngleStub = { orientation in
76
+ XCTAssertEqual ( orientation, 270 )
77
+ videoSetVideoOrientationExpectation. fulfill ( )
74
78
}
75
-
76
79
camera. lockCaptureOrientation ( FCPPlatformDeviceOrientation . portraitDown)
77
80
78
81
camera. deviceOrientation = . landscapeLeft
79
-
80
- XCTAssertTrue ( photoSetVideoOrientationCalled)
81
- XCTAssertTrue ( videoSetVideoOrientationCalled)
82
+
83
+ waitForExpectations ( timeout: 30 , handler: nil )
82
84
}
83
85
84
86
func testSetDeviceOrientation_doesNotSetOrientations_ifRecordingIsInProgress( ) {
85
87
let ( camera, mockPhotoCaptureConnection, mockVideoCaptureConnection) = createCamera ( )
86
88
87
89
camera. startVideoRecording ( completion: { _ in } , messengerForStreaming: nil )
88
90
89
- mockPhotoCaptureConnection. setVideoOrientationStub = { _ in XCTFail ( ) }
90
- mockVideoCaptureConnection. setVideoOrientationStub = { _ in XCTFail ( ) }
91
+ mockPhotoCaptureConnection. setVideoRotationAngleStub = { _ in XCTFail ( ) }
92
+ mockVideoCaptureConnection. setVideoRotationAngleStub = { _ in XCTFail ( ) }
91
93
92
94
camera. deviceOrientation = . landscapeLeft
93
95
}
94
96
95
97
func testSetDeviceOrientation_doesNotSetOrientations_forDuplicateUpdates( ) {
96
98
let ( camera, mockPhotoCaptureConnection, mockVideoCaptureConnection) = createCamera ( )
97
99
var photoSetVideoOrientationCallCount = 0
98
- mockPhotoCaptureConnection. setVideoOrientationStub = { _ in
100
+ mockPhotoCaptureConnection. setVideoRotationAngleStub = { _ in
99
101
photoSetVideoOrientationCallCount += 1
100
102
}
101
103
102
104
var videoSetVideoOrientationCallCount = 0
103
- mockVideoCaptureConnection. setVideoOrientationStub = { _ in
105
+ mockVideoCaptureConnection. setVideoRotationAngleStub = { _ in
104
106
videoSetVideoOrientationCallCount += 1
105
107
}
106
108
0 commit comments