From 96e623bcd9a56fdf153a6c82376a9ab0c45aa102 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Wed, 17 Oct 2018 22:09:53 +0200 Subject: [PATCH] tests: Check that sourcePeer() is set in SignalProxyTest 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 | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/common/signalproxytest.cpp b/tests/common/signalproxytest.cpp index c79f0a2d..18b71e1e 100644 --- a/tests/common/signalproxytest.cpp +++ b/tests/common/signalproxytest.cpp @@ -65,20 +65,32 @@ public: using Data = std::pair; using Spy = ValueSpy; - ProxyObject(Spy* spy) + ProxyObject(Spy* spy, Peer* expectedPeer) : _spy{spy} + , _expectedPeer{expectedPeer} {} signals: void sendData(int, const QString&); void sendMoreData(int, const QString&); + void sendToFunctor(int, const QString&); 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; + Peer* _expectedPeer; }; TEST_F(SignalProxyTest, attachSignal) @@ -91,8 +103,8 @@ TEST_F(SignalProxyTest, attachSignal) } 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&))); -- 2.20.1