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

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

Issue 2697603002: Move iOS tests to XCTest from gtest. (Closed)
Patch Set: Enable apprtcmobile tests on bots 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
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 24
23 - (void)testStoringInavlidConstraintReturnsNo; 25 - (void)testStoringInavlidConstraintReturnsNo;
24 - (void)testDefaultMediaFromStore; 26 - (void)testDefaultMediaFromStore;
25 - (void)testWidthConstraintFromStore; 27 - (void)testWidthConstraintFromStore;
26 - (void)testHeightConstraintFromStore; 28 - (void)testHeightConstraintFromStore;
27 29
28 @end 30 @end
29 31
30 @implementation ARDSettingsModelTests 32 @implementation ARDSettingsModelTests
31 33
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 { 34 - (id)setupMockStoreWithMediaConstraintString:(NSString *)constraintString {
41 id storeMock = [OCMockObject mockForClass:[ARDSettingsStore class]]; 35 id storeMock = [OCMockObject mockForClass:[ARDSettingsStore class]];
42 [([[storeMock stub] andReturn:constraintString]) videoResolutionConstraints]; 36 [([[storeMock stub] andReturn:constraintString]) videoResolutionConstraints];
43 37
44 id partialMock = [OCMockObject partialMockForObject:_model]; 38 id partialMock = [OCMockObject partialMockForObject:_model];
45 [[[partialMock stub] andReturn:storeMock] settingsStore]; 39 [[[partialMock stub] andReturn:storeMock] settingsStore];
46 40
47 return storeMock; 41 return storeMock;
48 } 42 }
49 43
44 - (void)setUp {
45 _model = [[ARDSettingsModel alloc] init];
46 }
47
50 - (void)testDefaultMediaFromStore { 48 - (void)testDefaultMediaFromStore {
51 // given
52 id storeMock = [self setupMockStoreWithMediaConstraintString:nil]; 49 id storeMock = [self setupMockStoreWithMediaConstraintString:nil];
53
54 [[storeMock expect] setVideoResolutionConstraints:@"640x480"]; 50 [[storeMock expect] setVideoResolutionConstraints:@"640x480"];
55 51
56 // when
57 NSString *string = [_model currentVideoResoultionConstraintFromStore]; 52 NSString *string = [_model currentVideoResoultionConstraintFromStore];
58 53
59 // then 54 XCTAssertEqual(string, @"640x480");
daniela-webrtc 2017/02/13 16:08:22 Use XCTAssertEqualObjects here as well.
kthelgason 2017/02/14 09:48:46 I wonder how this worked and the test passed?
60 EXPECT_TRUE([string isEqualToString:@"640x480"]);
61 [storeMock verify]; 55 [storeMock verify];
62 } 56 }
63 57
64 - (void)testStoringInavlidConstraintReturnsNo { 58 - (void)testStoringInavlidConstraintReturnsNo {
65 // given 59 XCTAssertFalse([_model storeVideoResoultionConstraint:@"960x480"]);
66 id storeMock = [self setupMockStoreWithMediaConstraintString:@"960x480"];
magjed_webrtc 2017/02/13 15:57:36 What happened to this line? It's not included in t
daniela-webrtc 2017/02/13 16:08:22 +1
kthelgason 2017/02/14 09:48:46 storeMock is not used in this test.
magjed_webrtc 2017/02/14 10:00:28 No, but doesn't the call to setupMockStoreWithMedi
67
68 // when
69 BOOL result = [_model storeVideoResoultionConstraint:@"960x480"];
70
71 // then
72 EXPECT_FALSE(result);
73 } 60 }
74 61
75 - (void)testWidthConstraintFromStore { 62 - (void)testWidthConstraintFromStore {
76 // given
77 [self setupMockStoreWithMediaConstraintString:@"1270x480"]; 63 [self setupMockStoreWithMediaConstraintString:@"1270x480"];
78
79 // when
80 NSString *width = [_model currentVideoResolutionWidthFromStore]; 64 NSString *width = [_model currentVideoResolutionWidthFromStore];
81 65
82 // then 66 XCTAssertEqualObjects(width, @"1270");
83 EXPECT_TRUE([width isEqualToString:@"1270"]);
84 } 67 }
85 68
86 - (void)testHeightConstraintFromStore { 69 - (void)testHeightConstraintFromStore {
87 // given
88 [self setupMockStoreWithMediaConstraintString:@"960x540"]; 70 [self setupMockStoreWithMediaConstraintString:@"960x540"];
89 // when
90 NSString *height = [_model currentVideoResolutionHeightFromStore]; 71 NSString *height = [_model currentVideoResolutionHeightFromStore];
91 72
92 // then 73 XCTAssertEqualObjects(height, @"540");
93 EXPECT_TRUE([height isEqualToString:@"540"]);
94 } 74 }
95 75
96 - (void)testConstraintComponentIsNilWhenInvalidConstraintString { 76 - (void)testConstraintComponentIsNilWhenInvalidConstraintString {
97 // given
98 [self setupMockStoreWithMediaConstraintString:@"invalid"]; 77 [self setupMockStoreWithMediaConstraintString:@"invalid"];
99
100 // when
101 NSString *width = [_model currentVideoResolutionWidthFromStore]; 78 NSString *width = [_model currentVideoResolutionWidthFromStore];
102 79
103 // then 80 XCTAssertNil(width);
104 EXPECT_TRUE(width == nil);
105 } 81 }
106 82
107 - (void)testConstraintsDictionaryIsNilWhenInvalidConstraintString { 83 - (void)testConstraintsDictionaryIsNilWhenInvalidConstraintString {
108 // given
109 [self setupMockStoreWithMediaConstraintString:@"invalid"]; 84 [self setupMockStoreWithMediaConstraintString:@"invalid"];
110
111 // when
112 NSDictionary *constraintsDictionary = [_model currentMediaConstraintFromStoreA sRTCDictionary]; 85 NSDictionary *constraintsDictionary = [_model currentMediaConstraintFromStoreA sRTCDictionary];
113 86
114 // then 87 XCTAssertNil(constraintsDictionary);
115 EXPECT_TRUE(constraintsDictionary == nil);
116 } 88 }
117 @end 89 @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