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 | 13 |
13 #include "webrtc/test/gtest.h" | 14 #include "webrtc/test/gtest.h" |
14 | 15 |
15 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession.h" | 16 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession.h" |
16 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession+Private.h" | 17 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession+Private.h" |
18 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSessionConfiguration.h" | |
17 | 19 |
18 @interface RTCAudioSessionTestDelegate : NSObject <RTCAudioSessionDelegate> | 20 @interface RTCAudioSessionTestDelegate : NSObject <RTCAudioSessionDelegate> |
19 @end | 21 @end |
20 | 22 |
21 @implementation RTCAudioSessionTestDelegate | 23 @implementation RTCAudioSessionTestDelegate |
22 | 24 |
23 - (void)audioSessionDidBeginInterruption:(RTCAudioSession *)session { | 25 - (void)audioSessionDidBeginInterruption:(RTCAudioSession *)session { |
24 } | 26 } |
25 | 27 |
26 - (void)audioSessionDidEndInterruption:(RTCAudioSession *)session | 28 - (void)audioSessionDidEndInterruption:(RTCAudioSession *)session |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 | 180 |
179 - (void)testAudioSessionActivation { | 181 - (void)testAudioSessionActivation { |
180 RTCAudioSession *audioSession = [RTCAudioSession sharedInstance]; | 182 RTCAudioSession *audioSession = [RTCAudioSession sharedInstance]; |
181 EXPECT_EQ(0, audioSession.activationCount); | 183 EXPECT_EQ(0, audioSession.activationCount); |
182 [audioSession audioSessionDidActivate:[AVAudioSession sharedInstance]]; | 184 [audioSession audioSessionDidActivate:[AVAudioSession sharedInstance]]; |
183 EXPECT_EQ(1, audioSession.activationCount); | 185 EXPECT_EQ(1, audioSession.activationCount); |
184 [audioSession audioSessionDidDeactivate:[AVAudioSession sharedInstance]]; | 186 [audioSession audioSessionDidDeactivate:[AVAudioSession sharedInstance]]; |
185 EXPECT_EQ(0, audioSession.activationCount); | 187 EXPECT_EQ(0, audioSession.activationCount); |
186 } | 188 } |
187 | 189 |
190 // Hack - fixes OCMVerify link error | |
tkchin_webrtc
2017/04/18 17:53:28
what is the link error?
jtt_webrtc
2017/04/18 18:53:54
// Link error is: Undefined symbols for architectu
tkchin_webrtc
2017/04/18 21:06:33
Was that fixed upstream? Can we update ocmock?
| |
191 OCMLocation *OCMMakeLocation(id testCase, const char *fileCString, int line){ | |
192 return [OCMLocation locationWithTestCase:testCase file:[NSString | |
tkchin_webrtc
2017/04/18 17:53:28
align :
jtt_webrtc
2017/04/18 18:53:54
Done.
| |
193 stringWithUTF8String:fileCString] line:line]; | |
194 } | |
195 | |
196 - (void)testConfigureWebRTCSession { | |
197 NSError *error; | |
tkchin_webrtc
2017/04/18 17:53:28
nit: init to nil
jtt_webrtc
2017/04/18 18:53:54
Defaults to nil. Will add it anyway.
| |
198 | |
199 void (^setActiveBlock)(NSInvocation *invocation) = ^(NSInvocation *invocation) { | |
200 __autoreleasing NSError **retError; | |
tkchin_webrtc
2017/04/18 17:53:28
Do we really need to specify autoreleasing?
jtt_webrtc
2017/04/18 18:53:54
Yes, otherwise it'll throw a build error.
tkchin_webrtc
2017/04/18 21:06:33
what's the build error? (for my education)
| |
201 [invocation getArgument:&retError atIndex:4]; | |
202 *retError = [NSError errorWithDomain:@"AVAudioSession" code:561017449 userIn fo:nil]; | |
henrika_webrtc
2017/04/18 18:14:11
Where does these details come from?
jtt_webrtc
2017/04/18 18:53:54
Acknowledged.
| |
203 BOOL failure = NO; | |
204 [invocation setReturnValue:&failure]; | |
205 }; | |
206 | |
207 id mockAVAudioSession = OCMPartialMock([AVAudioSession sharedInstance]); | |
208 OCMExpect([[mockAVAudioSession ignoringNonObjectArgs] | |
tkchin_webrtc
2017/04/18 17:53:28
nit: stub everything you need first, and then plac
jtt_webrtc
2017/04/18 18:53:54
Done.
| |
209 setActive:YES withOptions:0 error:((NSError __autoreleasing **)[OCMArg any Pointer])]). | |
210 andDo(setActiveBlock); | |
211 OCMStub([[mockAVAudioSession ignoringNonObjectArgs] | |
212 setActive:YES withOptions:0 error:((NSError __autoreleasing **)[OCMArg any Pointer])]). | |
213 andDo(setActiveBlock); | |
214 | |
215 id mockAudioSession = OCMPartialMock([RTCAudioSession sharedInstance]); | |
216 OCMExpect([mockAudioSession session]).andReturn(mockAVAudioSession); | |
217 OCMStub([mockAudioSession session]).andReturn(mockAVAudioSession); | |
218 | |
219 RTCAudioSession *audioSession = mockAudioSession; | |
220 EXPECT_EQ(0, audioSession.activationCount); | |
221 [audioSession lockForConfiguration]; | |
222 EXPECT_TRUE([audioSession checkLock:nil]); | |
223 // Force failure, so activationCount should remain 0 | |
tkchin_webrtc
2017/04/18 17:53:28
nit: this isn't technically forcing a failure - th
jtt_webrtc
2017/04/18 18:53:54
Done.
| |
224 EXPECT_FALSE([audioSession configureWebRTCSession:&error]); | |
225 EXPECT_EQ(0, audioSession.activationCount); | |
226 | |
227 id session = audioSession.session; | |
228 EXPECT_EQ(session, mockAVAudioSession); | |
229 EXPECT_EQ(FALSE, [mockAVAudioSession setActive:YES withOptions:0 error:&error] ); | |
tkchin_webrtc
2017/04/18 17:53:28
don't use FALSE -> NO
jtt_webrtc
2017/04/18 18:53:54
Done.
| |
230 [audioSession unlockForConfiguration]; | |
231 | |
232 OCMVerify([mockAudioSession session]); | |
233 OCMVerify([[mockAVAudioSession ignoringNonObjectArgs] setActive:YES withOption s:0 error:&error]); | |
234 OCMVerify([[mockAVAudioSession ignoringNonObjectArgs] setActive:NO withOptions :0 error:&error]); | |
235 | |
236 [mockAVAudioSession stopMocking]; | |
237 [mockAudioSession stopMocking]; | |
238 } | |
239 | |
188 @end | 240 @end |
189 | 241 |
190 namespace webrtc { | 242 namespace webrtc { |
191 | 243 |
192 class AudioSessionTest : public ::testing::Test { | 244 class AudioSessionTest : public ::testing::Test { |
193 protected: | 245 protected: |
194 void TearDown() { | 246 void TearDown() { |
195 RTCAudioSession *session = [RTCAudioSession sharedInstance]; | 247 RTCAudioSession *session = [RTCAudioSession sharedInstance]; |
196 for (id<RTCAudioSessionDelegate> delegate : session.delegates) { | 248 for (id<RTCAudioSessionDelegate> delegate : session.delegates) { |
197 [session removeDelegate:delegate]; | 249 [session removeDelegate:delegate]; |
(...skipping 24 matching lines...) Expand all Loading... | |
222 TEST_F(AudioSessionTest, RemoveDelegateOnDealloc) { | 274 TEST_F(AudioSessionTest, RemoveDelegateOnDealloc) { |
223 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; | 275 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; |
224 [test testRemoveDelegateOnDealloc]; | 276 [test testRemoveDelegateOnDealloc]; |
225 } | 277 } |
226 | 278 |
227 TEST_F(AudioSessionTest, AudioSessionActivation) { | 279 TEST_F(AudioSessionTest, AudioSessionActivation) { |
228 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; | 280 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; |
229 [test testAudioSessionActivation]; | 281 [test testAudioSessionActivation]; |
230 } | 282 } |
231 | 283 |
284 TEST_F(AudioSessionTest, ConfigureWebRTCSession) { | |
285 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; | |
tkchin_webrtc
2017/04/18 21:06:33
Do all these need to be in an autoreleasepool? I d
| |
286 [test testConfigureWebRTCSession]; | |
287 } | |
232 | 288 |
233 } // namespace webrtc | 289 } // namespace webrtc |
OLD | NEW |