OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 sigslot::signal<> signal; | 265 sigslot::signal<> signal; |
266 SigslotReceiver<> receiver; | 266 SigslotReceiver<> receiver; |
267 receiver.Connect(&signal); | 267 receiver.Connect(&signal); |
268 | 268 |
269 // Fire the signal after copying the receiver, expecting the copied receiver | 269 // Fire the signal after copying the receiver, expecting the copied receiver |
270 // to be notified. | 270 // to be notified. |
271 SigslotReceiver<> copied_receiver(receiver); | 271 SigslotReceiver<> copied_receiver(receiver); |
272 signal(); | 272 signal(); |
273 EXPECT_EQ(1, copied_receiver.signal_count()); | 273 EXPECT_EQ(1, copied_receiver.signal_count()); |
274 } | 274 } |
275 | |
276 // Just used for the test below. | |
277 class Disconnector : public sigslot::has_slots<> { | |
278 public: | |
279 Disconnector(SigslotReceiver<>* receiver1, SigslotReceiver<>* receiver2) | |
280 : receiver1_(receiver1), receiver2_(receiver2) {} | |
281 | |
282 void Connect(sigslot::signal<>* signal) { | |
283 signal_ = signal; | |
284 signal->connect(this, | |
285 &Disconnector::Disconnect); | |
286 } | |
287 | |
288 private: | |
289 void Disconnect() { | |
290 receiver1_->Disconnect(); | |
291 receiver2_->Disconnect(); | |
292 signal_->disconnect(this); | |
293 } | |
294 | |
295 sigslot::signal<>* signal_; | |
296 SigslotReceiver<>* receiver1_; | |
297 SigslotReceiver<>* receiver2_; | |
298 }; | |
299 | |
300 // Test that things work as expected if a signal is disconnected from a slot whi
le it's | |
301 TEST(SigslotTest, DisconnectFromSignalWhileFiring) { | |
302 sigslot::signal<> signal; | |
303 SigslotReceiver<> receiver1; | |
304 SigslotReceiver<> receiver2; | |
305 SigslotReceiver<> receiver3; | |
306 Disconnector disconnector(&receiver1, &receiver2); | |
307 | |
308 // From this ordering, receiver1 should receive the signal, then the | |
309 // disconnector will be invoked, causing receiver2 to be disconnected before | |
310 // it receives the signal. And receiver2 should also receive the signal, | |
311 // since it was never disconnected. | |
312 receiver1.Connect(&signal); | |
313 disconnector.Connect(&signal); | |
314 receiver2.Connect(&signal); | |
315 receiver3.Connect(&signal); | |
316 signal(); | |
317 | |
318 EXPECT_EQ(1, receiver1.signal_count()); | |
319 EXPECT_EQ(0, receiver2.signal_count()); | |
320 EXPECT_EQ(1, receiver3.signal_count()); | |
321 } | |
OLD | NEW |