| 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 |
| 11 #import <Foundation/Foundation.h> | 11 #import <Foundation/Foundation.h> |
| 12 #import <OCMock/OCMock.h> | 12 #import <OCMock/OCMock.h> |
| 13 #import <XCTest/XCTest.h> | 13 #import <XCTest/XCTest.h> |
| 14 | 14 |
| 15 #import "WebRTC/RTCMediaConstraints.h" | 15 #import "WebRTC/RTCMediaConstraints.h" |
| 16 | 16 |
| 17 #import "ARDSettingsModel+Private.h" | 17 #import "ARDSettingsModel+Private.h" |
| 18 #import "ARDSettingsStore.h" | 18 #import "ARDSettingsStore.h" |
| 19 | 19 |
| 20 | 20 |
| 21 @interface ARDSettingsModelTests : XCTestCase { | 21 @interface ARDSettingsModelTests : XCTestCase { |
| 22 ARDSettingsModel *_model; | 22 ARDSettingsModel *_model; |
| 23 } | 23 } |
| 24 @end | 24 @end |
| 25 | 25 |
| 26 @implementation ARDSettingsModelTests | 26 @implementation ARDSettingsModelTests |
| 27 | 27 |
| 28 - (id)setupMockStoreWithMediaConstraintString:(NSString *)constraintString { | 28 - (id)setupMockStoreWithVideoResolution:(NSString *)videoResolution { |
| 29 id storeMock = [OCMockObject mockForClass:[ARDSettingsStore class]]; | 29 id storeMock = [OCMockObject mockForClass:[ARDSettingsStore class]]; |
| 30 [([[storeMock stub] andReturn:constraintString]) videoResolutionConstraints]; | 30 [([[storeMock stub] andReturn:videoResolution])videoResolution]; |
| 31 | 31 |
| 32 id partialMock = [OCMockObject partialMockForObject:_model]; | 32 id partialMock = [OCMockObject partialMockForObject:_model]; |
| 33 [[[partialMock stub] andReturn:storeMock] settingsStore]; | 33 [[[partialMock stub] andReturn:storeMock] settingsStore]; |
| 34 | 34 |
| 35 return storeMock; | 35 return storeMock; |
| 36 } | 36 } |
| 37 | 37 |
| 38 - (void)setUp { | 38 - (void)setUp { |
| 39 _model = [[ARDSettingsModel alloc] init]; | 39 _model = [[ARDSettingsModel alloc] init]; |
| 40 } | 40 } |
| 41 | 41 |
| 42 - (void)testDefaultMediaFromStore { | 42 - (void)testDefaultMediaFromStore { |
| 43 id storeMock = [self setupMockStoreWithMediaConstraintString:nil]; | 43 id storeMock = [self setupMockStoreWithVideoResolution:nil]; |
| 44 [[storeMock expect] setVideoResolutionConstraints:@"640x480"]; | 44 [[storeMock expect] setVideoResolution:@"640x480"]; |
| 45 | 45 |
| 46 NSString *string = [_model currentVideoResoultionConstraintFromStore]; | 46 NSString *string = [_model currentVideoResolutionSettingFromStore]; |
| 47 | 47 |
| 48 XCTAssertEqualObjects(string, @"640x480"); | 48 XCTAssertEqualObjects(string, @"640x480"); |
| 49 [storeMock verify]; | 49 [storeMock verify]; |
| 50 } | 50 } |
| 51 | 51 |
| 52 - (void)testStoringInvalidConstraintReturnsNo { | 52 - (void)testStoringInvalidConstraintReturnsNo { |
| 53 __unused id storeMock = [self setupMockStoreWithMediaConstraintString:@"960x48
0"]; | 53 __unused id storeMock = [self setupMockStoreWithVideoResolution:@"960x480"]; |
| 54 XCTAssertFalse([_model storeVideoResoultionConstraint:@"960x480"]); | 54 XCTAssertFalse([_model storeVideoResolutionSetting:@"960x480"]); |
| 55 } | 55 } |
| 56 | 56 |
| 57 - (void)testWidthConstraintFromStore { | 57 - (void)testWidthConstraintFromStore { |
| 58 [self setupMockStoreWithMediaConstraintString:@"1270x480"]; | 58 [self setupMockStoreWithVideoResolution:@"1270x480"]; |
| 59 NSString *width = [_model currentVideoResolutionWidthFromStore]; | 59 int width = [_model currentVideoResolutionWidthFromStore]; |
| 60 | 60 |
| 61 XCTAssertEqualObjects(width, @"1270"); | 61 XCTAssertEqual(width, 1270); |
| 62 } | 62 } |
| 63 | 63 |
| 64 - (void)testHeightConstraintFromStore { | 64 - (void)testHeightConstraintFromStore { |
| 65 [self setupMockStoreWithMediaConstraintString:@"960x540"]; | 65 [self setupMockStoreWithVideoResolution:@"960x540"]; |
| 66 NSString *height = [_model currentVideoResolutionHeightFromStore]; | 66 int height = [_model currentVideoResolutionHeightFromStore]; |
| 67 | 67 |
| 68 XCTAssertEqualObjects(height, @"540"); | 68 XCTAssertEqual(height, 540); |
| 69 } | 69 } |
| 70 | 70 |
| 71 - (void)testConstraintComponentIsNilWhenInvalidConstraintString { | 71 - (void)testConstraintComponentIsNilWhenInvalidConstraintString { |
| 72 [self setupMockStoreWithMediaConstraintString:@"invalid"]; | 72 [self setupMockStoreWithVideoResolution:@"invalid"]; |
| 73 NSString *width = [_model currentVideoResolutionWidthFromStore]; | 73 int width = [_model currentVideoResolutionWidthFromStore]; |
| 74 | 74 |
| 75 XCTAssertNil(width); | 75 XCTAssertEqual(width, 0); |
| 76 } | |
| 77 | |
| 78 - (void)testConstraintsDictionaryIsNilWhenInvalidConstraintString { | |
| 79 [self setupMockStoreWithMediaConstraintString:@"invalid"]; | |
| 80 NSDictionary *constraintsDictionary = [_model currentMediaConstraintFromStoreA
sRTCDictionary]; | |
| 81 | |
| 82 XCTAssertNil(constraintsDictionary); | |
| 83 } | 76 } |
| 84 @end | 77 @end |
| OLD | NEW |