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)testStoringInavlidConstraintReturnsNo { |
65 // given | 53 XCTAssertFalse([_model storeVideoResoultionConstraint:@"960x480"]); |
66 id storeMock = [self setupMockStoreWithMediaConstraintString:@"960x480"]; | |
67 | |
68 // when | |
69 BOOL result = [_model storeVideoResoultionConstraint:@"960x480"]; | |
70 | |
71 // then | |
72 EXPECT_FALSE(result); | |
73 } | 54 } |
74 | 55 |
75 - (void)testWidthConstraintFromStore { | 56 - (void)testWidthConstraintFromStore { |
76 // given | |
77 [self setupMockStoreWithMediaConstraintString:@"1270x480"]; | 57 [self setupMockStoreWithMediaConstraintString:@"1270x480"]; |
78 | |
79 // when | |
80 NSString *width = [_model currentVideoResolutionWidthFromStore]; | 58 NSString *width = [_model currentVideoResolutionWidthFromStore]; |
81 | 59 |
82 // then | 60 XCTAssertEqualObjects(width, @"1270"); |
83 EXPECT_TRUE([width isEqualToString:@"1270"]); | |
84 } | 61 } |
85 | 62 |
86 - (void)testHeightConstraintFromStore { | 63 - (void)testHeightConstraintFromStore { |
87 // given | |
88 [self setupMockStoreWithMediaConstraintString:@"960x540"]; | 64 [self setupMockStoreWithMediaConstraintString:@"960x540"]; |
89 // when | |
90 NSString *height = [_model currentVideoResolutionHeightFromStore]; | 65 NSString *height = [_model currentVideoResolutionHeightFromStore]; |
91 | 66 |
92 // then | 67 XCTAssertEqualObjects(height, @"540"); |
93 EXPECT_TRUE([height isEqualToString:@"540"]); | |
94 } | 68 } |
95 | 69 |
96 - (void)testConstraintComponentIsNilWhenInvalidConstraintString { | 70 - (void)testConstraintComponentIsNilWhenInvalidConstraintString { |
97 // given | |
98 [self setupMockStoreWithMediaConstraintString:@"invalid"]; | 71 [self setupMockStoreWithMediaConstraintString:@"invalid"]; |
99 | |
100 // when | |
101 NSString *width = [_model currentVideoResolutionWidthFromStore]; | 72 NSString *width = [_model currentVideoResolutionWidthFromStore]; |
102 | 73 |
103 // then | 74 XCTAssertNil(width); |
104 EXPECT_TRUE(width == nil); | |
105 } | 75 } |
106 | 76 |
107 - (void)testConstraintsDictionaryIsNilWhenInvalidConstraintString { | 77 - (void)testConstraintsDictionaryIsNilWhenInvalidConstraintString { |
108 // given | |
109 [self setupMockStoreWithMediaConstraintString:@"invalid"]; | 78 [self setupMockStoreWithMediaConstraintString:@"invalid"]; |
110 | |
111 // when | |
112 NSDictionary *constraintsDictionary = [_model currentMediaConstraintFromStoreA
sRTCDictionary]; | 79 NSDictionary *constraintsDictionary = [_model currentMediaConstraintFromStoreA
sRTCDictionary]; |
113 | 80 |
114 // then | 81 XCTAssertNil(constraintsDictionary); |
115 EXPECT_TRUE(constraintsDictionary == nil); | |
116 } | 82 } |
117 @end | 83 @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 |