Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1884)

Side by Side Diff: webrtc/base/sigslot_unittest.cc

Issue 2842423002: Fixing sigslot copy constructors. (Closed)
Patch Set: Fixing missing backreference from copied slot to signal. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/base/sigslot.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 18 matching lines...) Expand all
29 }; 29 };
30 30
31 template<class slot_policy = sigslot::single_threaded, 31 template<class slot_policy = sigslot::single_threaded,
32 class signal_policy = sigslot::single_threaded> 32 class signal_policy = sigslot::single_threaded>
33 class SigslotReceiver : public sigslot::has_slots<slot_policy> { 33 class SigslotReceiver : public sigslot::has_slots<slot_policy> {
34 public: 34 public:
35 SigslotReceiver() : signal_(nullptr), signal_count_(0) {} 35 SigslotReceiver() : signal_(nullptr), signal_count_(0) {}
36 ~SigslotReceiver() { 36 ~SigslotReceiver() {
37 } 37 }
38 38
39 // Provide copy constructor so that tests can exercise the has_slots copy
40 // constructor.
41 SigslotReceiver(const SigslotReceiver&) = default;
42
39 void Connect(sigslot::signal0<signal_policy>* signal) { 43 void Connect(sigslot::signal0<signal_policy>* signal) {
40 if (!signal) return; 44 if (!signal) return;
41 Disconnect(); 45 Disconnect();
42 signal_ = signal; 46 signal_ = signal;
43 signal->connect(this, 47 signal->connect(this,
44 &SigslotReceiver<slot_policy, signal_policy>::OnSignal); 48 &SigslotReceiver<slot_policy, signal_policy>::OnSignal);
45 } 49 }
46 void Disconnect() { 50 void Disconnect() {
47 if (!signal_) return; 51 if (!signal_) return;
48 signal_->disconnect(this); 52 signal_->disconnect(this);
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 // Test that locks are acquired and released correctly. 219 // Test that locks are acquired and released correctly.
216 TEST_F(SigslotMTLockTest, LockSanity) { 220 TEST_F(SigslotMTLockTest, LockSanity) {
217 const int lock_count = SignalLockCount(); 221 const int lock_count = SignalLockCount();
218 Signal(); 222 Signal();
219 EXPECT_FALSE(InCriticalSection()); 223 EXPECT_FALSE(InCriticalSection());
220 EXPECT_EQ(lock_count + 1, SignalLockCount()); 224 EXPECT_EQ(lock_count + 1, SignalLockCount());
221 EXPECT_EQ(1, signal_count()); 225 EXPECT_EQ(1, signal_count());
222 } 226 }
223 227
224 // Destroy signal and slot in different orders. 228 // Destroy signal and slot in different orders.
225 TEST(DestructionOrder, SignalFirst) { 229 TEST(SigslotDestructionOrder, SignalFirst) {
226 sigslot::signal0<>* signal = new sigslot::signal0<>; 230 sigslot::signal0<>* signal = new sigslot::signal0<>;
227 SigslotReceiver<>* receiver = new SigslotReceiver<>(); 231 SigslotReceiver<>* receiver = new SigslotReceiver<>();
228 receiver->Connect(signal); 232 receiver->Connect(signal);
229 (*signal)(); 233 (*signal)();
230 EXPECT_EQ(1, receiver->signal_count()); 234 EXPECT_EQ(1, receiver->signal_count());
231 delete signal; 235 delete signal;
232 delete receiver; 236 delete receiver;
233 } 237 }
234 238
235 TEST(DestructionOrder, SlotFirst) { 239 TEST(SigslotDestructionOrder, SlotFirst) {
236 sigslot::signal0<>* signal = new sigslot::signal0<>; 240 sigslot::signal0<>* signal = new sigslot::signal0<>;
237 SigslotReceiver<>* receiver = new SigslotReceiver<>(); 241 SigslotReceiver<>* receiver = new SigslotReceiver<>();
238 receiver->Connect(signal); 242 receiver->Connect(signal);
239 (*signal)(); 243 (*signal)();
240 EXPECT_EQ(1, receiver->signal_count()); 244 EXPECT_EQ(1, receiver->signal_count());
241 245
242 delete receiver; 246 delete receiver;
243 (*signal)(); 247 (*signal)();
244 delete signal; 248 delete signal;
245 } 249 }
250
251 // Test that if a signal is copied, its slot connections are copied as well.
252 TEST(SigslotTest, CopyConnectedSignal) {
253 sigslot::signal<> signal;
254 SigslotReceiver<> receiver;
255 receiver.Connect(&signal);
256
257 // Fire the copied signal, expecting the receiver to be notified.
258 sigslot::signal<> copied_signal(signal);
259 copied_signal();
260 EXPECT_EQ(1, receiver.signal_count());
261 }
262
263 // Test that if a slot is copied, its signal connections are copied as well.
264 TEST(SigslotTest, CopyConnectedSlot) {
265 sigslot::signal<> signal;
266 SigslotReceiver<> receiver;
267 receiver.Connect(&signal);
268
269 // Fire the signal after copying the receiver, expecting the copied receiver
270 // to be notified.
271 SigslotReceiver<> copied_receiver(receiver);
272 signal();
273 EXPECT_EQ(1, copied_receiver.signal_count());
274 }
OLDNEW
« no previous file with comments | « webrtc/base/sigslot.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698