forked from robingarbo/qt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-1 int…
…o master-integration * 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-1: QtDBus: Add unit tests for QDBusAbstractAdaptor QtDBus: Add unit tests for QDBusInterface QtDBus: Add unit tests for QDBusAbstractInterface QtDBus: Register QDBusServer connection name in QDBusConnectionManager QtDBus: Skip bus name check for peer-to-peer connection QtDBus: Fix minor coding style issues QtDBus: Add default constructor to QDBusServer QtDBus: Add unit tests for peer-to-peer connection QtDBus: Add method QDBusConnection::disconnectFromPeer() QtDBus: Add method QDBusConnection::connectToPeer() QtDBus: Fix QDBusConnection::disconnectFromBus() for peer-to-peer connections QtDBus: Fix bus in peer-to-peer connections should not be used QtDBus: Fix empty service name in peer-to-peer connections QtDBus: Fix registering objects using path '/' in peer-to-peer connections QtDBus: Fix QDBusServer to handle correctly new dbus connections QtDBus: Cleaning comments, spacing, etc.
Showing
28 changed files
with
3,426 additions
and
545 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/**************************************************************************** | ||
** | ||
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). | ||
** All rights reserved. | ||
** Contact: Nokia Corporation (qt-info@nokia.com) | ||
** | ||
** This file is part of the QtDBus module of the Qt Toolkit. | ||
** | ||
** $QT_BEGIN_LICENSE:LGPL$ | ||
** No Commercial Usage | ||
** This file contains pre-release code and may not be distributed. | ||
** You may use this file in accordance with the terms and conditions | ||
** contained in the Technology Preview License Agreement accompanying | ||
** this package. | ||
** | ||
** GNU Lesser General Public License Usage | ||
** Alternatively, this file may be used under the terms of the GNU Lesser | ||
** General Public License version 2.1 as published by the Free Software | ||
** Foundation and appearing in the file LICENSE.LGPL included in the | ||
** packaging of this file. Please review the following information to | ||
** ensure the GNU Lesser General Public License version 2.1 requirements | ||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
** | ||
** In addition, as a special exception, Nokia gives you certain additional | ||
** rights. These rights are described in the Nokia Qt LGPL Exception | ||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
** | ||
** If you have questions regarding the use of this file, please contact | ||
** Nokia at qt-info@nokia.com. | ||
** | ||
** | ||
** | ||
** | ||
** | ||
** | ||
** | ||
** | ||
** $QT_END_LICENSE$ | ||
** | ||
****************************************************************************/ | ||
|
||
// | ||
// W A R N I N G | ||
// ------------- | ||
// | ||
// This file is not part of the public API. This header file may | ||
// change from version to version without notice, or even be | ||
// removed. | ||
// | ||
// We mean it. | ||
// | ||
// | ||
|
||
#ifndef QDBUSCONNECTIONMANAGER_P_H | ||
#define QDBUSCONNECTIONMANAGER_P_H | ||
|
||
#include "qdbusconnection_p.h" | ||
|
||
#ifndef QT_NO_DBUS | ||
|
||
QT_BEGIN_NAMESPACE | ||
|
||
class QDBusConnectionManager | ||
{ | ||
public: | ||
QDBusConnectionManager() {} | ||
~QDBusConnectionManager(); | ||
static QDBusConnectionManager* instance(); | ||
|
||
QDBusConnectionPrivate *connection(const QString &name) const; | ||
void removeConnection(const QString &name); | ||
void setConnection(const QString &name, QDBusConnectionPrivate *c); | ||
|
||
QDBusConnectionPrivate *sender() const; | ||
void setSender(const QDBusConnectionPrivate *s); | ||
|
||
mutable QMutex mutex; | ||
private: | ||
QHash<QString, QDBusConnectionPrivate *> connectionHash; | ||
|
||
mutable QMutex senderMutex; | ||
QString senderName; // internal; will probably change | ||
}; | ||
|
||
QT_END_NAMESPACE | ||
|
||
#endif // QT_NO_DBUS | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,286 @@ | ||
/**************************************************************************** | ||
** | ||
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). | ||
** All rights reserved. | ||
** Contact: Nokia Corporation (qt-info@nokia.com) | ||
** | ||
** This file is part of the test suite of the Qt Toolkit. | ||
** | ||
** $QT_BEGIN_LICENSE:LGPL$ | ||
** No Commercial Usage | ||
** This file contains pre-release code and may not be distributed. | ||
** You may use this file in accordance with the terms and conditions | ||
** contained in the Technology Preview License Agreement accompanying | ||
** this package. | ||
** | ||
** GNU Lesser General Public License Usage | ||
** Alternatively, this file may be used under the terms of the GNU Lesser | ||
** General Public License version 2.1 as published by the Free Software | ||
** Foundation and appearing in the file LICENSE.LGPL included in the | ||
** packaging of this file. Please review the following information to | ||
** ensure the GNU Lesser General Public License version 2.1 requirements | ||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
** | ||
** In addition, as a special exception, Nokia gives you certain additional | ||
** rights. These rights are described in the Nokia Qt LGPL Exception | ||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
** | ||
** If you have questions regarding the use of this file, please contact | ||
** Nokia at qt-info@nokia.com. | ||
** | ||
** | ||
** | ||
** | ||
** | ||
** | ||
** | ||
** | ||
** $QT_END_LICENSE$ | ||
** | ||
****************************************************************************/ | ||
|
||
#ifndef MYOBJECT_H | ||
#define MYOBJECT_H | ||
|
||
#include <QtCore/QObject> | ||
#include <QtDBus/QtDBus> | ||
|
||
extern const char *slotSpy; | ||
extern QString valueSpy; | ||
|
||
class QDBusSignalSpy: public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
public slots: | ||
void slot(const QDBusMessage &msg) | ||
{ | ||
++count; | ||
interface = msg.interface(); | ||
name = msg.member(); | ||
signature = msg.signature(); | ||
path = msg.path(); | ||
value.clear(); | ||
if (msg.arguments().count()) | ||
value = msg.arguments().at(0); | ||
} | ||
|
||
public: | ||
QDBusSignalSpy() : count(0) { } | ||
|
||
int count; | ||
QString interface; | ||
QString name; | ||
QString signature; | ||
QString path; | ||
QVariant value; | ||
}; | ||
|
||
class Interface1: public QDBusAbstractAdaptor | ||
{ | ||
Q_OBJECT | ||
Q_CLASSINFO("D-Bus Interface", "local.Interface1") | ||
public: | ||
Interface1(QObject *parent) : QDBusAbstractAdaptor(parent) | ||
{ } | ||
}; | ||
|
||
class Interface2: public QDBusAbstractAdaptor | ||
{ | ||
Q_OBJECT | ||
Q_CLASSINFO("D-Bus Interface", "local.Interface2") | ||
Q_PROPERTY(QString prop1 READ prop1) | ||
Q_PROPERTY(QString prop2 READ prop2 WRITE setProp2 SCRIPTABLE true) | ||
Q_PROPERTY(QUrl nonDBusProperty READ nonDBusProperty) | ||
public: | ||
Interface2(QObject *parent) : QDBusAbstractAdaptor(parent) | ||
{ setAutoRelaySignals(true); } | ||
|
||
QString prop1() const | ||
{ return QLatin1String("QString Interface2::prop1() const"); } | ||
|
||
QString prop2() const | ||
{ return QLatin1String("QString Interface2::prop2() const"); } | ||
|
||
void setProp2(const QString &value) | ||
{ | ||
slotSpy = "void Interface2::setProp2(const QString &)"; | ||
valueSpy = value; | ||
} | ||
|
||
QUrl nonDBusProperty() const | ||
{ return QUrl(); } | ||
|
||
void emitSignal(const QString &, const QVariant &) | ||
{ emit signal(); } | ||
|
||
public slots: | ||
void method() | ||
{ | ||
slotSpy = "void Interface2::method()"; | ||
} | ||
|
||
Q_SCRIPTABLE void scriptableMethod() | ||
{ | ||
slotSpy = "void Interface2::scriptableMethod()"; | ||
} | ||
|
||
signals: | ||
void signal(); | ||
}; | ||
|
||
class Interface3: public QDBusAbstractAdaptor | ||
{ | ||
Q_OBJECT | ||
Q_CLASSINFO("D-Bus Interface", "local.Interface3") | ||
Q_PROPERTY(QString prop1 READ prop1) | ||
Q_PROPERTY(QString prop2 READ prop2 WRITE setProp2) | ||
Q_PROPERTY(QString interface3prop READ interface3prop) | ||
public: | ||
Interface3(QObject *parent) : QDBusAbstractAdaptor(parent) | ||
{ setAutoRelaySignals(true); } | ||
|
||
QString prop1() const | ||
{ return QLatin1String("QString Interface3::prop1() const"); } | ||
|
||
QString prop2() const | ||
{ return QLatin1String("QString Interface3::prop2() const"); } | ||
|
||
void setProp2(const QString &value) | ||
{ | ||
slotSpy = "void Interface3::setProp2(const QString &)"; | ||
valueSpy = value; | ||
} | ||
|
||
QString interface3prop() const | ||
{ return QLatin1String("QString Interface3::interface3prop() const"); } | ||
|
||
void emitSignal(const QString &name, const QVariant &value) | ||
{ | ||
if (name == "signalVoid") | ||
emit signalVoid(); | ||
else if (name == "signalInt") | ||
emit signalInt(value.toInt()); | ||
else if (name == "signalString") | ||
emit signalString(value.toString()); | ||
} | ||
|
||
public slots: | ||
void methodVoid() { slotSpy = "void Interface3::methodVoid()"; } | ||
void methodInt(int) { slotSpy = "void Interface3::methodInt(int)"; } | ||
void methodString(QString) { slotSpy = "void Interface3::methodString(QString)"; } | ||
|
||
int methodStringString(const QString &s, QString &out) | ||
{ | ||
slotSpy = "int Interface3::methodStringString(const QString &, QString &)"; | ||
out = s; | ||
return 42; | ||
} | ||
|
||
signals: | ||
void signalVoid(); | ||
void signalInt(int); | ||
void signalString(const QString &); | ||
}; | ||
|
||
class Interface4: public QDBusAbstractAdaptor | ||
{ | ||
Q_OBJECT | ||
Q_CLASSINFO("D-Bus Interface", "local.Interface4") | ||
Q_PROPERTY(QString prop1 READ prop1) | ||
Q_PROPERTY(QString prop2 READ prop2 WRITE setProp2) | ||
Q_PROPERTY(QString interface4prop READ interface4prop) | ||
public: | ||
Interface4(QObject *parent) : QDBusAbstractAdaptor(parent) | ||
{ setAutoRelaySignals(true); } | ||
|
||
QString prop1() const | ||
{ return QLatin1String("QString Interface4::prop1() const"); } | ||
|
||
QString prop2() const | ||
{ return QLatin1String("QString Interface4::prop2() const"); } | ||
|
||
QString interface4prop() const | ||
{ return QLatin1String("QString Interface4::interface4prop() const"); } | ||
|
||
void setProp2(const QString &value) | ||
{ | ||
slotSpy = "void Interface4::setProp2(const QString &)"; | ||
valueSpy = value; | ||
} | ||
|
||
void emitSignal(const QString &, const QVariant &value) | ||
{ | ||
switch (value.type()) | ||
{ | ||
case QVariant::Invalid: | ||
emit signal(); | ||
break; | ||
case QVariant::Int: | ||
emit signal(value.toInt()); | ||
break; | ||
case QVariant::String: | ||
emit signal(value.toString()); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
public slots: | ||
void method() { slotSpy = "void Interface4::method()"; } | ||
void method(int) { slotSpy = "void Interface4::method(int)"; } | ||
void method(QString) { slotSpy = "void Interface4::method(QString)"; } | ||
|
||
signals: | ||
void signal(); | ||
void signal(int); | ||
void signal(const QString &); | ||
}; | ||
|
||
class MyObject: public QObject | ||
{ | ||
Q_OBJECT | ||
Q_CLASSINFO("D-Bus Interface", "local.MyObject") | ||
public: | ||
Interface1 *if1; | ||
Interface2 *if2; | ||
Interface3 *if3; | ||
Interface4 *if4; | ||
|
||
MyObject(int n = 4) | ||
: if1(0), if2(0), if3(0), if4(0) | ||
{ | ||
switch (n) | ||
{ | ||
case 4: | ||
if4 = new Interface4(this); | ||
case 3: | ||
if3 = new Interface3(this); | ||
case 2: | ||
if2 = new Interface2(this); | ||
case 1: | ||
if1 = new Interface1(this); | ||
} | ||
} | ||
|
||
void emitSignal(const QString &name, const QVariant &value) | ||
{ | ||
if (name == "scriptableSignalVoid") | ||
emit scriptableSignalVoid(); | ||
else if (name == "scriptableSignalInt") | ||
emit scriptableSignalInt(value.toInt()); | ||
else if (name == "scriptableSignalString") | ||
emit scriptableSignalString(value.toString()); | ||
else if (name == "nonScriptableSignalVoid") | ||
emit nonScriptableSignalVoid(); | ||
} | ||
|
||
signals: | ||
Q_SCRIPTABLE void scriptableSignalVoid(); | ||
Q_SCRIPTABLE void scriptableSignalInt(int); | ||
Q_SCRIPTABLE void scriptableSignalString(QString); | ||
void nonScriptableSignalVoid(); | ||
}; | ||
|
||
#endif // MYOBJECT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
load(qttest_p4) | ||
QT = core | ||
contains(QT_CONFIG,dbus): { | ||
SOURCES += tst_qdbusabstractadaptor.cpp | ||
QT += dbus | ||
TEMPLATE = subdirs | ||
CONFIG += ordered | ||
SUBDIRS = qmyserver test | ||
} else { | ||
SOURCES += ../qdbusmarshall/dummy.cpp | ||
SOURCES += ../qdbusmarshall/dummy.cpp | ||
} | ||
|
||
|
167 changes: 167 additions & 0 deletions
167
tests/auto/qdbusabstractadaptor/qmyserver/qmyserver.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
/**************************************************************************** | ||
** | ||
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). | ||
** All rights reserved. | ||
** Contact: Nokia Corporation (qt-info@nokia.com) | ||
** | ||
** This file is part of the test suite of the Qt Toolkit. | ||
** | ||
** $QT_BEGIN_LICENSE:LGPL$ | ||
** No Commercial Usage | ||
** This file contains pre-release code and may not be distributed. | ||
** You may use this file in accordance with the terms and conditions | ||
** contained in the Technology Preview License Agreement accompanying | ||
** this package. | ||
** | ||
** GNU Lesser General Public License Usage | ||
** Alternatively, this file may be used under the terms of the GNU Lesser | ||
** General Public License version 2.1 as published by the Free Software | ||
** Foundation and appearing in the file LICENSE.LGPL included in the | ||
** packaging of this file. Please review the following information to | ||
** ensure the GNU Lesser General Public License version 2.1 requirements | ||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
** | ||
** In addition, as a special exception, Nokia gives you certain additional | ||
** rights. These rights are described in the Nokia Qt LGPL Exception | ||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
** | ||
** If you have questions regarding the use of this file, please contact | ||
** Nokia at qt-info@nokia.com. | ||
** | ||
** | ||
** | ||
** | ||
** | ||
** | ||
** | ||
** | ||
** $QT_END_LICENSE$ | ||
** | ||
****************************************************************************/ | ||
#include <QtCore/QtCore> | ||
#include <QtDBus/QtDBus> | ||
|
||
#include "../myobject.h" | ||
|
||
static const char serviceName[] = "com.trolltech.autotests.qmyserver"; | ||
static const char objectPath[] = "/com/trolltech/qmyserver"; | ||
//static const char *interfaceName = serviceName; | ||
|
||
const char *slotSpy; | ||
QString valueSpy; | ||
|
||
Q_DECLARE_METATYPE(QDBusConnection::RegisterOptions) | ||
|
||
class MyServer : public QDBusServer | ||
{ | ||
Q_OBJECT | ||
Q_CLASSINFO("D-Bus Interface", "com.trolltech.autotests.qmyserver") | ||
|
||
public: | ||
MyServer(QString addr = "unix:tmpdir=/tmp", QObject* parent = 0) | ||
: QDBusServer(addr, parent), | ||
m_conn("none"), | ||
obj(NULL) | ||
{ | ||
connect(this, SIGNAL(newConnection(const QDBusConnection&)), SLOT(handleConnection(const QDBusConnection&))); | ||
} | ||
|
||
~MyServer() | ||
{ | ||
if (obj) | ||
obj->deleteLater(); | ||
} | ||
|
||
public slots: | ||
QString address() const | ||
{ | ||
return QDBusServer::address(); | ||
} | ||
|
||
bool isConnected() const | ||
{ | ||
return m_conn.isConnected(); | ||
} | ||
|
||
void emitSignal(const QString& interface, const QString& name, const QDBusVariant& parameter) | ||
{ | ||
if (interface.endsWith('2')) | ||
obj->if2->emitSignal(name, parameter.variant()); | ||
else if (interface.endsWith('3')) | ||
obj->if3->emitSignal(name, parameter.variant()); | ||
else if (interface.endsWith('4')) | ||
obj->if4->emitSignal(name, parameter.variant()); | ||
else | ||
obj->emitSignal(name, parameter.variant()); | ||
} | ||
|
||
void emitSignal2(const QString& interface, const QString& name) | ||
{ | ||
if (interface.endsWith('2')) | ||
obj->if2->emitSignal(name, QVariant()); | ||
else if (interface.endsWith('3')) | ||
obj->if3->emitSignal(name, QVariant()); | ||
else if (interface.endsWith('4')) | ||
obj->if4->emitSignal(name, QVariant()); | ||
else | ||
obj->emitSignal(name, QVariant()); | ||
} | ||
|
||
void newMyObject(int nInterfaces = 4) | ||
{ | ||
if (obj) | ||
obj->deleteLater(); | ||
obj = new MyObject(nInterfaces); | ||
} | ||
|
||
void registerMyObject(const QString & path, int options) | ||
{ | ||
m_conn.registerObject(path, obj, (QDBusConnection::RegisterOptions)options); | ||
} | ||
|
||
QString slotSpyServer() | ||
{ | ||
return QLatin1String(slotSpy); | ||
} | ||
|
||
QString valueSpyServer() | ||
{ | ||
return valueSpy; | ||
} | ||
|
||
void clearValueSpy() | ||
{ | ||
valueSpy.clear(); | ||
} | ||
|
||
private slots: | ||
void handleConnection(const QDBusConnection& con) | ||
{ | ||
m_conn = con; | ||
} | ||
|
||
private: | ||
QDBusConnection m_conn; | ||
MyObject* obj; | ||
}; | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QCoreApplication app(argc, argv); | ||
|
||
QDBusConnection con = QDBusConnection::sessionBus(); | ||
if (!con.isConnected()) | ||
exit(1); | ||
|
||
if (!con.registerService(serviceName)) | ||
exit(2); | ||
|
||
MyServer server; | ||
con.registerObject(objectPath, &server, QDBusConnection::ExportAllSlots); | ||
|
||
printf("ready.\n"); | ||
|
||
return app.exec(); | ||
} | ||
|
||
#include "qmyserver.moc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
SOURCES = qmyserver.cpp | ||
HEADERS = ../myobject.h | ||
TARGET = qmyserver | ||
QT += dbus | ||
QT -= gui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
load(qttest_p4) | ||
SOURCES += ../tst_qdbusabstractadaptor.cpp | ||
HEADERS += ../myobject.h | ||
TARGET = ../tst_qdbusabstractadaptor | ||
|
||
QT = core | ||
QT += dbus |
1,091 changes: 771 additions & 320 deletions
1,091
tests/auto/qdbusabstractadaptor/tst_qdbusabstractadaptor.cpp
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 6 additions & 11 deletions
17
tests/auto/qdbusabstractinterface/qdbusabstractinterface.pro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,10 @@ | ||
load(qttest_p4) | ||
QT = core | ||
contains(QT_CONFIG,dbus): { | ||
SOURCES += tst_qdbusabstractinterface.cpp interface.cpp | ||
HEADERS += interface.h | ||
QT += dbus | ||
|
||
# These are generated sources | ||
# To regenerate, see the command-line at the top of the files | ||
SOURCES += pinger.cpp | ||
HEADERS += pinger.h | ||
contains(QT_CONFIG,dbus): { | ||
TEMPLATE = subdirs | ||
CONFIG += ordered | ||
SUBDIRS = qpinger test | ||
} else { | ||
SOURCES += ../qdbusmarshall/dummy.cpp | ||
} | ||
else:SOURCES += ../qdbusmarshall/dummy.cpp | ||
|
||
OTHER_FILES += com.trolltech.QtDBus.Pinger.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/**************************************************************************** | ||
** | ||
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). | ||
** All rights reserved. | ||
** Contact: Nokia Corporation (qt-info@nokia.com) | ||
** | ||
** This file is part of the test suite of the Qt Toolkit. | ||
** | ||
** $QT_BEGIN_LICENSE:LGPL$ | ||
** No Commercial Usage | ||
** This file contains pre-release code and may not be distributed. | ||
** You may use this file in accordance with the terms and conditions | ||
** contained in the Technology Preview License Agreement accompanying | ||
** this package. | ||
** | ||
** GNU Lesser General Public License Usage | ||
** Alternatively, this file may be used under the terms of the GNU Lesser | ||
** General Public License version 2.1 as published by the Free Software | ||
** Foundation and appearing in the file LICENSE.LGPL included in the | ||
** packaging of this file. Please review the following information to | ||
** ensure the GNU Lesser General Public License version 2.1 requirements | ||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
** | ||
** In addition, as a special exception, Nokia gives you certain additional | ||
** rights. These rights are described in the Nokia Qt LGPL Exception | ||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
** | ||
** If you have questions regarding the use of this file, please contact | ||
** Nokia at qt-info@nokia.com. | ||
** | ||
** | ||
** | ||
** | ||
** | ||
** | ||
** | ||
** | ||
** $QT_END_LICENSE$ | ||
** | ||
****************************************************************************/ | ||
#include <QtCore/QtCore> | ||
#include <QtDBus/QtDBus> | ||
#include "../interface.h" | ||
|
||
static const char serviceName[] = "com.trolltech.autotests.qpinger"; | ||
static const char objectPath[] = "/com/trolltech/qpinger"; | ||
//static const char *interfaceName = serviceName; | ||
|
||
class PingerServer : public QDBusServer | ||
{ | ||
Q_OBJECT | ||
Q_CLASSINFO("D-Bus Interface", "com.trolltech.autotests.qpinger") | ||
public: | ||
PingerServer(QString addr = "unix:tmpdir=/tmp", QObject* parent = 0) | ||
: QDBusServer(addr, parent), | ||
m_conn("none") | ||
{ | ||
connect(this, SIGNAL(newConnection(const QDBusConnection&)), SLOT(handleConnection(const QDBusConnection&))); | ||
reset(); | ||
} | ||
|
||
public slots: | ||
QString address() const | ||
{ | ||
return QDBusServer::address(); | ||
} | ||
|
||
bool isConnected() const | ||
{ | ||
return m_conn.isConnected(); | ||
} | ||
|
||
void reset() | ||
{ | ||
targetObj.m_stringProp = "This is a test"; | ||
targetObj.m_variantProp = QDBusVariant(QVariant(42)); | ||
targetObj.m_complexProp = RegisteredType("This is a test"); | ||
} | ||
|
||
void voidSignal() | ||
{ | ||
emit targetObj.voidSignal(); | ||
} | ||
|
||
void stringSignal(const QString& value) | ||
{ | ||
emit targetObj.stringSignal(value); | ||
} | ||
|
||
void complexSignal(const QString& value) | ||
{ | ||
RegisteredType reg(value); | ||
emit targetObj.complexSignal(reg); | ||
} | ||
|
||
private slots: | ||
void handleConnection(const QDBusConnection& con) | ||
{ | ||
m_conn = con; | ||
m_conn.registerObject("/", &targetObj, QDBusConnection::ExportScriptableContents); | ||
} | ||
|
||
private: | ||
Interface targetObj; | ||
QDBusConnection m_conn; | ||
}; | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QCoreApplication app(argc, argv); | ||
|
||
// register the meta types | ||
qDBusRegisterMetaType<RegisteredType>(); | ||
qRegisterMetaType<UnregisteredType>(); | ||
|
||
QDBusConnection con = QDBusConnection::sessionBus(); | ||
if (!con.isConnected()) | ||
exit(1); | ||
|
||
if (!con.registerService(serviceName)) | ||
exit(2); | ||
|
||
PingerServer server; | ||
con.registerObject(objectPath, &server, QDBusConnection::ExportAllSlots); | ||
|
||
printf("ready.\n"); | ||
|
||
return app.exec(); | ||
} | ||
|
||
#include "qpinger.moc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
SOURCES = qpinger.cpp ../interface.cpp | ||
HEADERS = ../interface.h | ||
TARGET = qpinger | ||
QT += dbus | ||
QT -= gui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
load(qttest_p4) | ||
SOURCES += ../tst_qdbusabstractinterface.cpp ../interface.cpp | ||
HEADERS += ../interface.h | ||
|
||
# These are generated sources | ||
# To regenerate, see the command-line at the top of the files | ||
SOURCES += ../pinger.cpp | ||
HEADERS += ../pinger.h | ||
|
||
TARGET = ../tst_qdbusabstractinterface | ||
|
||
QT = core | ||
QT += dbus |
573 changes: 573 additions & 0 deletions
573
tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
/**************************************************************************** | ||
** | ||
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). | ||
** All rights reserved. | ||
** Contact: Nokia Corporation (qt-info@nokia.com) | ||
** | ||
** This file is part of the test suite of the Qt Toolkit. | ||
** | ||
** $QT_BEGIN_LICENSE:LGPL$ | ||
** No Commercial Usage | ||
** This file contains pre-release code and may not be distributed. | ||
** You may use this file in accordance with the terms and conditions | ||
** contained in the Technology Preview License Agreement accompanying | ||
** this package. | ||
** | ||
** GNU Lesser General Public License Usage | ||
** Alternatively, this file may be used under the terms of the GNU Lesser | ||
** General Public License version 2.1 as published by the Free Software | ||
** Foundation and appearing in the file LICENSE.LGPL included in the | ||
** packaging of this file. Please review the following information to | ||
** ensure the GNU Lesser General Public License version 2.1 requirements | ||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
** | ||
** In addition, as a special exception, Nokia gives you certain additional | ||
** rights. These rights are described in the Nokia Qt LGPL Exception | ||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
** | ||
** If you have questions regarding the use of this file, please contact | ||
** Nokia at qt-info@nokia.com. | ||
** | ||
** | ||
** | ||
** | ||
** | ||
** | ||
** | ||
** | ||
** $QT_END_LICENSE$ | ||
** | ||
****************************************************************************/ | ||
|
||
#ifndef MYOBJECT_H | ||
#define MYOBJECT_H | ||
|
||
#include <QtCore/QObject> | ||
#include <QtDBus/QtDBus> | ||
|
||
Q_DECLARE_METATYPE(QVariantList) | ||
|
||
class MyObject: public QObject | ||
{ | ||
Q_OBJECT | ||
Q_CLASSINFO("D-Bus Interface", "com.trolltech.QtDBus.MyObject") | ||
Q_CLASSINFO("D-Bus Introspection", "" | ||
" <interface name=\"com.trolltech.QtDBus.MyObject\" >\n" | ||
" <property access=\"readwrite\" type=\"i\" name=\"prop1\" />\n" | ||
" <property name=\"complexProp\" type=\"ai\" access=\"readwrite\">\n" | ||
" <annotation name=\"com.trolltech.QtDBus.QtTypeName\" value=\"QList<int>\"/>\n" | ||
" </property>\n" | ||
" <signal name=\"somethingHappened\" >\n" | ||
" <arg direction=\"out\" type=\"s\" />\n" | ||
" </signal>\n" | ||
" <method name=\"ping\" >\n" | ||
" <arg direction=\"in\" type=\"v\" name=\"ping\" />\n" | ||
" <arg direction=\"out\" type=\"v\" name=\"ping\" />\n" | ||
" </method>\n" | ||
" <method name=\"ping_invokable\" >\n" | ||
" <arg direction=\"in\" type=\"v\" name=\"ping_invokable\" />\n" | ||
" <arg direction=\"out\" type=\"v\" name=\"ping_invokable\" />\n" | ||
" </method>\n" | ||
" <method name=\"ping\" >\n" | ||
" <arg direction=\"in\" type=\"v\" name=\"ping1\" />\n" | ||
" <arg direction=\"in\" type=\"v\" name=\"ping2\" />\n" | ||
" <arg direction=\"out\" type=\"v\" name=\"pong1\" />\n" | ||
" <arg direction=\"out\" type=\"v\" name=\"pong2\" />\n" | ||
" </method>\n" | ||
" <method name=\"ping_invokable\" >\n" | ||
" <arg direction=\"in\" type=\"v\" name=\"ping1_invokable\" />\n" | ||
" <arg direction=\"in\" type=\"v\" name=\"ping2_invokable\" />\n" | ||
" <arg direction=\"out\" type=\"v\" name=\"pong1_invokable\" />\n" | ||
" <arg direction=\"out\" type=\"v\" name=\"pong2_invokable\" />\n" | ||
" </method>\n" | ||
" <method name=\"ping\" >\n" | ||
" <arg direction=\"in\" type=\"ai\" name=\"ping\" />\n" | ||
" <arg direction=\"out\" type=\"ai\" name=\"ping\" />\n" | ||
" <annotation name=\"com.trolltech.QtDBus.QtTypeName.In0\" value=\"QList<int>\"/>\n" | ||
" <annotation name=\"com.trolltech.QtDBus.QtTypeName.Out0\" value=\"QList<int>\"/>\n" | ||
" </method>\n" | ||
" <method name=\"ping_invokable\" >\n" | ||
" <arg direction=\"in\" type=\"ai\" name=\"ping_invokable\" />\n" | ||
" <arg direction=\"out\" type=\"ai\" name=\"ping_invokable\" />\n" | ||
" <annotation name=\"com.trolltech.QtDBus.QtTypeName.In0\" value=\"QList<int>\"/>\n" | ||
" <annotation name=\"com.trolltech.QtDBus.QtTypeName.Out0\" value=\"QList<int>\"/>\n" | ||
" </method>\n" | ||
" </interface>\n" | ||
"") | ||
Q_PROPERTY(int prop1 READ prop1 WRITE setProp1) | ||
Q_PROPERTY(QList<int> complexProp READ complexProp WRITE setComplexProp) | ||
|
||
public: | ||
static int callCount; | ||
static QVariantList callArgs; | ||
MyObject() | ||
{ | ||
QObject *subObject = new QObject(this); | ||
subObject->setObjectName("subObject"); | ||
} | ||
|
||
int m_prop1; | ||
int prop1() const | ||
{ | ||
++callCount; | ||
return m_prop1; | ||
} | ||
void setProp1(int value) | ||
{ | ||
++callCount; | ||
m_prop1 = value; | ||
} | ||
|
||
QList<int> m_complexProp; | ||
QList<int> complexProp() const | ||
{ | ||
++callCount; | ||
return m_complexProp; | ||
} | ||
void setComplexProp(const QList<int> &value) | ||
{ | ||
++callCount; | ||
m_complexProp = value; | ||
} | ||
|
||
Q_INVOKABLE void ping_invokable(QDBusMessage msg) | ||
{ | ||
QDBusConnection sender = QDBusConnection::sender(); | ||
if (!sender.isConnected()) | ||
exit(1); | ||
|
||
++callCount; | ||
callArgs = msg.arguments(); | ||
|
||
msg.setDelayedReply(true); | ||
if (!sender.send(msg.createReply(callArgs))) | ||
exit(1); | ||
} | ||
|
||
public slots: | ||
|
||
void ping(QDBusMessage msg) | ||
{ | ||
QDBusConnection sender = QDBusConnection::sender(); | ||
if (!sender.isConnected()) | ||
exit(1); | ||
|
||
++callCount; | ||
callArgs = msg.arguments(); | ||
|
||
msg.setDelayedReply(true); | ||
if (!sender.send(msg.createReply(callArgs))) | ||
exit(1); | ||
} | ||
}; | ||
|
||
#endif // INTERFACE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
load(qttest_p4) | ||
QT = core | ||
contains(QT_CONFIG,dbus): { | ||
SOURCES += tst_qdbusinterface.cpp | ||
QT += dbus | ||
TEMPLATE = subdirs | ||
CONFIG += ordered | ||
SUBDIRS = qmyserver test | ||
} else { | ||
SOURCES += ../qdbusmarshall/dummy.cpp | ||
SOURCES += ../qdbusmarshall/dummy.cpp | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
/**************************************************************************** | ||
** | ||
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). | ||
** All rights reserved. | ||
** Contact: Nokia Corporation (qt-info@nokia.com) | ||
** | ||
** This file is part of the test suite of the Qt Toolkit. | ||
** | ||
** $QT_BEGIN_LICENSE:LGPL$ | ||
** No Commercial Usage | ||
** This file contains pre-release code and may not be distributed. | ||
** You may use this file in accordance with the terms and conditions | ||
** contained in the Technology Preview License Agreement accompanying | ||
** this package. | ||
** | ||
** GNU Lesser General Public License Usage | ||
** Alternatively, this file may be used under the terms of the GNU Lesser | ||
** General Public License version 2.1 as published by the Free Software | ||
** Foundation and appearing in the file LICENSE.LGPL included in the | ||
** packaging of this file. Please review the following information to | ||
** ensure the GNU Lesser General Public License version 2.1 requirements | ||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
** | ||
** In addition, as a special exception, Nokia gives you certain additional | ||
** rights. These rights are described in the Nokia Qt LGPL Exception | ||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
** | ||
** If you have questions regarding the use of this file, please contact | ||
** Nokia at qt-info@nokia.com. | ||
** | ||
** | ||
** | ||
** | ||
** | ||
** | ||
** | ||
** | ||
** $QT_END_LICENSE$ | ||
** | ||
****************************************************************************/ | ||
#include <QtCore/QtCore> | ||
#include <QtDBus/QtDBus> | ||
|
||
#include "../myobject.h" | ||
|
||
static const char serviceName[] = "com.trolltech.autotests.qmyserver"; | ||
static const char objectPath[] = "/com/trolltech/qmyserver"; | ||
//static const char *interfaceName = serviceName; | ||
|
||
int MyObject::callCount = 0; | ||
QVariantList MyObject::callArgs; | ||
|
||
class MyServer : public QDBusServer | ||
{ | ||
Q_OBJECT | ||
Q_CLASSINFO("D-Bus Interface", "com.trolltech.autotests.qmyserver") | ||
|
||
public: | ||
MyServer(QString addr = "unix:tmpdir=/tmp", QObject* parent = 0) | ||
: QDBusServer(addr, parent), | ||
m_conn("none") | ||
{ | ||
connect(this, SIGNAL(newConnection(const QDBusConnection&)), SLOT(handleConnection(const QDBusConnection&))); | ||
} | ||
|
||
public slots: | ||
QString address() const | ||
{ | ||
return QDBusServer::address(); | ||
} | ||
|
||
bool isConnected() const | ||
{ | ||
return m_conn.isConnected(); | ||
} | ||
|
||
void emitSignal(const QString &interface, const QString &name, const QString &arg) | ||
{ | ||
QDBusMessage msg = QDBusMessage::createSignal("/", interface, name); | ||
msg << arg; | ||
m_conn.send(msg); | ||
} | ||
|
||
void reset() | ||
{ | ||
MyObject::callCount = 0; | ||
obj.m_complexProp.clear(); | ||
} | ||
|
||
int callCount() | ||
{ | ||
return MyObject::callCount; | ||
} | ||
|
||
QVariantList callArgs() | ||
{ | ||
qDebug() << "callArgs" << MyObject::callArgs.count(); | ||
return MyObject::callArgs; | ||
} | ||
|
||
void setProp1(int val) | ||
{ | ||
obj.m_prop1 = val; | ||
} | ||
|
||
int prop1() | ||
{ | ||
return obj.m_prop1; | ||
} | ||
|
||
void setComplexProp(QList<int> val) | ||
{ | ||
obj.m_complexProp = val; | ||
} | ||
|
||
QList<int> complexProp() | ||
{ | ||
return obj.m_complexProp; | ||
} | ||
|
||
|
||
private slots: | ||
void handleConnection(const QDBusConnection& con) | ||
{ | ||
m_conn = con; | ||
m_conn.registerObject("/", &obj, QDBusConnection::ExportAllProperties | ||
| QDBusConnection::ExportAllSlots | ||
| QDBusConnection::ExportAllInvokables); | ||
} | ||
|
||
private: | ||
QDBusConnection m_conn; | ||
MyObject obj; | ||
}; | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QCoreApplication app(argc, argv); | ||
|
||
QDBusConnection con = QDBusConnection::sessionBus(); | ||
if (!con.isConnected()) | ||
exit(1); | ||
|
||
if (!con.registerService(serviceName)) | ||
exit(2); | ||
|
||
MyServer server; | ||
con.registerObject(objectPath, &server, QDBusConnection::ExportAllSlots); | ||
|
||
printf("ready.\n"); | ||
|
||
return app.exec(); | ||
} | ||
|
||
#include "qmyserver.moc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
SOURCES = qmyserver.cpp | ||
HEADERS = ../myobject.h | ||
TARGET = qmyserver | ||
QT += dbus | ||
QT -= gui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
load(qttest_p4) | ||
SOURCES += ../tst_qdbusinterface.cpp | ||
HEADERS += ../myobject.h | ||
TARGET = ../tst_qdbusinterface | ||
|
||
QT = core | ||
QT += dbus |
Large diffs are not rendered by default.
Oops, something went wrong.