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 | |
191 // Link error is: Undefined symbols for architecture i386: | |
192 // "OCMMakeLocation(objc_object*, char const*, int)", referenced from: | |
193 // -[RTCAudioSessionTest testConfigureWebRTCSession] in RTCAudioSessionTest.o | |
194 // ld: symbol(s) not found for architecture i386 | |
195 // REASON: https://github.com/erikdoe/ocmock/issues/238 | |
196 OCMLocation *OCMMakeLocation(id testCase, const char *fileCString, int line){ | |
197 return [OCMLocation locationWithTestCase:testCase | |
198 file:[NSString stringWithUTF8String:fileCS tring] | |
199 line:line]; | |
200 } | |
201 | |
202 - (void)testConfigureWebRTCSession { | |
203 NSError *error = nil; | |
204 | |
205 void (^setActiveBlock)(NSInvocation *invocation) = ^(NSInvocation *invocation) { | |
206 __autoreleasing NSError **retError; | |
207 [invocation getArgument:&retError atIndex:4]; | |
208 *retError = [NSError errorWithDomain:@"AVAudioSession" | |
209 code:AVAudioSessionErrorInsufficientPriority userInfo:nil]; | |
tkchin_webrtc
2017/04/21 19:52:21
align : vertically
jtt_webrtc
2017/04/21 20:12:16
Done.
| |
210 BOOL failure = NO; | |
211 [invocation setReturnValue:&failure]; | |
212 }; | |
213 | |
214 id mockAVAudioSession = OCMPartialMock([AVAudioSession sharedInstance]); | |
215 OCMStub([[mockAVAudioSession ignoringNonObjectArgs] | |
216 setActive:YES withOptions:0 error:((NSError __autoreleasing **)[OCMArg any Pointer])]). | |
217 andDo(setActiveBlock); | |
218 | |
219 id mockAudioSession = OCMPartialMock([RTCAudioSession sharedInstance]); | |
220 OCMStub([mockAudioSession session]).andReturn(mockAVAudioSession); | |
221 | |
222 RTCAudioSession *audioSession = mockAudioSession; | |
223 EXPECT_EQ(0, audioSession.activationCount); | |
224 [audioSession lockForConfiguration]; | |
225 EXPECT_TRUE([audioSession checkLock:nil]); | |
226 // configureWebRTCSession is forced to fail in the above mock interface, | |
227 // so activationCount should remain 0 | |
228 OCMExpect([[mockAVAudioSession ignoringNonObjectArgs] | |
229 setActive:YES withOptions:0 error:((NSError __autoreleasing **)[OCMArg any Pointer])]). | |
230 andDo(setActiveBlock); | |
231 OCMExpect([mockAudioSession session]).andReturn(mockAVAudioSession); | |
232 EXPECT_FALSE([audioSession configureWebRTCSession:&error]); | |
233 EXPECT_EQ(0, audioSession.activationCount); | |
234 | |
235 id session = audioSession.session; | |
236 EXPECT_EQ(session, mockAVAudioSession); | |
237 EXPECT_EQ(NO, [mockAVAudioSession setActive:YES withOptions:0 error:&error]); | |
238 [audioSession unlockForConfiguration]; | |
239 | |
240 OCMVerify([mockAudioSession session]); | |
241 OCMVerify([[mockAVAudioSession ignoringNonObjectArgs] setActive:YES withOption s:0 error:&error]); | |
242 OCMVerify([[mockAVAudioSession ignoringNonObjectArgs] setActive:NO withOptions :0 error:&error]); | |
243 | |
244 [mockAVAudioSession stopMocking]; | |
245 [mockAudioSession stopMocking]; | |
246 } | |
247 | |
188 @end | 248 @end |
189 | 249 |
190 namespace webrtc { | 250 namespace webrtc { |
191 | 251 |
192 class AudioSessionTest : public ::testing::Test { | 252 class AudioSessionTest : public ::testing::Test { |
193 protected: | 253 protected: |
194 void TearDown() { | 254 void TearDown() { |
195 RTCAudioSession *session = [RTCAudioSession sharedInstance]; | 255 RTCAudioSession *session = [RTCAudioSession sharedInstance]; |
196 for (id<RTCAudioSessionDelegate> delegate : session.delegates) { | 256 for (id<RTCAudioSessionDelegate> delegate : session.delegates) { |
197 [session removeDelegate:delegate]; | 257 [session removeDelegate:delegate]; |
(...skipping 24 matching lines...) Expand all Loading... | |
222 TEST_F(AudioSessionTest, RemoveDelegateOnDealloc) { | 282 TEST_F(AudioSessionTest, RemoveDelegateOnDealloc) { |
223 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; | 283 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; |
224 [test testRemoveDelegateOnDealloc]; | 284 [test testRemoveDelegateOnDealloc]; |
225 } | 285 } |
226 | 286 |
227 TEST_F(AudioSessionTest, AudioSessionActivation) { | 287 TEST_F(AudioSessionTest, AudioSessionActivation) { |
228 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; | 288 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; |
229 [test testAudioSessionActivation]; | 289 [test testAudioSessionActivation]; |
230 } | 290 } |
231 | 291 |
292 TEST_F(AudioSessionTest, ConfigureWebRTCSession) { | |
293 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; | |
294 [test testConfigureWebRTCSession]; | |
295 } | |
232 | 296 |
233 } // namespace webrtc | 297 } // namespace webrtc |
OLD | NEW |