summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKevron Rees <kevron.m.rees@intel.com>2015-01-22 15:00:36 -0800
committerThiago Macieira <thiago.macieira@intel.com>2015-02-15 02:17:53 +0000
commit0eec8c86b604374c3210133822d41df229698b34 (patch)
treeef38b6a2def0b285aa35b57c52fbbe14263640a2 /tests
parent06ecd74db138bcdf6f87df5917f6d5035da41823 (diff)
QDBusConnection::registorObject with interface
Currently QDBus relies on a key in QMetaClassInfo to understand the DBus interface name. This patch allows QDBus to also use a specified interface name in the registerObject call instead of relying on QMetaClassInfo that might not be there (if the QObject was created in QML or Javascript for example). Change-Id: Ie02b2c67e7deb07f43e35eb166c11833fcbf38f3 Task-number: QTBUG-44074 Reviewed-by: Kevron Rees <kevron.m.rees@intel.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/dbus/qdbusconnection/tst_qdbusconnection.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.cpp b/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.cpp
index c9c9152580..32c228c186 100644
--- a/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.cpp
+++ b/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.cpp
@@ -65,6 +65,27 @@ void MyObject::method(const QDBusMessage &msg)
//qDebug() << msg;
}
+class MyObjectWithoutInterface: public QObject
+{
+ Q_OBJECT
+public slots:
+ void method(const QDBusMessage &msg);
+
+public:
+ static QString path;
+ static QString interface;
+ int callCount;
+ MyObjectWithoutInterface(QObject *parent = 0) : QObject(parent), callCount(0) {}
+};
+
+void MyObjectWithoutInterface::method(const QDBusMessage &msg)
+{
+ path = msg.path();
+ interface = msg.interface();
+ ++callCount;
+ //qDebug() << msg;
+}
+
class tst_QDBusConnection: public QObject
{
Q_OBJECT
@@ -87,6 +108,8 @@ private slots:
void registerObject_data();
void registerObject();
+ void registerObjectWithInterface_data();
+ void registerObjectWithInterface();
void registerObjectPeer_data();
void registerObjectPeer();
void registerObject2();
@@ -112,6 +135,7 @@ private slots:
public:
QString serviceName() const { return "org.qtproject.Qt.Autotests.QDBusConnection"; }
bool callMethod(const QDBusConnection &conn, const QString &path);
+ bool callMethod(const QDBusConnection &conn, const QString &path, const QString &interface);
bool callMethodPeer(const QDBusConnection &conn, const QString &path);
};
@@ -379,6 +403,40 @@ void tst_QDBusConnection::registerObject()
QVERIFY(!callMethod(con, path));
}
+void tst_QDBusConnection::registerObjectWithInterface_data()
+{
+ QTest::addColumn<QString>("path");
+ QTest::addColumn<QString>("interface");
+
+ QTest::newRow("/") << "/" << "org.foo";
+ QTest::newRow("/p1") << "/p1" << "org.foo";
+ QTest::newRow("/p2") << "/p2" << "org.foo";
+ QTest::newRow("/p1/q") << "/p1/q" << "org.foo";
+ QTest::newRow("/p1/q/r") << "/p1/q/r" << "org.foo";
+
+}
+
+void tst_QDBusConnection::registerObjectWithInterface()
+{
+ QFETCH(QString, path);
+ QFETCH(QString, interface);
+
+ QDBusConnection con = QDBusConnection::sessionBus();
+ QVERIFY(con.isConnected());
+
+ {
+ // register one object at root:
+ MyObjectWithoutInterface obj;
+ QVERIFY(con.registerObject(path, interface, &obj, QDBusConnection::ExportAllSlots));
+ QCOMPARE(con.objectRegisteredAt(path), static_cast<QObject *>(&obj));
+ QVERIFY(callMethod(con, path, interface));
+ QCOMPARE(obj.path, path);
+ QCOMPARE(obj.interface, interface);
+ }
+ // make sure it's gone
+ QVERIFY(!callMethod(con, path, interface));
+}
+
class MyServer : public QDBusServer
{
Q_OBJECT
@@ -844,6 +902,16 @@ bool tst_QDBusConnection::callMethod(const QDBusConnection &conn, const QString
return (MyObject::path == path);
}
+bool tst_QDBusConnection::callMethod(const QDBusConnection &conn, const QString &path, const QString &interface)
+{
+ QDBusMessage msg = QDBusMessage::createMethodCall(conn.baseService(), path, interface, "method");
+ QDBusMessage reply = conn.call(msg, QDBus::Block/*WithGui*/);
+ if (reply.type() != QDBusMessage::ReplyMessage)
+ return false;
+ QTest::qCompare(MyObjectWithoutInterface::path, path, "MyObjectWithoutInterface::path", "path", __FILE__, __LINE__);
+ return (MyObjectWithoutInterface::path == path) && MyObjectWithoutInterface::interface == interface;
+}
+
bool tst_QDBusConnection::callMethodPeer(const QDBusConnection &conn, const QString &path)
{
QDBusMessage msg = QDBusMessage::createMethodCall("", path, "", "method");
@@ -1307,6 +1375,8 @@ void tst_QDBusConnection::callVirtualObjectLocal()
}
QString MyObject::path;
+QString MyObjectWithoutInterface::path;
+QString MyObjectWithoutInterface::interface;
QTEST_MAIN(tst_QDBusConnection)
#include "tst_qdbusconnection.moc"