tests: Check that sourcePeer() is set in SignalProxyTest
authorManuel Nickschas <sputnick@quassel-irc.org>
Wed, 17 Oct 2018 20:09:53 +0000 (22:09 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 18 Nov 2018 10:06:43 +0000 (11:06 +0100)
We expect SignalProxy::current()->sourcePeer() to be set to the
currently sending peer when handling a signal, so add a check
for this to SignalProxyTest.

tests/common/signalproxytest.cpp

index c79f0a2..18b71e1 100644 (file)
@@ -65,20 +65,32 @@ public:
     using Data = std::pair<int, QString>;
     using Spy = ValueSpy<Data>;
 
     using Data = std::pair<int, QString>;
     using Spy = ValueSpy<Data>;
 
-    ProxyObject(Spy* spy)
+    ProxyObject(Spy* spy, Peer* expectedPeer)
         : _spy{spy}
         : _spy{spy}
+        , _expectedPeer{expectedPeer}
     {}
 
 signals:
     void sendData(int, const QString&);
     void sendMoreData(int, const QString&);
     {}
 
 signals:
     void sendData(int, const QString&);
     void sendMoreData(int, const QString&);
+    void sendToFunctor(int, const QString&);
 
 public slots:
 
 public slots:
-    void receiveData(int i, const QString& s) { _spy->notify(std::make_pair(i, s)); }
-    void receiveExtraData(int i, const QString& s) { _spy->notify(std::make_pair(-i, s.toUpper())); }
+    void receiveData(int i, const QString& s)
+    {
+        EXPECT_EQ(_expectedPeer, SignalProxy::current()->sourcePeer());
+        _spy->notify(std::make_pair(i, s));
+    }
+
+    void receiveExtraData(int i, const QString& s)
+    {
+        EXPECT_EQ(_expectedPeer, SignalProxy::current()->sourcePeer());
+        _spy->notify(std::make_pair(-i, s.toUpper()));
+    }
 
 private:
     Spy* _spy;
 
 private:
     Spy* _spy;
+    Peer* _expectedPeer;
 };
 
 TEST_F(SignalProxyTest, attachSignal)
 };
 
 TEST_F(SignalProxyTest, attachSignal)
@@ -91,8 +103,8 @@ TEST_F(SignalProxyTest, attachSignal)
     }
 
     ProxyObject::Spy clientSpy, serverSpy;
     }
 
     ProxyObject::Spy clientSpy, serverSpy;
-    ProxyObject clientObject{&clientSpy};
-    ProxyObject serverObject{&serverSpy};
+    ProxyObject clientObject{&clientSpy, _clientPeer};
+    ProxyObject serverObject{&serverSpy, _serverPeer};
 
     // Deliberately not normalize some of the macro invocations
     _clientProxy.attachSignal(&clientObject, SIGNAL(sendData(int, const QString&)));
 
     // Deliberately not normalize some of the macro invocations
     _clientProxy.attachSignal(&clientObject, SIGNAL(sendData(int, const QString&)));