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 | 12 |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession.h" | 15 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession.h" |
16 #import "webrtc/modules/audio_device/ios/objc/RTCAudioSession+Private.h" | |
17 | |
18 @interface RTCAudioSessionTestDelegate : NSObject <RTCAudioSessionDelegate> | |
19 @end | |
20 | |
21 @implementation RTCAudioSessionTestDelegate | |
22 | |
23 - (void)audioSessionDidBeginInterruption:(RTCAudioSession *)session { | |
24 } | |
25 | |
26 - (void)audioSessionDidEndInterruption:(RTCAudioSession *)session | |
27 shouldResumeSession:(BOOL)shouldResumeSession { | |
28 } | |
29 | |
30 - (void)audioSessionDidChangeRoute:(RTCAudioSession *)session | |
31 reason:(AVAudioSessionRouteChangeReason)reason | |
32 previousRoute:(AVAudioSessionRouteDescription *)previousRoute { | |
33 } | |
34 | |
35 - (void)audioSessionMediaServicesWereLost:(RTCAudioSession *)session { | |
36 } | |
37 | |
38 - (void)audioSessionMediaServicesWereReset:(RTCAudioSession *)session { | |
39 } | |
40 | |
41 - (void)audioSessionShouldConfigure:(RTCAudioSession *)session { | |
42 } | |
43 | |
44 - (void)audioSessionShouldUnconfigure:(RTCAudioSession *)session { | |
45 } | |
46 | |
47 @end | |
48 | |
16 | 49 |
17 @interface RTCAudioSessionTest : NSObject | 50 @interface RTCAudioSessionTest : NSObject |
18 | 51 |
19 - (void)testLockForConfiguration; | 52 - (void)testLockForConfiguration; |
20 | 53 |
21 @end | 54 @end |
22 | 55 |
23 @implementation RTCAudioSessionTest | 56 @implementation RTCAudioSessionTest |
24 | 57 |
25 - (void)testLockForConfiguration { | 58 - (void)testLockForConfiguration { |
26 RTCAudioSession *session = [RTCAudioSession sharedInstance]; | 59 RTCAudioSession *session = [RTCAudioSession sharedInstance]; |
27 | 60 |
28 for (size_t i = 0; i < 2; i++) { | 61 for (size_t i = 0; i < 2; i++) { |
29 [session lockForConfiguration]; | 62 [session lockForConfiguration]; |
30 EXPECT_TRUE(session.isLocked); | 63 EXPECT_TRUE(session.isLocked); |
31 } | 64 } |
32 for (size_t i = 0; i < 2; i++) { | 65 for (size_t i = 0; i < 2; i++) { |
33 EXPECT_TRUE(session.isLocked); | 66 EXPECT_TRUE(session.isLocked); |
34 [session unlockForConfiguration]; | 67 [session unlockForConfiguration]; |
35 } | 68 } |
36 EXPECT_FALSE(session.isLocked); | 69 EXPECT_FALSE(session.isLocked); |
37 } | 70 } |
38 | 71 |
72 - (void)testAddAndRemoveDelegates { | |
73 RTCAudioSession *session = [RTCAudioSession sharedInstance]; | |
74 NSMutableArray *delegates = [NSMutableArray array]; | |
75 const size_t count = 5; | |
76 for (size_t i = 0; i < count; ++i) { | |
77 RTCAudioSessionTestDelegate *delegate = | |
78 [[RTCAudioSessionTestDelegate alloc] init]; | |
79 [session addDelegate:delegate]; | |
80 [delegates addObject:delegate]; | |
81 EXPECT_EQ(i + 1, session.delegates.size()); | |
82 } | |
83 [delegates enumerateObjectsUsingBlock:^(RTCAudioSessionTestDelegate *obj, | |
84 NSUInteger idx, | |
85 BOOL *stop) { | |
86 [session removeDelegate:obj]; | |
87 }]; | |
88 EXPECT_EQ(0u, session.delegates.size()); | |
89 } | |
90 | |
91 - (void)testPushDelegate { | |
92 RTCAudioSession *session = [RTCAudioSession sharedInstance]; | |
93 NSMutableArray *delegates = [NSMutableArray array]; | |
94 const size_t count = 2; | |
95 for (size_t i = 0; i < count; ++i) { | |
96 RTCAudioSessionTestDelegate *delegate = | |
97 [[RTCAudioSessionTestDelegate alloc] init]; | |
98 [session addDelegate:delegate]; | |
99 [delegates addObject:delegate]; | |
100 } | |
101 // Test that it gets added to the front of the list. | |
102 RTCAudioSessionTestDelegate *pushedDelegate = | |
103 [[RTCAudioSessionTestDelegate alloc] init]; | |
104 [session pushDelegate:pushedDelegate]; | |
105 EXPECT_TRUE(pushedDelegate == session.delegates[0]); | |
106 | |
107 // Test that it stays at the front of the list. | |
108 for (size_t i = 0; i < count; ++i) { | |
109 RTCAudioSessionTestDelegate *delegate = | |
110 [[RTCAudioSessionTestDelegate alloc] init]; | |
111 [session addDelegate:delegate]; | |
112 [delegates addObject:delegate]; | |
113 } | |
114 EXPECT_TRUE(pushedDelegate == session.delegates[0]); | |
115 | |
116 // Test that the next one goes to the front too. | |
117 pushedDelegate = [[RTCAudioSessionTestDelegate alloc] init]; | |
118 [session pushDelegate:pushedDelegate]; | |
119 EXPECT_TRUE(pushedDelegate == session.delegates[0]); | |
120 } | |
121 | |
122 - (void)testZeroingWeakDelegate { | |
henrika_webrtc
2016/03/15 08:53:44
Please add a comment here. Not trivial to figure o
tkchin_webrtc
2016/03/15 20:14:59
Done.
| |
123 RTCAudioSession *session = [RTCAudioSession sharedInstance]; | |
124 @autoreleasepool { | |
125 RTCAudioSessionTestDelegate *delegate = | |
126 [[RTCAudioSessionTestDelegate alloc] init]; | |
127 [session addDelegate:delegate]; | |
128 EXPECT_EQ(1u, session.delegates.size()); | |
129 } | |
130 EXPECT_FALSE(session.delegates[0]); | |
131 RTCAudioSessionTestDelegate *delegate = | |
132 [[RTCAudioSessionTestDelegate alloc] init]; | |
133 [session addDelegate:delegate]; | |
134 EXPECT_EQ(1u, session.delegates.size()); | |
135 } | |
136 | |
39 @end | 137 @end |
40 | 138 |
41 TEST(RTCAudioSessionTest, LockForConfiguration) { | 139 namespace webrtc { |
140 | |
141 class AudioSessionTest : public ::testing::Test { | |
142 protected: | |
143 void TearDown() { | |
144 RTCAudioSession *session = [RTCAudioSession sharedInstance]; | |
145 for (id<RTCAudioSessionDelegate> delegate : session.delegates) { | |
146 [session removeDelegate:delegate]; | |
147 } | |
148 } | |
149 }; | |
150 | |
151 TEST_F(AudioSessionTest, LockForConfiguration) { | |
42 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; | 152 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; |
43 [test testLockForConfiguration]; | 153 [test testLockForConfiguration]; |
44 } | 154 } |
155 | |
156 TEST_F(AudioSessionTest, AddAndRemovekDelegates) { | |
henrika_webrtc
2016/03/15 08:53:44
Did you mean "Removek"?
tkchin_webrtc
2016/03/15 20:14:58
Done.
| |
157 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; | |
158 [test testAddAndRemoveDelegates]; | |
159 } | |
160 | |
161 TEST_F(AudioSessionTest, PushDelegate) { | |
162 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; | |
163 [test testPushDelegate]; | |
164 } | |
165 | |
166 TEST_F(AudioSessionTest, ZeroingWeakDelegate) { | |
167 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; | |
168 [test testZeroingWeakDelegate]; | |
169 } | |
170 | |
171 } // namespace webrtc | |
OLD | NEW |