From 7b6b9201bdc6435aaa50370c8cf511e47f6e630d Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 16 Feb 2011 14:05:54 +0100 Subject: Autotest: check that the type received is the expected one Task-number: QTBUG-17476 --- tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp | 51 ++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp b/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp index 0c53087..9bae6af 100644 --- a/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp +++ b/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp @@ -96,6 +96,19 @@ private: QProcess proc; }; +class QDBusMessageSpy: public QObject +{ + Q_OBJECT +public slots: + Q_SCRIPTABLE int theSlot(const QDBusMessage &msg) + { + list << msg; + return 42; + } +public: + QList list; +}; + struct UnregisteredType { }; Q_DECLARE_METATYPE(UnregisteredType) @@ -923,11 +936,12 @@ void tst_QDBusMarshall::sendCallErrors() void tst_QDBusMarshall::receiveUnknownType_data() { - QTest::newRow("in-call"); - QTest::newRow("type-variant"); - QTest::newRow("type-array"); - QTest::newRow("type-struct"); - QTest::newRow("type-naked"); + QTest::addColumn("receivedTypeId"); + QTest::newRow("in-call") << qMetaTypeId(); + QTest::newRow("type-variant") << qMetaTypeId(); + QTest::newRow("type-array") << qMetaTypeId(); + QTest::newRow("type-struct") << qMetaTypeId(); + QTest::newRow("type-naked") << qMetaTypeId(); } struct DisconnectRawDBus { @@ -974,7 +988,9 @@ void tst_QDBusMarshall::receiveUnknownType() if (qstrcmp(QTest::currentDataTag(), "in-call") == 0) { // create a call back to us containing a file descriptor - ScopedDBusMessage msg(dbus_message_new_method_call(con.baseService().toLatin1(), "/irrelevant/path", NULL, "irrelevantMethod")); + QDBusMessageSpy spy; + con.registerObject("/spyObject", &spy, QDBusConnection::ExportAllSlots); + ScopedDBusMessage msg(dbus_message_new_method_call(con.baseService().toLatin1(), "/spyObject", NULL, "theSlot")); int fd = fileno(stdout); dbus_message_append_args(msg.data(), DBUS_TYPE_UNIX_FD, &fd, DBUS_TYPE_INVALID); @@ -995,10 +1011,21 @@ void tst_QDBusMarshall::receiveUnknownType() // now try to receive the reply dbus_pending_call_block(pending.data()); + + // check that the spy received what it was supposed to receive + QCOMPARE(spy.list.size(), 1); + QCOMPARE(spy.list.at(0).arguments().size(), 1); + QFETCH(int, receivedTypeId); + QCOMPARE(spy.list.at(0).arguments().at(0).userType(), receivedTypeId); + msg.reset(dbus_pending_call_steal_reply(pending.data())); QVERIFY(msg); - QCOMPARE(dbus_message_get_type(msg.data()), DBUS_MESSAGE_TYPE_ERROR); - QCOMPARE(dbus_message_get_error_name(msg.data()), "org.freedesktop.DBus.Error.UnknownObject"); + QCOMPARE(dbus_message_get_type(msg.data()), DBUS_MESSAGE_TYPE_METHOD_RETURN); + QCOMPARE(dbus_message_get_signature(msg.data()), DBUS_TYPE_INT32_AS_STRING); + + int retval; + QVERIFY(dbus_message_get_args(msg.data(), &error, DBUS_TYPE_INT32, &retval, DBUS_TYPE_INVALID)); + QCOMPARE(retval, 42); } else { // create a signal that we'll emit static const char signalName[] = "signalName"; @@ -1006,6 +1033,9 @@ void tst_QDBusMarshall::receiveUnknownType() ScopedDBusMessage msg(dbus_message_new_signal("/", interfaceName, signalName)); con.connect(dbus_bus_get_unique_name(rawcon.data()), QString(), interfaceName, signalName, &QTestEventLoop::instance(), SLOT(exitLoop())); + QDBusMessageSpy spy; + con.connect(dbus_bus_get_unique_name(rawcon.data()), QString(), interfaceName, signalName, &spy, SLOT(theSlot(QDBusMessage))); + DBusMessageIter iter; dbus_message_iter_init_append(msg.data(), &iter); int fd = fileno(stdout); @@ -1035,6 +1065,11 @@ void tst_QDBusMarshall::receiveUnknownType() // now let's see what happens QTestEventLoop::instance().enterLoop(1); QVERIFY(!QTestEventLoop::instance().timeout()); + QCOMPARE(spy.list.size(), 1); + QCOMPARE(spy.list.at(0).arguments().count(), 1); + QFETCH(int, receivedTypeId); + //qDebug() << spy.list.at(0).arguments().at(0).typeName(); + QCOMPARE(spy.list.at(0).arguments().at(0).userType(), receivedTypeId); } #endif } -- cgit v0.12