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

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

Issue 2697603002: Move iOS tests to XCTest from gtest. (Closed)
Patch Set: fix nits Created 3 years, 10 months 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 "ARDSettingsModel+Private.h"
14 #import "ARDSettingsStore.h"
15 #import "WebRTC/RTCMediaConstraints.h"
16 #include "webrtc/base/gunit.h"
17
18
19 @interface ARDSettingsModelTests : NSObject {
20 ARDSettingsModel *_model;
21 }
22
23 - (void)testStoringInavlidConstraintReturnsNo;
24 - (void)testDefaultMediaFromStore;
25 - (void)testWidthConstraintFromStore;
26 - (void)testHeightConstraintFromStore;
27
28 @end
29
30 @implementation ARDSettingsModelTests
31
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 {
41 id storeMock = [OCMockObject mockForClass:[ARDSettingsStore class]];
42 [([[storeMock stub] andReturn:constraintString]) videoResolutionConstraints];
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] setVideoResolutionConstraints:@"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_FALSE(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 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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698