| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 } | 106 } |
| 107 | 107 |
| 108 - (NSArray *)videoSupportedFrameRateRanges { | 108 - (NSArray *)videoSupportedFrameRateRanges { |
| 109 return @[ self.rangeMock ]; | 109 return @[ self.rangeMock ]; |
| 110 } | 110 } |
| 111 | 111 |
| 112 @end | 112 @end |
| 113 | 113 |
| 114 TEST(AVFormatMapperTest, SuportedCricketFormatsWithInvalidFramerateFormats) { | 114 TEST(AVFormatMapperTest, SuportedCricketFormatsWithInvalidFramerateFormats) { |
| 115 // given | 115 // given |
| 116 id mockDevice = [OCMockObject mockForClass:[AVCaptureDevice class]]; | 116 id mockDevice = OCMClassMock([AVCaptureDevice class]); |
| 117 | 117 |
| 118 // Valid media subtype, invalid framerate | 118 // Valid media subtype, invalid framerate |
| 119 AVCaptureDeviceFormatMock* mock = | 119 AVCaptureDeviceFormatMock* mock = |
| 120 [AVCaptureDeviceFormatMock invalidFpsFormat]; | 120 [AVCaptureDeviceFormatMock invalidFpsFormat]; |
| 121 | 121 OCMStub([mockDevice formats]).andReturn(@[ mock ]); |
| 122 [[[mockDevice stub] andReturn:@[ mock ]] formats]; | |
| 123 | 122 |
| 124 // when | 123 // when |
| 125 std::set<cricket::VideoFormat> result = | 124 std::set<cricket::VideoFormat> result = |
| 126 webrtc::GetSupportedVideoFormatsForDevice(mockDevice); | 125 webrtc::GetSupportedVideoFormatsForDevice(mockDevice); |
| 127 | 126 |
| 128 // then | 127 // then |
| 129 EXPECT_TRUE(result.empty()); | 128 EXPECT_TRUE(result.empty()); |
| 130 } | 129 } |
| 131 | 130 |
| 132 TEST(AVFormatMapperTest, SuportedCricketFormatsWithInvalidFormats) { | 131 TEST(AVFormatMapperTest, SuportedCricketFormatsWithInvalidFormats) { |
| 133 // given | 132 // given |
| 134 id mockDevice = [OCMockObject mockForClass:[AVCaptureDevice class]]; | 133 id mockDevice = OCMClassMock([AVCaptureDevice class]); |
| 135 | 134 |
| 136 // Invalid media subtype, valid framerate | 135 // Invalid media subtype, valid framerate |
| 137 AVCaptureDeviceFormatMock* mock = | 136 AVCaptureDeviceFormatMock* mock = |
| 138 [AVCaptureDeviceFormatMock invalidMediaSubtypeFormat]; | 137 [AVCaptureDeviceFormatMock invalidMediaSubtypeFormat]; |
| 139 | 138 OCMStub([mockDevice formats]).andReturn(@[ mock ]); |
| 140 [[[mockDevice stub] andReturn:@[ mock ]] formats]; | |
| 141 | 139 |
| 142 // when | 140 // when |
| 143 std::set<cricket::VideoFormat> result = | 141 std::set<cricket::VideoFormat> result = |
| 144 webrtc::GetSupportedVideoFormatsForDevice(mockDevice); | 142 webrtc::GetSupportedVideoFormatsForDevice(mockDevice); |
| 145 | 143 |
| 146 // then | 144 // then |
| 147 EXPECT_TRUE(result.empty()); | 145 EXPECT_TRUE(result.empty()); |
| 148 } | 146 } |
| 149 | 147 |
| 150 TEST(AVFormatMapperTest, SuportedCricketFormats) { | 148 TEST(AVFormatMapperTest, SuportedCricketFormats) { |
| 151 // given | 149 // given |
| 152 id mockDevice = [OCMockObject mockForClass:[AVCaptureDevice class]]; | 150 id mockDevice = OCMClassMock([AVCaptureDevice class]); |
| 153 | 151 |
| 154 // valid media subtype, valid framerate | 152 // valid media subtype, valid framerate |
| 155 AVCaptureDeviceFormatMock* mock = [AVCaptureDeviceFormatMock validFormat]; | 153 AVCaptureDeviceFormatMock* mock = [AVCaptureDeviceFormatMock validFormat]; |
| 156 [[[mockDevice stub] andReturn:@[ mock ]] formats]; | 154 OCMStub([mockDevice formats]).andReturn(@[ mock ]); |
| 157 | 155 |
| 158 // when | 156 // when |
| 159 std::set<cricket::VideoFormat> result = | 157 std::set<cricket::VideoFormat> result = |
| 160 webrtc::GetSupportedVideoFormatsForDevice(mockDevice); | 158 webrtc::GetSupportedVideoFormatsForDevice(mockDevice); |
| 161 | 159 |
| 162 // then | 160 // then |
| 163 EXPECT_EQ(1u, result.size()); | 161 EXPECT_EQ(1u, result.size()); |
| 164 | |
| 165 // make sure the set has the expected format | 162 // make sure the set has the expected format |
| 166 EXPECT_EQ(expectedFormat, *result.begin()); | 163 EXPECT_EQ(expectedFormat, *result.begin()); |
| 167 } | 164 } |
| 168 | 165 |
| 169 TEST(AVFormatMapperTest, MediaSubtypePreference) { | 166 TEST(AVFormatMapperTest, MediaSubtypePreference) { |
| 170 // given | 167 // given |
| 171 id mockDevice = [OCMockObject mockForClass:[AVCaptureDevice class]]; | 168 id mockDevice = OCMClassMock([AVCaptureDevice class]); |
| 172 | 169 |
| 173 // valid media subtype, valid framerate | 170 // valid media subtype, valid framerate |
| 174 AVCaptureDeviceFormatMock* mockOne = [[AVCaptureDeviceFormatMock alloc] | 171 AVCaptureDeviceFormatMock* mockOne = [[AVCaptureDeviceFormatMock alloc] |
| 175 initWithMediaSubtype:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange | 172 initWithMediaSubtype:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange |
| 176 minFps:0.0 | 173 minFps:0.0 |
| 177 maxFps:30.0]; | 174 maxFps:30.0]; |
| 178 | |
| 179 // valid media subtype, valid framerate. | 175 // valid media subtype, valid framerate. |
| 180 // This media subtype should be the preffered one. | 176 // This media subtype should be the preffered one. |
| 181 AVCaptureDeviceFormatMock* mockTwo = [[AVCaptureDeviceFormatMock alloc] | 177 AVCaptureDeviceFormatMock* mockTwo = [[AVCaptureDeviceFormatMock alloc] |
| 182 initWithMediaSubtype:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange | 178 initWithMediaSubtype:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange |
| 183 minFps:0.0 | 179 minFps:0.0 |
| 184 maxFps:30.0]; | 180 maxFps:30.0]; |
| 185 | 181 OCMStub([mockDevice lockForConfiguration:[OCMArg setTo:nil]]).andReturn(YES); |
| 186 [[[mockDevice stub] andReturnValue:@(YES)] | 182 OCMStub([mockDevice unlockForConfiguration]); |
| 187 lockForConfiguration:[OCMArg setTo:nil]]; | 183 NSArray* array = @[ mockOne, mockTwo ]; |
| 188 [[mockDevice stub] unlockForConfiguration]; | 184 OCMStub([mockDevice formats]).andReturn(array); |
| 189 | |
| 190 [[[mockDevice stub] andReturn:@[ mockOne, mockTwo ]] formats]; | |
| 191 | 185 |
| 192 // to verify | 186 // to verify |
| 193 [[mockDevice expect] setActiveFormat:(AVCaptureDeviceFormat*)mockTwo]; | 187 OCMExpect([mockDevice setActiveFormat:(AVCaptureDeviceFormat*)mockTwo]); |
| 194 [[mockDevice expect] | 188 OCMExpect( |
| 195 setActiveVideoMinFrameDuration:CMTimeMake(1, kFramerate)]; | 189 [mockDevice setActiveVideoMinFrameDuration:CMTimeMake(1, kFramerate)]); |
| 196 | 190 |
| 197 // when | 191 // when |
| 198 bool resultFormat = | 192 bool resultFormat = |
| 199 webrtc::SetFormatForCaptureDevice(mockDevice, nil, expectedFormat); | 193 webrtc::SetFormatForCaptureDevice(mockDevice, nil, expectedFormat); |
| 200 | 194 |
| 201 // then | 195 // then |
| 202 EXPECT_TRUE(resultFormat); | 196 EXPECT_TRUE(resultFormat); |
| 203 [mockDevice verify]; | 197 [mockDevice verify]; |
| 204 } | 198 } |
| 205 | 199 |
| 206 TEST(AVFormatMapperTest, SetFormatWhenDeviceCannotLock) { | 200 TEST(AVFormatMapperTest, SetFormatWhenDeviceCannotLock) { |
| 207 // given | 201 // given |
| 208 id mockDevice = [OCMockObject mockForClass:[AVCaptureDevice class]]; | 202 id mockDevice = OCMClassMock([AVCaptureDevice class]); |
| 209 [[[mockDevice stub] andReturnValue:@(NO)] | 203 [[[mockDevice stub] andReturnValue:@(NO)] |
| 210 lockForConfiguration:[OCMArg setTo:nil]]; | 204 lockForConfiguration:[OCMArg setTo:nil]]; |
| 211 | |
| 212 [[[mockDevice stub] andReturn:@[]] formats]; | 205 [[[mockDevice stub] andReturn:@[]] formats]; |
| 213 | 206 |
| 214 // when | 207 // when |
| 215 bool resultFormat = webrtc::SetFormatForCaptureDevice(mockDevice, nil, | 208 bool resultFormat = webrtc::SetFormatForCaptureDevice(mockDevice, nil, |
| 216 cricket::VideoFormat()); | 209 cricket::VideoFormat()); |
| 217 | 210 |
| 218 // then | 211 // then |
| 219 EXPECT_FALSE(resultFormat); | 212 EXPECT_FALSE(resultFormat); |
| 220 } | 213 } |
| 221 | 214 |
| 222 // Disabled due to failing with OCMock 3.1.5: | 215 TEST(AVFormatMapperTest, SetFormatWhenFormatIsIncompatible) { |
| 223 // https://bugs.chromium.org/p/webrtc/issues/detail?id=7137 | |
| 224 TEST(AVFormatMapperTest, DISABLED_SetFormatWhenFormatIsIncompatible) { | |
| 225 // given | 216 // given |
| 226 id mockDevice = [OCMockObject mockForClass:[AVCaptureDevice class]]; | 217 id mockDevice = OCMClassMock([AVCaptureDevice class]); |
| 227 [[[mockDevice stub] andReturn:@[]] formats]; | 218 OCMStub([mockDevice formats]).andReturn(@[]); |
| 228 [[[mockDevice stub] andReturnValue:@(YES)] | 219 OCMStub([mockDevice lockForConfiguration:[OCMArg setTo:nil]]).andReturn(YES); |
| 229 lockForConfiguration:[OCMArg setTo:nil]]; | 220 NSException* testException = |
| 230 | |
| 231 NSException* exception = | |
| 232 [NSException exceptionWithName:@"Test exception" | 221 [NSException exceptionWithName:@"Test exception" |
| 233 reason:@"Raised from unit tests" | 222 reason:@"Raised from unit tests" |
| 234 userInfo:nil]; | 223 userInfo:nil]; |
| 235 [[[mockDevice stub] andThrow:exception] setActiveFormat:[OCMArg any]]; | 224 OCMStub([mockDevice setActiveFormat:[OCMArg any]]).andThrow(testException); |
| 236 [[mockDevice expect] unlockForConfiguration]; | 225 OCMExpect([mockDevice unlockForConfiguration]); |
| 237 | 226 |
| 238 // when | 227 // when |
| 239 bool resultFormat = webrtc::SetFormatForCaptureDevice(mockDevice, nil, | 228 bool resultFormat = webrtc::SetFormatForCaptureDevice(mockDevice, nil, |
| 240 cricket::VideoFormat()); | 229 cricket::VideoFormat()); |
| 241 | 230 |
| 242 // then | 231 // then |
| 243 EXPECT_FALSE(resultFormat); | 232 EXPECT_FALSE(resultFormat); |
| 244 [mockDevice verify]; | 233 |
| 234 // TODO(denicija): Remove try-catch when Chromium rolls this change: |
| 235 // https://github.com/erikdoe/ocmock/commit/de1419415581dc307045e54bfe9c98c86e
fea96b |
| 236 // Without it, stubbed exceptions are being re-raised on [mock verify]. |
| 237 // More information here: |
| 238 //https://github.com/erikdoe/ocmock/issues/241 |
| 239 @try { |
| 240 [mockDevice verify]; |
| 241 } @catch (NSException* exception) { |
| 242 if ([exception.reason isEqual:testException.reason]) { |
| 243 // Nothing dangerous here |
| 244 EXPECT_TRUE([exception.reason isEqualToString:exception.reason]); |
| 245 } |
| 246 } |
| 245 } | 247 } |
| OLD | NEW |