Re-enable disabled test and upgrade avformatmappertests to OCMock 3 syntax.

BUG=webrtc:7137

Review-Url: https://codereview.webrtc.org/2724443003
Cr-Commit-Position: refs/heads/master@{#16917}
This commit is contained in:
denicija
2017-02-28 09:14:45 -08:00
committed by Commit bot
parent 13645302ce
commit 907abd8414

View File

@ -113,13 +113,12 @@ static cricket::VideoFormat expectedFormat =
TEST(AVFormatMapperTest, SuportedCricketFormatsWithInvalidFramerateFormats) {
// given
id mockDevice = [OCMockObject mockForClass:[AVCaptureDevice class]];
id mockDevice = OCMClassMock([AVCaptureDevice class]);
// Valid media subtype, invalid framerate
AVCaptureDeviceFormatMock* mock =
[AVCaptureDeviceFormatMock invalidFpsFormat];
[[[mockDevice stub] andReturn:@[ mock ]] formats];
OCMStub([mockDevice formats]).andReturn(@[ mock ]);
// when
std::set<cricket::VideoFormat> result =
@ -131,13 +130,12 @@ TEST(AVFormatMapperTest, SuportedCricketFormatsWithInvalidFramerateFormats) {
TEST(AVFormatMapperTest, SuportedCricketFormatsWithInvalidFormats) {
// given
id mockDevice = [OCMockObject mockForClass:[AVCaptureDevice class]];
id mockDevice = OCMClassMock([AVCaptureDevice class]);
// Invalid media subtype, valid framerate
AVCaptureDeviceFormatMock* mock =
[AVCaptureDeviceFormatMock invalidMediaSubtypeFormat];
[[[mockDevice stub] andReturn:@[ mock ]] formats];
OCMStub([mockDevice formats]).andReturn(@[ mock ]);
// when
std::set<cricket::VideoFormat> result =
@ -149,11 +147,11 @@ TEST(AVFormatMapperTest, SuportedCricketFormatsWithInvalidFormats) {
TEST(AVFormatMapperTest, SuportedCricketFormats) {
// given
id mockDevice = [OCMockObject mockForClass:[AVCaptureDevice class]];
id mockDevice = OCMClassMock([AVCaptureDevice class]);
// valid media subtype, valid framerate
AVCaptureDeviceFormatMock* mock = [AVCaptureDeviceFormatMock validFormat];
[[[mockDevice stub] andReturn:@[ mock ]] formats];
OCMStub([mockDevice formats]).andReturn(@[ mock ]);
// when
std::set<cricket::VideoFormat> result =
@ -161,38 +159,34 @@ TEST(AVFormatMapperTest, SuportedCricketFormats) {
// then
EXPECT_EQ(1u, result.size());
// make sure the set has the expected format
EXPECT_EQ(expectedFormat, *result.begin());
}
TEST(AVFormatMapperTest, MediaSubtypePreference) {
// given
id mockDevice = [OCMockObject mockForClass:[AVCaptureDevice class]];
id mockDevice = OCMClassMock([AVCaptureDevice class]);
// valid media subtype, valid framerate
AVCaptureDeviceFormatMock* mockOne = [[AVCaptureDeviceFormatMock alloc]
initWithMediaSubtype:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange
minFps:0.0
maxFps:30.0];
// valid media subtype, valid framerate.
// This media subtype should be the preffered one.
AVCaptureDeviceFormatMock* mockTwo = [[AVCaptureDeviceFormatMock alloc]
initWithMediaSubtype:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
minFps:0.0
maxFps:30.0];
[[[mockDevice stub] andReturnValue:@(YES)]
lockForConfiguration:[OCMArg setTo:nil]];
[[mockDevice stub] unlockForConfiguration];
[[[mockDevice stub] andReturn:@[ mockOne, mockTwo ]] formats];
OCMStub([mockDevice lockForConfiguration:[OCMArg setTo:nil]]).andReturn(YES);
OCMStub([mockDevice unlockForConfiguration]);
NSArray* array = @[ mockOne, mockTwo ];
OCMStub([mockDevice formats]).andReturn(array);
// to verify
[[mockDevice expect] setActiveFormat:(AVCaptureDeviceFormat*)mockTwo];
[[mockDevice expect]
setActiveVideoMinFrameDuration:CMTimeMake(1, kFramerate)];
OCMExpect([mockDevice setActiveFormat:(AVCaptureDeviceFormat*)mockTwo]);
OCMExpect(
[mockDevice setActiveVideoMinFrameDuration:CMTimeMake(1, kFramerate)]);
// when
bool resultFormat =
@ -205,10 +199,9 @@ TEST(AVFormatMapperTest, MediaSubtypePreference) {
TEST(AVFormatMapperTest, SetFormatWhenDeviceCannotLock) {
// given
id mockDevice = [OCMockObject mockForClass:[AVCaptureDevice class]];
id mockDevice = OCMClassMock([AVCaptureDevice class]);
[[[mockDevice stub] andReturnValue:@(NO)]
lockForConfiguration:[OCMArg setTo:nil]];
[[[mockDevice stub] andReturn:@[]] formats];
// when
@ -219,21 +212,17 @@ TEST(AVFormatMapperTest, SetFormatWhenDeviceCannotLock) {
EXPECT_FALSE(resultFormat);
}
// Disabled due to failing with OCMock 3.1.5:
// https://bugs.chromium.org/p/webrtc/issues/detail?id=7137
TEST(AVFormatMapperTest, DISABLED_SetFormatWhenFormatIsIncompatible) {
TEST(AVFormatMapperTest, SetFormatWhenFormatIsIncompatible) {
// given
id mockDevice = [OCMockObject mockForClass:[AVCaptureDevice class]];
[[[mockDevice stub] andReturn:@[]] formats];
[[[mockDevice stub] andReturnValue:@(YES)]
lockForConfiguration:[OCMArg setTo:nil]];
NSException* exception =
id mockDevice = OCMClassMock([AVCaptureDevice class]);
OCMStub([mockDevice formats]).andReturn(@[]);
OCMStub([mockDevice lockForConfiguration:[OCMArg setTo:nil]]).andReturn(YES);
NSException* testException =
[NSException exceptionWithName:@"Test exception"
reason:@"Raised from unit tests"
userInfo:nil];
[[[mockDevice stub] andThrow:exception] setActiveFormat:[OCMArg any]];
[[mockDevice expect] unlockForConfiguration];
OCMStub([mockDevice setActiveFormat:[OCMArg any]]).andThrow(testException);
OCMExpect([mockDevice unlockForConfiguration]);
// when
bool resultFormat = webrtc::SetFormatForCaptureDevice(mockDevice, nil,
@ -241,5 +230,18 @@ TEST(AVFormatMapperTest, DISABLED_SetFormatWhenFormatIsIncompatible) {
// then
EXPECT_FALSE(resultFormat);
[mockDevice verify];
// TODO(denicija): Remove try-catch when Chromium rolls this change:
// https://github.com/erikdoe/ocmock/commit/de1419415581dc307045e54bfe9c98c86efea96b
// Without it, stubbed exceptions are being re-raised on [mock verify].
// More information here:
//https://github.com/erikdoe/ocmock/issues/241
@try {
[mockDevice verify];
} @catch (NSException* exception) {
if ([exception.reason isEqual:testException.reason]) {
// Nothing dangerous here
EXPECT_TRUE([exception.reason isEqualToString:exception.reason]);
}
}
}