diff options
author | Frederik Gladhorn <frederik.gladhorn@nokia.com> | 2011-05-22 19:36:10 (GMT) |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@nokia.com> | 2011-07-04 11:44:14 (GMT) |
commit | b07919b3de8cff3e44b7271062372b14bcda5b83 (patch) | |
tree | fb6e9c5ebbade0756b85819b59eb3efcf0ee242d /tests/auto/qdbusinterface/tst_qdbusinterface.cpp | |
parent | cee1f6454a7b52a52795590e2f793c0cd4e15ce1 (diff) | |
download | Qt-b07919b3de8cff3e44b7271062372b14bcda5b83.zip Qt-b07919b3de8cff3e44b7271062372b14bcda5b83.tar.gz Qt-b07919b3de8cff3e44b7271062372b14bcda5b83.tar.bz2 |
Add DBus VirtualObject to handle multiple paths.
When a virtual object is registered with the SubPath option
it will handle all dbus calls to itself and all child paths.
It needs to reimplement handleMessage for that purpose.
Introspection needs to be implemented manually in the introspect function.
Reviewed-by: Thiago Macieira <thiago.macieira@nokia.com>
Diffstat (limited to 'tests/auto/qdbusinterface/tst_qdbusinterface.cpp')
-rw-r--r-- | tests/auto/qdbusinterface/tst_qdbusinterface.cpp | 71 |
1 files changed, 70 insertions, 1 deletions
diff --git a/tests/auto/qdbusinterface/tst_qdbusinterface.cpp b/tests/auto/qdbusinterface/tst_qdbusinterface.cpp index 96ab311..9156818 100644 --- a/tests/auto/qdbusinterface/tst_qdbusinterface.cpp +++ b/tests/auto/qdbusinterface/tst_qdbusinterface.cpp @@ -200,6 +200,7 @@ private slots: void invalidAfterServiceOwnerChanged(); void introspect(); void introspectUnknownTypes(); + void introspectVirtualObject(); void callMethod(); void invokeMethod(); void invokeMethodWithReturn(); @@ -361,7 +362,6 @@ void tst_QDBusInterface::invalidAfterServiceOwnerChanged() void tst_QDBusInterface::introspect() { - QDBusConnection con = QDBusConnection::sessionBus(); QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"), TEST_INTERFACE_NAME); @@ -394,6 +394,75 @@ void tst_QDBusInterface::introspectUnknownTypes() QVERIFY(mo->indexOfProperty("prop1") != -1); int pidx = mo->indexOfProperty("prop1"); QCOMPARE(mo->property(pidx).typeName(), "QDBusRawType<0x7e>*"); + + + + QDBusMessage message = QDBusMessage::createMethodCall(con.baseService(), "/unknownTypes", "org.freedesktop.DBus.Introspectable", "Introspect"); + QDBusMessage reply = con.call(message, QDBus::Block, 5000); + qDebug() << "REPL: " << reply.arguments(); + +} + + +class VirtualObject: public QDBusVirtualObject +{ + Q_OBJECT +public: + VirtualObject() :success(true) {} + + QString introspect(const QString &path) const { + if (path == "/some/path/superNode") + return "zitroneneis"; + if (path == "/some/path/superNode/foo") + return " <interface name=\"com.trolltech.QtDBus.VirtualObject\">\n" + " <method name=\"klingeling\" />\n" + " </interface>\n" ; + return QString(); + } + + bool handleMessage(const QDBusMessage &message, const QDBusConnection &connection) { + ++callCount; + lastMessage = message; + + if (success) { + QDBusMessage reply = message.createReply(replyArguments); + connection.send(reply); + } + emit messageReceived(message); + return success; + } +signals: + void messageReceived(const QDBusMessage &message) const; + +public: + mutable QDBusMessage lastMessage; + QVariantList replyArguments; + mutable int callCount; + bool success; +}; + +void tst_QDBusInterface::introspectVirtualObject() +{ + QDBusConnection con = QDBusConnection::sessionBus(); + QVERIFY(con.isConnected()); + VirtualObject obj; + + obj.success = false; + + QString path = "/some/path/superNode"; + QVERIFY(con.registerVirtualObject(path, &obj, QDBusConnection::SubPath)); + + QDBusMessage message = QDBusMessage::createMethodCall(con.baseService(), path, "org.freedesktop.DBus.Introspectable", "Introspect"); + QDBusMessage reply = con.call(message, QDBus::Block, 5000); + QVERIFY(reply.arguments().at(0).toString().contains( + QRegExp("<node>.*zitroneneis.*<interface name=") )); + + QDBusMessage message2 = QDBusMessage::createMethodCall(con.baseService(), path + "/foo", "org.freedesktop.DBus.Introspectable", "Introspect"); + QDBusMessage reply2 = con.call(message2, QDBus::Block, 5000); + QVERIFY(reply2.arguments().at(0).toString().contains( + QRegExp("<node>.*<interface name=\"com.trolltech.QtDBus.VirtualObject\">" + ".*<method name=\"klingeling\" />\n" + ".*</interface>.*<interface name=") )); } void tst_QDBusInterface::callMethod() |