Fix QDBusAbstractInterface::isValid() for peer connections
Do not attempt to lookup the service owner on peer connections (it will fail). Make QDBusAbstractInterface::isValid() return a sensible result on peer connections, instead of always returning false. Task-number: QTBUG-32374 Change-Id: I1b02feaffb3b255188f8d63306f89f5034a32f22 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
8493f5d6a3
commit
9b8b6c7db8
@ -288,7 +288,8 @@ QDBusAbstractInterface::QDBusAbstractInterface(QDBusAbstractInterfacePrivate &d,
|
||||
if (d.isValid &&
|
||||
d.connection.isConnected()
|
||||
&& !d.service.isEmpty()
|
||||
&& !d.service.startsWith(QLatin1Char(':')))
|
||||
&& !d.service.startsWith(QLatin1Char(':'))
|
||||
&& d.connectionPrivate()->mode != QDBusConnectionPrivate::PeerMode)
|
||||
d_func()->connection.connect(QLatin1String(DBUS_SERVICE_DBUS), // service
|
||||
QString(), // path
|
||||
QLatin1String(DBUS_INTERFACE_DBUS), // interface
|
||||
@ -313,7 +314,8 @@ QDBusAbstractInterface::QDBusAbstractInterface(const QString &service, const QSt
|
||||
if (d_func()->isValid &&
|
||||
d_func()->connection.isConnected()
|
||||
&& !service.isEmpty()
|
||||
&& !service.startsWith(QLatin1Char(':')))
|
||||
&& !service.startsWith(QLatin1Char(':'))
|
||||
&& d_func()->connectionPrivate()->mode != QDBusConnectionPrivate::PeerMode)
|
||||
d_func()->connection.connect(QLatin1String(DBUS_SERVICE_DBUS), // service
|
||||
QString(), // path
|
||||
QLatin1String(DBUS_INTERFACE_DBUS), // interface
|
||||
@ -340,7 +342,13 @@ QDBusAbstractInterface::~QDBusAbstractInterface()
|
||||
*/
|
||||
bool QDBusAbstractInterface::isValid() const
|
||||
{
|
||||
return !d_func()->currentOwner.isEmpty();
|
||||
Q_D(const QDBusAbstractInterface);
|
||||
/* We don't retrieve the owner name for peer connections */
|
||||
if (d->connectionPrivate() && d->connectionPrivate()->mode == QDBusConnectionPrivate::PeerMode) {
|
||||
return d->isValid;
|
||||
} else {
|
||||
return !d->currentOwner.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -70,12 +70,12 @@ class tst_QDBusAbstractInterface: public QObject
|
||||
return Pinger(new com::trolltech::QtDBus::Pinger(service, path, con));
|
||||
}
|
||||
|
||||
Pinger getPingerPeer(const QString &path = "/")
|
||||
Pinger getPingerPeer(const QString &path = "/", const QString &service = "")
|
||||
{
|
||||
QDBusConnection con = QDBusConnection("peer");
|
||||
if (!con.isConnected())
|
||||
return Pinger();
|
||||
return Pinger(new com::trolltech::QtDBus::Pinger("", path, con));
|
||||
return Pinger(new com::trolltech::QtDBus::Pinger(service, path, con));
|
||||
}
|
||||
|
||||
void resetServer()
|
||||
@ -197,6 +197,10 @@ private slots:
|
||||
void directPropertyReadErrorsPeer();
|
||||
void directPropertyWriteErrorsPeer_data();
|
||||
void directPropertyWriteErrorsPeer();
|
||||
|
||||
void validity_data();
|
||||
void validity();
|
||||
|
||||
private:
|
||||
QProcess proc;
|
||||
};
|
||||
@ -1381,5 +1385,23 @@ void tst_QDBusAbstractInterface::directPropertyWriteErrorsPeer()
|
||||
QTEST(p->lastError().name(), "errorName");
|
||||
}
|
||||
|
||||
void tst_QDBusAbstractInterface::validity_data()
|
||||
{
|
||||
QTest::addColumn<QString>("service");
|
||||
|
||||
QTest::newRow("null-service") << "";
|
||||
QTest::newRow("ignored-service") << "org.example.anyservice";
|
||||
}
|
||||
|
||||
void tst_QDBusAbstractInterface::validity()
|
||||
{
|
||||
/* Test case for QTBUG-32374 */
|
||||
QFETCH(QString, service);
|
||||
Pinger p = getPingerPeer("/", service);
|
||||
QVERIFY2(p, "Not connected to D-Bus");
|
||||
|
||||
QVERIFY(p->isValid());
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QDBusAbstractInterface)
|
||||
#include "tst_qdbusabstractinterface.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user