summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2009-11-19 12:21:04 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2009-11-24 20:29:53 (GMT)
commit8a820c790f2316052819148e344a3cd197877433 (patch)
treec89750f9efe2ee7681d829b334e7cfecdfda1f3f /tests
parent70d0d80e5cc11f98778234ddd20ce668551e9d9d (diff)
downloadQt-8a820c790f2316052819148e344a3cd197877433.zip
Qt-8a820c790f2316052819148e344a3cd197877433.tar.gz
Qt-8a820c790f2316052819148e344a3cd197877433.tar.bz2
Fix the detection of when this process gets names on the bus.
Previously, we were relying on NameOwnerChanged to notify us of our own names. This worked because we got all NameOwnerChanged that happened on the bus. Now, we only get those we're interested in. Instead of watching for newOwner==baseService, let's just use the NameAcquired and NameLost signals, that the D-Bus server sends to us anyway. Task-number: QTBUG-5979
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qdbusconnection/tst_qdbusconnection.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/auto/qdbusconnection/tst_qdbusconnection.cpp b/tests/auto/qdbusconnection/tst_qdbusconnection.cpp
index bb034a3..c1976c0 100644
--- a/tests/auto/qdbusconnection/tst_qdbusconnection.cpp
+++ b/tests/auto/qdbusconnection/tst_qdbusconnection.cpp
@@ -96,6 +96,8 @@ private slots:
void registerQObjectChildren();
void callSelf();
+ void callSelfByAnotherName_data();
+ void callSelfByAnotherName();
void multipleInterfacesInQObject();
void slotsWithLessParameters();
@@ -493,6 +495,70 @@ void tst_QDBusConnection::callSelf()
QCOMPARE(reply.arguments().value(0).toInt(), 45);
}
+void tst_QDBusConnection::callSelfByAnotherName_data()
+{
+ QTest::addColumn<int>("registerMethod");
+ QTest::newRow("connection") << 0;
+ QTest::newRow("connection-interface") << 1;
+ QTest::newRow("direct") << 2;
+}
+
+void tst_QDBusConnection::callSelfByAnotherName()
+{
+ static int counter = 0;
+ QString sname = serviceName() + QString::number(counter++);
+
+ QDBusConnection con = QDBusConnection::sessionBus();
+ QVERIFY(con.isConnected());
+
+ TestObject testObject;
+ QVERIFY(con.registerObject("/test", &testObject,
+ QDBusConnection::ExportAllContents));
+ con.connect("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "NameOwnerChanged",
+ QStringList() << sname << "",
+ QString(), &QTestEventLoop::instance(), SLOT(exitLoop()));
+
+ // register the name
+ QFETCH(int, registerMethod);
+ switch (registerMethod) {
+ case 0:
+ QVERIFY(con.registerService(sname));
+ break;
+
+ case 1:
+ QVERIFY(con.interface()->registerService(sname).value() == QDBusConnectionInterface::ServiceRegistered);
+ break;
+
+ case 2: {
+ // flag is DBUS_NAME_FLAG_DO_NOT_QUEUE = 0x04
+ // reply is DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER = 1
+ QDBusReply<uint> reply = con.interface()->call("RequestName", sname, 4u);
+ QVERIFY(reply.value() == 1);
+ }
+ }
+
+ struct Deregisterer {
+ QDBusConnection con;
+ QString sname;
+ Deregisterer(const QDBusConnection &con, const QString &sname) : con(con), sname(sname) {}
+ ~Deregisterer() { con.interface()->unregisterService(sname); }
+ } deregisterer(con, sname);
+
+ // give the connection a chance to find out that we're good to go
+ QTestEventLoop::instance().enterLoop(2);
+ con.disconnect("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "NameOwnerChanged",
+ QStringList() << sname << "",
+ QString(), &QTestEventLoop::instance(), SLOT(exitLoop()));
+ QVERIFY(!QTestEventLoop::instance().timeout());
+
+ // make the call
+ QDBusMessage msg = QDBusMessage::createMethodCall(sname, "/test",
+ QString(), "test0");
+ QDBusMessage reply = con.call(msg, QDBus::Block, 1000);
+
+ QVERIFY(reply.type() == QDBusMessage::ReplyMessage);
+}
+
void tst_QDBusConnection::multipleInterfacesInQObject()
{
QDBusConnection con = QDBusConnection::sessionBus();