OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 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 |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #import <Foundation/Foundation.h> |
| 12 #import <OCMock/OCMock.h> |
| 13 #import "ARDMediaConstraintsModel+Private.h" |
| 14 #import "ARDMediaConstraintsSettingsStore.h" |
| 15 #import "WebRTC/RTCMediaConstraints.h" |
| 16 #include "webrtc/base/gunit.h" |
| 17 |
| 18 |
| 19 @interface ARDMediaConstraintsModelTests : NSObject { |
| 20 ARDMediaConstraintsModel *_model; |
| 21 } |
| 22 |
| 23 - (void)testStoringInavlidConstraintReturnsNo; |
| 24 - (void)testDefaultMediaFromStore; |
| 25 - (void)testWidthConstraintFromStore; |
| 26 - (void)testHeightConstraintFromStore; |
| 27 |
| 28 @end |
| 29 |
| 30 @implementation ARDMediaConstraintsModelTests |
| 31 |
| 32 - (instancetype)init { |
| 33 self = [super init]; |
| 34 if (self) { |
| 35 _model = [[ARDMediaConstraintsModel alloc] init]; |
| 36 } |
| 37 return self; |
| 38 } |
| 39 |
| 40 - (id)setupMockStoreWithMediaConstraintString:(NSString *)constraintString { |
| 41 id storeMock = [OCMockObject mockForClass:[ARDMediaConstraintsSettingsStore cl
ass]]; |
| 42 [([[storeMock stub] andReturn:constraintString]) videoResolutionConstraintsSet
ting]; |
| 43 |
| 44 id partialMock = [OCMockObject partialMockForObject:_model]; |
| 45 [[[partialMock stub] andReturn:storeMock] settingsStore]; |
| 46 |
| 47 return storeMock; |
| 48 } |
| 49 |
| 50 - (void)testDefaultMediaFromStore { |
| 51 // given |
| 52 id storeMock = [self setupMockStoreWithMediaConstraintString:nil]; |
| 53 |
| 54 [[storeMock expect] setVideoResolutionConstraintsSetting:@"640x480"]; |
| 55 |
| 56 // when |
| 57 NSString *string = [_model currentVideoResoultionConstraintFromStore]; |
| 58 |
| 59 // then |
| 60 EXPECT_TRUE([string isEqualToString:@"640x480"]); |
| 61 [storeMock verify]; |
| 62 } |
| 63 |
| 64 - (void)testStoringInavlidConstraintReturnsNo { |
| 65 // given |
| 66 id storeMock = [self setupMockStoreWithMediaConstraintString:@"960x480"]; |
| 67 |
| 68 // when |
| 69 BOOL result = [_model storeVideoResoultionConstraint:@"960x480"]; |
| 70 |
| 71 // then |
| 72 EXPECT_TRUE(result); |
| 73 } |
| 74 |
| 75 - (void)testWidthConstraintFromStore { |
| 76 // given |
| 77 [self setupMockStoreWithMediaConstraintString:@"1270x480"]; |
| 78 |
| 79 // when |
| 80 NSString *width = [_model currentVideoResolutionWidthFromStore]; |
| 81 |
| 82 // then |
| 83 EXPECT_TRUE([width isEqualToString:@"1270"]); |
| 84 } |
| 85 |
| 86 - (void)testHeightConstraintFromStore { |
| 87 // given |
| 88 [self setupMockStoreWithMediaConstraintString:@"960x540"]; |
| 89 // when |
| 90 NSString *height = [_model currentVideoResolutionHeightFromStore]; |
| 91 |
| 92 // then |
| 93 EXPECT_TRUE([height isEqualToString:@"540"]); |
| 94 } |
| 95 |
| 96 - (void)testConstraintComponentIsNilWhenInvalidConstraintString { |
| 97 // given |
| 98 [self setupMockStoreWithMediaConstraintString:@"invalid"]; |
| 99 |
| 100 // when |
| 101 NSString *width = [_model currentVideoResolutionWidthFromStore]; |
| 102 |
| 103 // then |
| 104 EXPECT_TRUE(width == nil); |
| 105 } |
| 106 |
| 107 - (void)testConstraintsDictionaryIsNilWhenInvalidConstraintString { |
| 108 // given |
| 109 [self setupMockStoreWithMediaConstraintString:@"invalid"]; |
| 110 |
| 111 // when |
| 112 NSDictionary *constraintsDictionary = [_model currentMediaConstraintFromStoreA
sRTCDictionary]; |
| 113 |
| 114 // then |
| 115 EXPECT_TRUE(constraintsDictionary == nil); |
| 116 } |
| 117 @end |
| 118 |
| 119 class ARDMediaConstraintsModelTest : public ::testing::Test { |
| 120 protected: |
| 121 ARDMediaConstraintsModelTests *test; |
| 122 ARDMediaConstraintsModelTest() { test = [[ARDMediaConstraintsModelTests alloc]
init]; } |
| 123 }; |
| 124 |
| 125 TEST_F(ARDMediaConstraintsModelTest, DefaultMediaFromStore) { |
| 126 @autoreleasepool { |
| 127 [test testDefaultMediaFromStore]; |
| 128 } |
| 129 } |
| 130 |
| 131 TEST_F(ARDMediaConstraintsModelTest, StoringInvalidConstraintsReturnsNo) { |
| 132 @autoreleasepool { |
| 133 [test testStoringInavlidConstraintReturnsNo]; |
| 134 } |
| 135 } |
| 136 |
| 137 TEST_F(ARDMediaConstraintsModelTest, WidthConstraintFromStore) { |
| 138 @autoreleasepool { |
| 139 [test testWidthConstraintFromStore]; |
| 140 } |
| 141 } |
| 142 |
| 143 TEST_F(ARDMediaConstraintsModelTest, HeightConstraintFromStore) { |
| 144 @autoreleasepool { |
| 145 [test testHeightConstraintFromStore]; |
| 146 } |
| 147 } |
| 148 |
| 149 TEST_F(ARDMediaConstraintsModelTest, ConstratintIsNil) { |
| 150 @autoreleasepool { |
| 151 [test testConstraintComponentIsNilWhenInvalidConstraintString]; |
| 152 } |
| 153 } |
| 154 |
| 155 TEST_F(ARDMediaConstraintsModelTest, DictionaryIsNil) { |
| 156 @autoreleasepool { |
| 157 [test testConstraintsDictionaryIsNilWhenInvalidConstraintString]; |
| 158 } |
| 159 } |
OLD | NEW |