Remove the hardcoding of Unix socket paths for QtDBus

This allows the tests to be run on Windows too by using TCP socket
connections instead of requiring Unix sockets. The tests shouldn't have
hardcoded the path, which came from QDBusServer anyway. Now the tests
simply defer to QDBusServer.

This is a slight behavior change for Windows, but not one that should
matter since anyone who was using the default constructor resulted in a
QDBusServer that failed to listen.

[ChangeLog][QtDBus][QDBusServer] Fixed a bug that made QDBusServer's
default constructor try to bind to a Unix socket on non-Unix systems.
Now QDBusServer will attempt to bind to a TCP socket instead.

Change-Id: I2a126019671c2d90257e739ed3aff7938d1fe946
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
This commit is contained in:
Thiago Macieira 2014-12-11 14:37:11 -08:00
parent 9434162eda
commit 7b6ab50c68
5 changed files with 21 additions and 18 deletions

View File

@ -72,12 +72,18 @@ QDBusServer::QDBusServer(const QString &address, QObject *parent)
/*! /*!
Constructs a QDBusServer with the given \a parent. The server will listen Constructs a QDBusServer with the given \a parent. The server will listen
for connections in \c {/tmp}. for connections in \c {/tmp} (on Unix systems) or on a TCP port bound to
localhost (elsewhere).
*/ */
QDBusServer::QDBusServer(QObject *parent) QDBusServer::QDBusServer(QObject *parent)
: QObject(parent) : QObject(parent)
{ {
const QString address = QLatin1String("unix:tmpdir=/tmp"); #ifdef Q_OS_UNIX
// Use Unix sockets on Unix systems only
static const char address[] = "unix:tmpdir=/tmp";
#else
static const char address[] = "tcp:";
#endif
if (!qdbus_loadLibDBus()) { if (!qdbus_loadLibDBus()) {
d = 0; d = 0;
@ -89,7 +95,7 @@ QDBusServer::QDBusServer(QObject *parent)
this, SIGNAL(newConnection(QDBusConnection))); this, SIGNAL(newConnection(QDBusConnection)));
QDBusErrorInternal error; QDBusErrorInternal error;
d->setServer(q_dbus_server_listen(address.toUtf8().constData(), error), error); d->setServer(q_dbus_server_listen(address, error), error);
} }
/*! /*!

View File

@ -50,8 +50,8 @@ class MyServer : public QDBusServer
Q_CLASSINFO("D-Bus Interface", "org.qtproject.autotests.qmyserver") Q_CLASSINFO("D-Bus Interface", "org.qtproject.autotests.qmyserver")
public: public:
MyServer(QString addr = "unix:tmpdir=/tmp", QObject* parent = 0) MyServer(QObject* parent = 0)
: QDBusServer(addr, parent), : QDBusServer(parent),
m_conn("none"), m_conn("none"),
obj(NULL) obj(NULL)
{ {

View File

@ -43,8 +43,8 @@ class PingerServer : public QDBusServer
Q_OBJECT Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.qtproject.autotests.qpinger") Q_CLASSINFO("D-Bus Interface", "org.qtproject.autotests.qpinger")
public: public:
PingerServer(QString addr = "unix:tmpdir=/tmp", QObject* parent = 0) PingerServer(QObject* parent = 0)
: QDBusServer(addr, parent), : QDBusServer(parent),
m_conn("none") m_conn("none")
{ {
connect(this, SIGNAL(newConnection(QDBusConnection)), SLOT(handleConnection(QDBusConnection))); connect(this, SIGNAL(newConnection(QDBusConnection)), SLOT(handleConnection(QDBusConnection)));

View File

@ -296,7 +296,7 @@ void tst_QDBusConnection::connectToPeer()
QVERIFY(con.lastError().isValid()); QVERIFY(con.lastError().isValid());
} }
QDBusServer server("unix:tmpdir=/tmp", 0); QDBusServer server;
{ {
QDBusConnection con = QDBusConnection::connectToPeer( QDBusConnection con = QDBusConnection::connectToPeer(
@ -381,9 +381,7 @@ class MyServer : public QDBusServer
{ {
Q_OBJECT Q_OBJECT
public: public:
MyServer(QString path, QString addr, QObject* parent) : QDBusServer(addr, parent), MyServer(QString path) : m_path(path), m_connections()
m_path(path),
m_connections()
{ {
connect(this, SIGNAL(newConnection(QDBusConnection)), SLOT(handleConnection(QDBusConnection))); connect(this, SIGNAL(newConnection(QDBusConnection)), SLOT(handleConnection(QDBusConnection)));
} }
@ -446,7 +444,7 @@ void tst_QDBusConnection::registerObjectPeer()
{ {
QFETCH(QString, path); QFETCH(QString, path);
MyServer server(path, "unix:tmpdir=/tmp", 0); MyServer server(path);
QDBusConnection::connectToPeer(server.address(), "beforeFoo"); QDBusConnection::connectToPeer(server.address(), "beforeFoo");
@ -594,8 +592,7 @@ class MyServer2 : public QDBusServer
{ {
Q_OBJECT Q_OBJECT
public: public:
MyServer2(QString addr, QObject* parent) : QDBusServer(addr, parent), MyServer2() : m_conn("none")
m_conn("none")
{ {
connect(this, SIGNAL(newConnection(QDBusConnection)), SLOT(handleConnection(QDBusConnection))); connect(this, SIGNAL(newConnection(QDBusConnection)), SLOT(handleConnection(QDBusConnection)));
} }
@ -620,7 +617,7 @@ private:
void tst_QDBusConnection::registerObjectPeer2() void tst_QDBusConnection::registerObjectPeer2()
{ {
MyServer2 server("unix:tmpdir=/tmp", 0); MyServer2 server;
QDBusConnection con = QDBusConnection::connectToPeer(server.address(), "foo"); QDBusConnection con = QDBusConnection::connectToPeer(server.address(), "foo");
QCoreApplication::processEvents(); QCoreApplication::processEvents();
QVERIFY(con.isConnected()); QVERIFY(con.isConnected());
@ -775,7 +772,7 @@ void tst_QDBusConnection::registerQObjectChildren()
void tst_QDBusConnection::registerQObjectChildrenPeer() void tst_QDBusConnection::registerQObjectChildrenPeer()
{ {
MyServer2 server("unix:tmpdir=/tmp", 0); MyServer2 server;
QDBusConnection con = QDBusConnection::connectToPeer(server.address(), "foo"); QDBusConnection con = QDBusConnection::connectToPeer(server.address(), "foo");
QCoreApplication::processEvents(); QCoreApplication::processEvents();
QVERIFY(con.isConnected()); QVERIFY(con.isConnected());

View File

@ -48,8 +48,8 @@ class MyServer : public QDBusServer
Q_CLASSINFO("D-Bus Interface", "org.qtproject.autotests.qmyserver") Q_CLASSINFO("D-Bus Interface", "org.qtproject.autotests.qmyserver")
public: public:
MyServer(QString addr = "unix:tmpdir=/tmp", QObject* parent = 0) MyServer(QObject* parent = 0)
: QDBusServer(addr, parent), : QDBusServer(parent),
m_conn("none") m_conn("none")
{ {
connect(this, SIGNAL(newConnection(QDBusConnection)), SLOT(handleConnection(QDBusConnection))); connect(this, SIGNAL(newConnection(QDBusConnection)), SLOT(handleConnection(QDBusConnection)));