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 |
| 210 userInfo:nil]; |
| 211 BOOL failure = NO; |
| 212 [invocation setReturnValue:&failure]; |
| 213 }; |
| 214 |
| 215 id mockAVAudioSession = OCMPartialMock([AVAudioSession sharedInstance]); |
| 216 OCMStub([[mockAVAudioSession ignoringNonObjectArgs] |
| 217 setActive:YES withOptions:0 error:((NSError __autoreleasing **)[OCMArg any
Pointer])]). |
| 218 andDo(setActiveBlock); |
| 219 |
| 220 id mockAudioSession = OCMPartialMock([RTCAudioSession sharedInstance]); |
| 221 OCMStub([mockAudioSession session]).andReturn(mockAVAudioSession); |
| 222 |
| 223 RTCAudioSession *audioSession = mockAudioSession; |
| 224 EXPECT_EQ(0, audioSession.activationCount); |
| 225 [audioSession lockForConfiguration]; |
| 226 EXPECT_TRUE([audioSession checkLock:nil]); |
| 227 // configureWebRTCSession is forced to fail in the above mock interface, |
| 228 // so activationCount should remain 0 |
| 229 OCMExpect([[mockAVAudioSession ignoringNonObjectArgs] |
| 230 setActive:YES withOptions:0 error:((NSError __autoreleasing **)[OCMArg any
Pointer])]). |
| 231 andDo(setActiveBlock); |
| 232 OCMExpect([mockAudioSession session]).andReturn(mockAVAudioSession); |
| 233 EXPECT_FALSE([audioSession configureWebRTCSession:&error]); |
| 234 EXPECT_EQ(0, audioSession.activationCount); |
| 235 |
| 236 id session = audioSession.session; |
| 237 EXPECT_EQ(session, mockAVAudioSession); |
| 238 EXPECT_EQ(NO, [mockAVAudioSession setActive:YES withOptions:0 error:&error]); |
| 239 [audioSession unlockForConfiguration]; |
| 240 |
| 241 OCMVerify([mockAudioSession session]); |
| 242 OCMVerify([[mockAVAudioSession ignoringNonObjectArgs] setActive:YES withOption
s:0 error:&error]); |
| 243 OCMVerify([[mockAVAudioSession ignoringNonObjectArgs] setActive:NO withOptions
:0 error:&error]); |
| 244 |
| 245 [mockAVAudioSession stopMocking]; |
| 246 [mockAudioSession stopMocking]; |
| 247 } |
| 248 |
188 @end | 249 @end |
189 | 250 |
190 namespace webrtc { | 251 namespace webrtc { |
191 | 252 |
192 class AudioSessionTest : public ::testing::Test { | 253 class AudioSessionTest : public ::testing::Test { |
193 protected: | 254 protected: |
194 void TearDown() { | 255 void TearDown() { |
195 RTCAudioSession *session = [RTCAudioSession sharedInstance]; | 256 RTCAudioSession *session = [RTCAudioSession sharedInstance]; |
196 for (id<RTCAudioSessionDelegate> delegate : session.delegates) { | 257 for (id<RTCAudioSessionDelegate> delegate : session.delegates) { |
197 [session removeDelegate:delegate]; | 258 [session removeDelegate:delegate]; |
(...skipping 24 matching lines...) Expand all Loading... |
222 TEST_F(AudioSessionTest, RemoveDelegateOnDealloc) { | 283 TEST_F(AudioSessionTest, RemoveDelegateOnDealloc) { |
223 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; | 284 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; |
224 [test testRemoveDelegateOnDealloc]; | 285 [test testRemoveDelegateOnDealloc]; |
225 } | 286 } |
226 | 287 |
227 TEST_F(AudioSessionTest, AudioSessionActivation) { | 288 TEST_F(AudioSessionTest, AudioSessionActivation) { |
228 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; | 289 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; |
229 [test testAudioSessionActivation]; | 290 [test testAudioSessionActivation]; |
230 } | 291 } |
231 | 292 |
| 293 TEST_F(AudioSessionTest, ConfigureWebRTCSession) { |
| 294 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; |
| 295 [test testConfigureWebRTCSession]; |
| 296 } |
232 | 297 |
233 } // namespace webrtc | 298 } // namespace webrtc |
OLD | NEW |