| 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> |
| 14 |
| 15 #import "WebRTC/RTCMediaConstraints.h" |
| 16 |
| 13 #import "ARDSettingsModel+Private.h" | 17 #import "ARDSettingsModel+Private.h" |
| 14 #import "ARDSettingsStore.h" | 18 #import "ARDSettingsStore.h" |
| 15 #import "WebRTC/RTCMediaConstraints.h" | |
| 16 #include "webrtc/base/gunit.h" | |
| 17 | 19 |
| 18 | 20 |
| 19 @interface ARDSettingsModelTests : NSObject { | 21 @interface ARDSettingsModelTests : XCTestCase { |
| 20 ARDSettingsModel *_model; | 22 ARDSettingsModel *_model; |
| 21 } | 23 } |
| 22 | |
| 23 - (void)testStoringInavlidConstraintReturnsNo; | |
| 24 - (void)testDefaultMediaFromStore; | |
| 25 - (void)testWidthConstraintFromStore; | |
| 26 - (void)testHeightConstraintFromStore; | |
| 27 | |
| 28 @end | 24 @end |
| 29 | 25 |
| 30 @implementation ARDSettingsModelTests | 26 @implementation ARDSettingsModelTests |
| 31 | 27 |
| 32 - (instancetype)init { | |
| 33 self = [super init]; | |
| 34 if (self) { | |
| 35 _model = [[ARDSettingsModel alloc] init]; | |
| 36 } | |
| 37 return self; | |
| 38 } | |
| 39 | |
| 40 - (id)setupMockStoreWithMediaConstraintString:(NSString *)constraintString { | 28 - (id)setupMockStoreWithMediaConstraintString:(NSString *)constraintString { |
| 41 id storeMock = [OCMockObject mockForClass:[ARDSettingsStore class]]; | 29 id storeMock = [OCMockObject mockForClass:[ARDSettingsStore class]]; |
| 42 [([[storeMock stub] andReturn:constraintString]) videoResolutionConstraints]; | 30 [([[storeMock stub] andReturn:constraintString]) videoResolutionConstraints]; |
| 43 | 31 |
| 44 id partialMock = [OCMockObject partialMockForObject:_model]; | 32 id partialMock = [OCMockObject partialMockForObject:_model]; |
| 45 [[[partialMock stub] andReturn:storeMock] settingsStore]; | 33 [[[partialMock stub] andReturn:storeMock] settingsStore]; |
| 46 | 34 |
| 47 return storeMock; | 35 return storeMock; |
| 48 } | 36 } |
| 49 | 37 |
| 38 - (void)setUp { |
| 39 _model = [[ARDSettingsModel alloc] init]; |
| 40 } |
| 41 |
| 50 - (void)testDefaultMediaFromStore { | 42 - (void)testDefaultMediaFromStore { |
| 51 // given | |
| 52 id storeMock = [self setupMockStoreWithMediaConstraintString:nil]; | 43 id storeMock = [self setupMockStoreWithMediaConstraintString:nil]; |
| 53 | |
| 54 [[storeMock expect] setVideoResolutionConstraints:@"640x480"]; | 44 [[storeMock expect] setVideoResolutionConstraints:@"640x480"]; |
| 55 | 45 |
| 56 // when | |
| 57 NSString *string = [_model currentVideoResoultionConstraintFromStore]; | 46 NSString *string = [_model currentVideoResoultionConstraintFromStore]; |
| 58 | 47 |
| 59 // then | 48 XCTAssertEqualObjects(string, @"640x480"); |
| 60 EXPECT_TRUE([string isEqualToString:@"640x480"]); | |
| 61 [storeMock verify]; | 49 [storeMock verify]; |
| 62 } | 50 } |
| 63 | 51 |
| 64 - (void)testStoringInavlidConstraintReturnsNo { | 52 - (void)testStoringInvalidConstraintReturnsNo { |
| 65 // given | 53 __unused id storeMock = [self setupMockStoreWithMediaConstraintString:@"960x48
0"]; |
| 66 id storeMock = [self setupMockStoreWithMediaConstraintString:@"960x480"]; | 54 XCTAssertFalse([_model storeVideoResoultionConstraint:@"960x480"]); |
| 67 | |
| 68 // when | |
| 69 BOOL result = [_model storeVideoResoultionConstraint:@"960x480"]; | |
| 70 | |
| 71 // then | |
| 72 EXPECT_FALSE(result); | |
| 73 } | 55 } |
| 74 | 56 |
| 75 - (void)testWidthConstraintFromStore { | 57 - (void)testWidthConstraintFromStore { |
| 76 // given | |
| 77 [self setupMockStoreWithMediaConstraintString:@"1270x480"]; | 58 [self setupMockStoreWithMediaConstraintString:@"1270x480"]; |
| 78 | |
| 79 // when | |
| 80 NSString *width = [_model currentVideoResolutionWidthFromStore]; | 59 NSString *width = [_model currentVideoResolutionWidthFromStore]; |
| 81 | 60 |
| 82 // then | 61 XCTAssertEqualObjects(width, @"1270"); |
| 83 EXPECT_TRUE([width isEqualToString:@"1270"]); | |
| 84 } | 62 } |
| 85 | 63 |
| 86 - (void)testHeightConstraintFromStore { | 64 - (void)testHeightConstraintFromStore { |
| 87 // given | |
| 88 [self setupMockStoreWithMediaConstraintString:@"960x540"]; | 65 [self setupMockStoreWithMediaConstraintString:@"960x540"]; |
| 89 // when | |
| 90 NSString *height = [_model currentVideoResolutionHeightFromStore]; | 66 NSString *height = [_model currentVideoResolutionHeightFromStore]; |
| 91 | 67 |
| 92 // then | 68 XCTAssertEqualObjects(height, @"540"); |
| 93 EXPECT_TRUE([height isEqualToString:@"540"]); | |
| 94 } | 69 } |
| 95 | 70 |
| 96 - (void)testConstraintComponentIsNilWhenInvalidConstraintString { | 71 - (void)testConstraintComponentIsNilWhenInvalidConstraintString { |
| 97 // given | |
| 98 [self setupMockStoreWithMediaConstraintString:@"invalid"]; | 72 [self setupMockStoreWithMediaConstraintString:@"invalid"]; |
| 99 | |
| 100 // when | |
| 101 NSString *width = [_model currentVideoResolutionWidthFromStore]; | 73 NSString *width = [_model currentVideoResolutionWidthFromStore]; |
| 102 | 74 |
| 103 // then | 75 XCTAssertNil(width); |
| 104 EXPECT_TRUE(width == nil); | |
| 105 } | 76 } |
| 106 | 77 |
| 107 - (void)testConstraintsDictionaryIsNilWhenInvalidConstraintString { | 78 - (void)testConstraintsDictionaryIsNilWhenInvalidConstraintString { |
| 108 // given | |
| 109 [self setupMockStoreWithMediaConstraintString:@"invalid"]; | 79 [self setupMockStoreWithMediaConstraintString:@"invalid"]; |
| 110 | |
| 111 // when | |
| 112 NSDictionary *constraintsDictionary = [_model currentMediaConstraintFromStoreA
sRTCDictionary]; | 80 NSDictionary *constraintsDictionary = [_model currentMediaConstraintFromStoreA
sRTCDictionary]; |
| 113 | 81 |
| 114 // then | 82 XCTAssertNil(constraintsDictionary); |
| 115 EXPECT_TRUE(constraintsDictionary == nil); | |
| 116 } | 83 } |
| 117 @end | 84 @end |
| 118 | |
| 119 class ARDSettingsModelTest : public ::testing::Test { | |
| 120 protected: | |
| 121 ARDSettingsModelTests *test; | |
| 122 ARDSettingsModelTest() { test = [[ARDSettingsModelTests alloc] init]; } | |
| 123 }; | |
| 124 | |
| 125 TEST_F(ARDSettingsModelTest, DefaultMediaFromStore) { | |
| 126 @autoreleasepool { | |
| 127 [test testDefaultMediaFromStore]; | |
| 128 } | |
| 129 } | |
| 130 | |
| 131 TEST_F(ARDSettingsModelTest, StoringInvalidConstraintsReturnsNo) { | |
| 132 @autoreleasepool { | |
| 133 [test testStoringInavlidConstraintReturnsNo]; | |
| 134 } | |
| 135 } | |
| 136 | |
| 137 TEST_F(ARDSettingsModelTest, WidthConstraintFromStore) { | |
| 138 @autoreleasepool { | |
| 139 [test testWidthConstraintFromStore]; | |
| 140 } | |
| 141 } | |
| 142 | |
| 143 TEST_F(ARDSettingsModelTest, HeightConstraintFromStore) { | |
| 144 @autoreleasepool { | |
| 145 [test testHeightConstraintFromStore]; | |
| 146 } | |
| 147 } | |
| 148 | |
| 149 TEST_F(ARDSettingsModelTest, ConstratintIsNil) { | |
| 150 @autoreleasepool { | |
| 151 [test testConstraintComponentIsNilWhenInvalidConstraintString]; | |
| 152 } | |
| 153 } | |
| 154 | |
| 155 TEST_F(ARDSettingsModelTest, DictionaryIsNil) { | |
| 156 @autoreleasepool { | |
| 157 [test testConstraintsDictionaryIsNilWhenInvalidConstraintString]; | |
| 158 } | |
| 159 } | |
| OLD | NEW |