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
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)
: 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()) {
d = 0;
@ -89,7 +95,7 @@ QDBusServer::QDBusServer(QObject *parent)
this, SIGNAL(newConnection(QDBusConnection)));
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")
public:
MyServer(QString addr = "unix:tmpdir=/tmp", QObject* parent = 0)
: QDBusServer(addr, parent),
MyServer(QObject* parent = 0)
: QDBusServer(parent),
m_conn("none"),
obj(NULL)
{

View File

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

View File

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

View File

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