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

Unified 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, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/base/sigslot.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/sigslot_unittest.cc
diff --git a/webrtc/base/sigslot_unittest.cc b/webrtc/base/sigslot_unittest.cc
index cb773363101b93e3f0ee05f3c3208ddbc7a69cea..e860fe33736da248646b40e475d92ccdf9b7d351 100644
--- a/webrtc/base/sigslot_unittest.cc
+++ b/webrtc/base/sigslot_unittest.cc
@@ -36,6 +36,10 @@ class SigslotReceiver : public sigslot::has_slots<slot_policy> {
~SigslotReceiver() {
}
+ // Provide copy constructor so that tests can exercise the has_slots copy
+ // constructor.
+ SigslotReceiver(const SigslotReceiver&) = default;
+
void Connect(sigslot::signal0<signal_policy>* signal) {
if (!signal) return;
Disconnect();
@@ -222,7 +226,7 @@ TEST_F(SigslotMTLockTest, LockSanity) {
}
// Destroy signal and slot in different orders.
-TEST(DestructionOrder, SignalFirst) {
+TEST(SigslotDestructionOrder, SignalFirst) {
sigslot::signal0<>* signal = new sigslot::signal0<>;
SigslotReceiver<>* receiver = new SigslotReceiver<>();
receiver->Connect(signal);
@@ -232,7 +236,7 @@ TEST(DestructionOrder, SignalFirst) {
delete receiver;
}
-TEST(DestructionOrder, SlotFirst) {
+TEST(SigslotDestructionOrder, SlotFirst) {
sigslot::signal0<>* signal = new sigslot::signal0<>;
SigslotReceiver<>* receiver = new SigslotReceiver<>();
receiver->Connect(signal);
@@ -243,3 +247,28 @@ TEST(DestructionOrder, SlotFirst) {
(*signal)();
delete signal;
}
+
+// Test that if a signal is copied, its slot connections are copied as well.
+TEST(SigslotTest, CopyConnectedSignal) {
+ sigslot::signal<> signal;
+ SigslotReceiver<> receiver;
+ receiver.Connect(&signal);
+
+ // Fire the copied signal, expecting the receiver to be notified.
+ sigslot::signal<> copied_signal(signal);
+ copied_signal();
+ EXPECT_EQ(1, receiver.signal_count());
+}
+
+// Test that if a slot is copied, its signal connections are copied as well.
+TEST(SigslotTest, CopyConnectedSlot) {
+ sigslot::signal<> signal;
+ SigslotReceiver<> receiver;
+ receiver.Connect(&signal);
+
+ // Fire the signal after copying the receiver, expecting the copied receiver
+ // to be notified.
+ SigslotReceiver<> copied_receiver(receiver);
+ signal();
+ EXPECT_EQ(1, copied_receiver.signal_count());
+}
« 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