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 |
(...skipping 28 matching lines...) Expand all Loading... |
39 } | 39 } |
40 | 40 |
41 - (void)audioSessionShouldConfigure:(RTCAudioSession *)session { | 41 - (void)audioSessionShouldConfigure:(RTCAudioSession *)session { |
42 } | 42 } |
43 | 43 |
44 - (void)audioSessionShouldUnconfigure:(RTCAudioSession *)session { | 44 - (void)audioSessionShouldUnconfigure:(RTCAudioSession *)session { |
45 } | 45 } |
46 | 46 |
47 @end | 47 @end |
48 | 48 |
| 49 // A delegate that adds itself to the audio session on init and removes itself |
| 50 // in its dealloc. |
| 51 @interface RTCTestRemoveOnDeallocDelegate : RTCAudioSessionTestDelegate |
| 52 @end |
| 53 |
| 54 @implementation RTCTestRemoveOnDeallocDelegate |
| 55 |
| 56 - (instancetype)init { |
| 57 if (self = [super init]) { |
| 58 RTCAudioSession *session = [RTCAudioSession sharedInstance]; |
| 59 [session addDelegate:self]; |
| 60 } |
| 61 return self; |
| 62 } |
| 63 |
| 64 - (void)dealloc { |
| 65 RTCAudioSession *session = [RTCAudioSession sharedInstance]; |
| 66 [session removeDelegate:self]; |
| 67 } |
| 68 |
| 69 @end |
| 70 |
49 | 71 |
50 @interface RTCAudioSessionTest : NSObject | 72 @interface RTCAudioSessionTest : NSObject |
51 | 73 |
52 - (void)testLockForConfiguration; | 74 - (void)testLockForConfiguration; |
53 | 75 |
54 @end | 76 @end |
55 | 77 |
56 @implementation RTCAudioSessionTest | 78 @implementation RTCAudioSessionTest |
57 | 79 |
58 - (void)testLockForConfiguration { | 80 - (void)testLockForConfiguration { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 // The previously created delegate should've de-alloced, leaving a nil ptr. | 157 // The previously created delegate should've de-alloced, leaving a nil ptr. |
136 EXPECT_FALSE(session.delegates[0]); | 158 EXPECT_FALSE(session.delegates[0]); |
137 RTCAudioSessionTestDelegate *delegate = | 159 RTCAudioSessionTestDelegate *delegate = |
138 [[RTCAudioSessionTestDelegate alloc] init]; | 160 [[RTCAudioSessionTestDelegate alloc] init]; |
139 [session addDelegate:delegate]; | 161 [session addDelegate:delegate]; |
140 // On adding a new delegate, nil ptrs should've been cleared. | 162 // On adding a new delegate, nil ptrs should've been cleared. |
141 EXPECT_EQ(1u, session.delegates.size()); | 163 EXPECT_EQ(1u, session.delegates.size()); |
142 EXPECT_TRUE(session.delegates[0]); | 164 EXPECT_TRUE(session.delegates[0]); |
143 } | 165 } |
144 | 166 |
| 167 // Tests that we don't crash when removing delegates in dealloc. |
| 168 // Added as a regression test. |
| 169 - (void)testRemoveDelegateOnDealloc { |
| 170 @autoreleasepool { |
| 171 RTCTestRemoveOnDeallocDelegate *delegate = |
| 172 [[RTCTestRemoveOnDeallocDelegate alloc] init]; |
| 173 EXPECT_TRUE(delegate); |
| 174 } |
| 175 RTCAudioSession *session = [RTCAudioSession sharedInstance]; |
| 176 EXPECT_EQ(0u, session.delegates.size()); |
| 177 } |
| 178 |
145 @end | 179 @end |
146 | 180 |
147 namespace webrtc { | 181 namespace webrtc { |
148 | 182 |
149 class AudioSessionTest : public ::testing::Test { | 183 class AudioSessionTest : public ::testing::Test { |
150 protected: | 184 protected: |
151 void TearDown() { | 185 void TearDown() { |
152 RTCAudioSession *session = [RTCAudioSession sharedInstance]; | 186 RTCAudioSession *session = [RTCAudioSession sharedInstance]; |
153 for (id<RTCAudioSessionDelegate> delegate : session.delegates) { | 187 for (id<RTCAudioSessionDelegate> delegate : session.delegates) { |
154 [session removeDelegate:delegate]; | 188 [session removeDelegate:delegate]; |
(...skipping 14 matching lines...) Expand all Loading... |
169 TEST_F(AudioSessionTest, PushDelegate) { | 203 TEST_F(AudioSessionTest, PushDelegate) { |
170 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; | 204 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; |
171 [test testPushDelegate]; | 205 [test testPushDelegate]; |
172 } | 206 } |
173 | 207 |
174 TEST_F(AudioSessionTest, ZeroingWeakDelegate) { | 208 TEST_F(AudioSessionTest, ZeroingWeakDelegate) { |
175 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; | 209 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; |
176 [test testZeroingWeakDelegate]; | 210 [test testZeroingWeakDelegate]; |
177 } | 211 } |
178 | 212 |
| 213 TEST_F(AudioSessionTest, RemoveDelegateOnDealloc) { |
| 214 RTCAudioSessionTest *test = [[RTCAudioSessionTest alloc] init]; |
| 215 [test testRemoveDelegateOnDealloc]; |
| 216 } |
| 217 |
179 } // namespace webrtc | 218 } // namespace webrtc |
OLD | NEW |