Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: webrtc/examples/objc/AppRTCMobile/tests/ARDMediaConstraintsModelTests.mm

Issue 2462623002: Add setting to AppRTCMobile for iOS, that can change capture resolution. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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)testDefaultMediaFromStore;
24 - (void)testWidthConstraintFromStore;
25 - (void)testHeightConstraintFromStore;
26
27 @end
28
29 @implementation ARDMediaConstraintsModelTests
30
31 - (instancetype)init {
32 self = [super init];
33 if (self) {
34 _model = [[ARDMediaConstraintsModel alloc] init];
35 }
36 return self;
37 }
38
39 - (id)setupMockStoreWithMediaConstraintString:(NSString *)constraintString {
40 id storeMock = [OCMockObject mockForClass:[ARDMediaConstraintsSettingsStore cl ass]];
41 [([[storeMock stub] andReturn:constraintString]) videoResolutionConstraintsSet ting];
42
43 id partialMock = [OCMockObject partialMockForObject:_model];
44 [[[partialMock stub] andReturn:storeMock] settingsStore];
45
46 return storeMock;
47 }
48
49 - (void)testDefaultMediaFromStore {
50 // given
51 id storeMock = [self setupMockStoreWithMediaConstraintString:nil];
52
53 [[storeMock expect] setVideoResolutionConstraintsSetting:@"640x480"];
54
55 // when
56 NSString *string = [_model currentVideoResoultionConstraintFromStore];
57
58 // then
59 EXPECT_TRUE([string isEqualToString:@"640x480"]);
60 [storeMock verify];
61 }
62
63 - (void)testWidthConstraintFromStore {
64 // given
65 [self setupMockStoreWithMediaConstraintString:@"1270x480"];
66
67 // when
68 NSString *width = [_model currentVideoResolutionWidthFromStore];
69
70 // then
71 EXPECT_TRUE([width isEqualToString:@"1270"]);
72 }
73
74 - (void)testHeightConstraintFromStore {
75 // given
76 [self setupMockStoreWithMediaConstraintString:@"960x540"];
77 // when
78 NSString *height = [_model currentVideoResolutionHeightFromStore];
79
80 // then
81 EXPECT_TRUE([height isEqualToString:@"540"]);
82 }
83
84 - (void)testConstraintComponentIsNilWhenInvalidConstraintString {
85 // given
86 [self setupMockStoreWithMediaConstraintString:@"invalid"];
87
88 // when
89 NSString *width = [_model currentVideoResolutionWidthFromStore];
90
91 // then
92 EXPECT_TRUE(width == nil);
93 }
94
95 - (void)testConstraintsDictionaryIsNilWhenInvalidConstraintString {
96 // given
97 [self setupMockStoreWithMediaConstraintString:@"invalid"];
98
99 // when
100 NSDictionary *constraintsDictionary = [_model currentMediaConstraintFromStoreA sRTCDictionary];
101
102 // then
103 EXPECT_TRUE(constraintsDictionary == nil);
104 }
105 @end
106
107 class ARDMediaConstraintsModelTest : public ::testing::Test {
108 protected:
109 ARDMediaConstraintsModelTests *test;
110 ARDMediaConstraintsModelTest() { test = [[ARDMediaConstraintsModelTests alloc] init]; }
111 };
112
113 TEST_F(ARDMediaConstraintsModelTest, DefaultMediaFromStore) {
114 @autoreleasepool {
115 [test testDefaultMediaFromStore];
116 }
117 }
118
119 TEST_F(ARDMediaConstraintsModelTest, WidthConstraintFromStore) {
120 @autoreleasepool {
121 [test testWidthConstraintFromStore];
122 }
123 }
124
125 TEST_F(ARDMediaConstraintsModelTest, HeightConstraintFromStore) {
126 @autoreleasepool {
127 [test testHeightConstraintFromStore];
128 }
129 }
130
131 TEST_F(ARDMediaConstraintsModelTest, ConstratintIsNil) {
132 @autoreleasepool {
133 [test testConstraintComponentIsNilWhenInvalidConstraintString];
134 }
135 }
136
137 TEST_F(ARDMediaConstraintsModelTest, DictionaryIsNil) {
138 @autoreleasepool {
139 [test testConstraintsDictionaryIsNilWhenInvalidConstraintString];
140 }
141 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698