tst_QDBusConnection: add a test for a regular signal connection
Since it's a slot with the same name as an existing one, this test also verifies that QDBusConnection::connect() can properly distinguish between overloads. This test moves the receiver out of the main class, just to be sure that we don't leave connections behind when tests are run (like slotsWithLessParameters did). Change-Id: I87e17314d8b24ae983b1fffd1453ad81952c49aa Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
parent
169f1beaf5
commit
5fa3e2a82e
@ -1057,6 +1057,38 @@ void tst_QDBusConnection::multipleInterfacesInQObject()
|
|||||||
QVERIFY_HOOKCALLED();
|
QVERIFY_HOOKCALLED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QDBusConnection::connectSignal()
|
||||||
|
{
|
||||||
|
if (!QCoreApplication::instance())
|
||||||
|
QSKIP("Test requires a QCoreApplication");
|
||||||
|
|
||||||
|
QDBusConnection con = QDBusConnection::sessionBus();
|
||||||
|
|
||||||
|
QDBusMessage signal = QDBusMessage::createSignal("/", "org.qtproject.TestCase",
|
||||||
|
"oneSignal");
|
||||||
|
signal << "one parameter";
|
||||||
|
|
||||||
|
SignalReceiver recv;
|
||||||
|
QVERIFY(con.connect(con.baseService(), signal.path(), signal.interface(),
|
||||||
|
signal.member(), &recv, SLOT(oneSlot(QString))));
|
||||||
|
QVERIFY(con.send(signal));
|
||||||
|
QTest::qWait(100);
|
||||||
|
QCOMPARE(recv.argumentReceived, signal.arguments().at(0).toString());
|
||||||
|
QCOMPARE(recv.signalsReceived, 1);
|
||||||
|
|
||||||
|
// disconnect and try with a signature
|
||||||
|
recv.argumentReceived.clear();
|
||||||
|
recv.signalsReceived = 0;
|
||||||
|
QVERIFY(con.disconnect(con.baseService(), signal.path(), signal.interface(),
|
||||||
|
signal.member(), &recv, SLOT(oneSlot(QString))));
|
||||||
|
QVERIFY(con.connect(con.baseService(), signal.path(), signal.interface(),
|
||||||
|
signal.member(), "s", &recv, SLOT(oneSlot(QString))));
|
||||||
|
QVERIFY(con.send(signal));
|
||||||
|
QTest::qWait(100);
|
||||||
|
QCOMPARE(recv.argumentReceived, signal.arguments().at(0).toString());
|
||||||
|
QCOMPARE(recv.signalsReceived, 1);
|
||||||
|
}
|
||||||
|
|
||||||
void tst_QDBusConnection::slotsWithLessParameters()
|
void tst_QDBusConnection::slotsWithLessParameters()
|
||||||
{
|
{
|
||||||
if (!QCoreApplication::instance())
|
if (!QCoreApplication::instance())
|
||||||
@ -1068,25 +1100,27 @@ void tst_QDBusConnection::slotsWithLessParameters()
|
|||||||
"oneSignal");
|
"oneSignal");
|
||||||
signal << "one parameter";
|
signal << "one parameter";
|
||||||
|
|
||||||
signalsReceived = 0;
|
SignalReceiver recv;
|
||||||
QVERIFY(con.connect(con.baseService(), signal.path(), signal.interface(),
|
QVERIFY(con.connect(con.baseService(), signal.path(), signal.interface(),
|
||||||
signal.member(), this, SLOT(oneSlot())));
|
signal.member(), &recv, SLOT(oneSlot())));
|
||||||
QVERIFY(con.send(signal));
|
QVERIFY(con.send(signal));
|
||||||
QTest::qWait(100);
|
QTest::qWait(100);
|
||||||
QCOMPARE(signalsReceived, 1);
|
QCOMPARE(recv.argumentReceived, QString());
|
||||||
|
QCOMPARE(recv.signalsReceived, 1);
|
||||||
|
|
||||||
// disconnect and try with a signature
|
// disconnect and try with a signature
|
||||||
signalsReceived = 0;
|
recv.signalsReceived = 0;
|
||||||
QVERIFY(con.disconnect(con.baseService(), signal.path(), signal.interface(),
|
QVERIFY(con.disconnect(con.baseService(), signal.path(), signal.interface(),
|
||||||
signal.member(), this, SLOT(oneSlot())));
|
signal.member(), &recv, SLOT(oneSlot())));
|
||||||
QVERIFY(con.connect(con.baseService(), signal.path(), signal.interface(),
|
QVERIFY(con.connect(con.baseService(), signal.path(), signal.interface(),
|
||||||
signal.member(), "s", this, SLOT(oneSlot())));
|
signal.member(), "s", &recv, SLOT(oneSlot())));
|
||||||
QVERIFY(con.send(signal));
|
QVERIFY(con.send(signal));
|
||||||
QTest::qWait(100);
|
QTest::qWait(100);
|
||||||
QCOMPARE(signalsReceived, 1);
|
QCOMPARE(recv.argumentReceived, QString());
|
||||||
|
QCOMPARE(recv.signalsReceived, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QDBusConnection::secondCallWithCallback()
|
void SignalReceiver::secondCallWithCallback()
|
||||||
{
|
{
|
||||||
QDBusConnection con = QDBusConnection::sessionBus();
|
QDBusConnection con = QDBusConnection::sessionBus();
|
||||||
QDBusMessage msg = QDBusMessage::createMethodCall(con.baseService(), "/test", QString(),
|
QDBusMessage msg = QDBusMessage::createMethodCall(con.baseService(), "/test", QString(),
|
||||||
@ -1106,12 +1140,12 @@ void tst_QDBusConnection::nestedCallWithCallback()
|
|||||||
|
|
||||||
QDBusMessage msg = QDBusMessage::createMethodCall(connection.baseService(), "/test", QString(),
|
QDBusMessage msg = QDBusMessage::createMethodCall(connection.baseService(), "/test", QString(),
|
||||||
"ThisFunctionDoesntExist");
|
"ThisFunctionDoesntExist");
|
||||||
signalsReceived = 0;
|
|
||||||
|
|
||||||
connection.callWithCallback(msg, this, SLOT(exitLoop()), SLOT(secondCallWithCallback()), 10);
|
SignalReceiver recv;
|
||||||
|
connection.callWithCallback(msg, &recv, SLOT(exitLoop()), SLOT(secondCallWithCallback()), 10);
|
||||||
QTestEventLoop::instance().enterLoop(15);
|
QTestEventLoop::instance().enterLoop(15);
|
||||||
QVERIFY(!QTestEventLoop::instance().timeout());
|
QVERIFY(!QTestEventLoop::instance().timeout());
|
||||||
QCOMPARE(signalsReceived, 1);
|
QCOMPARE(recv.signalsReceived, 1);
|
||||||
QCOMPARE_HOOKCOUNT(2);
|
QCOMPARE_HOOKCOUNT(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,20 +69,30 @@ public:
|
|||||||
MyObjectWithoutInterface(QObject *parent = 0) : QObject(parent), callCount(0) {}
|
MyObjectWithoutInterface(QObject *parent = 0) : QObject(parent), callCount(0) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class SignalReceiver : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
QString argumentReceived;
|
||||||
|
int signalsReceived;
|
||||||
|
SignalReceiver() : signalsReceived(0) {}
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void oneSlot(const QString &arg) { ++signalsReceived; argumentReceived = arg;}
|
||||||
|
void oneSlot() { ++signalsReceived; }
|
||||||
|
void exitLoop() { ++signalsReceived; QTestEventLoop::instance().exitLoop(); }
|
||||||
|
void secondCallWithCallback();
|
||||||
|
};
|
||||||
|
|
||||||
class tst_QDBusConnection: public QObject
|
class tst_QDBusConnection: public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
int signalsReceived;
|
|
||||||
public:
|
public:
|
||||||
static int hookCallCount;
|
static int hookCallCount;
|
||||||
tst_QDBusConnection();
|
tst_QDBusConnection();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void oneSlot() { ++signalsReceived; }
|
|
||||||
void exitLoop() { ++signalsReceived; QTestEventLoop::instance().exitLoop(); }
|
|
||||||
void secondCallWithCallback();
|
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
@ -115,6 +125,7 @@ private slots:
|
|||||||
void callSelfByAnotherName();
|
void callSelfByAnotherName();
|
||||||
void multipleInterfacesInQObject();
|
void multipleInterfacesInQObject();
|
||||||
|
|
||||||
|
void connectSignal();
|
||||||
void slotsWithLessParameters();
|
void slotsWithLessParameters();
|
||||||
void nestedCallWithCallback();
|
void nestedCallWithCallback();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user