summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2009-07-02 10:49:55 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2009-07-02 10:49:55 (GMT)
commite76a5a08e4e46a49a28e6aa338c4a27acc715dc2 (patch)
treed2543adfeaf56663ace84bf59bc22211dac687d8 /tests
parent9a90dab23bd1bd37bd4a7aace588896d2ae7e9d9 (diff)
parent200286b8e83918e785b61e4695443a3b77ebeaea (diff)
downloadQt-e76a5a08e4e46a49a28e6aa338c4a27acc715dc2.zip
Qt-e76a5a08e4e46a49a28e6aa338c4a27acc715dc2.tar.gz
Qt-e76a5a08e4e46a49a28e6aa338c4a27acc715dc2.tar.bz2
Merge branch 'research/qdbus-improvements'
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/auto.pro1
-rw-r--r--tests/auto/qdbusabstractadaptor/tst_qdbusabstractadaptor.cpp21
-rw-r--r--tests/auto/qdbusabstractinterface/com.trolltech.QtDBus.Pinger.xml30
-rw-r--r--tests/auto/qdbusabstractinterface/interface.cpp48
-rw-r--r--tests/auto/qdbusabstractinterface/interface.h113
-rw-r--r--tests/auto/qdbusabstractinterface/pinger.cpp67
-rw-r--r--tests/auto/qdbusabstractinterface/pinger.h145
-rw-r--r--tests/auto/qdbusabstractinterface/qdbusabstractinterface.pro15
-rw-r--r--tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp576
-rw-r--r--tests/auto/qdbusinterface/tst_qdbusinterface.cpp194
-rw-r--r--tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp121
11 files changed, 1315 insertions, 16 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 5e4764d..9924904 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -435,6 +435,7 @@ xmlpatternsxslts.depends = xmlpatternsxqts
unix:!embedded:contains(QT_CONFIG, dbus):SUBDIRS += \
qdbusabstractadaptor \
+ qdbusabstractinterface \
qdbusconnection \
qdbusinterface \
qdbuslocalcalls \
diff --git a/tests/auto/qdbusabstractadaptor/tst_qdbusabstractadaptor.cpp b/tests/auto/qdbusabstractadaptor/tst_qdbusabstractadaptor.cpp
index c70c619..5d08c63 100644
--- a/tests/auto/qdbusabstractadaptor/tst_qdbusabstractadaptor.cpp
+++ b/tests/auto/qdbusabstractadaptor/tst_qdbusabstractadaptor.cpp
@@ -609,19 +609,22 @@ void tst_QDBusAbstractAdaptor::methodCalls()
QVERIFY(con.isConnected());
//QDBusInterface emptycon.baseService(), "/", QString());
- QDBusInterface if1(con.baseService(), "/", "local.Interface1", con);
- QDBusInterface if2(con.baseService(), "/", "local.Interface2", con);
- QDBusInterface if3(con.baseService(), "/", "local.Interface3", con);
- QDBusInterface if4(con.baseService(), "/", "local.Interface4", con);
- // must fail: no object
- //QCOMPARE(empty->call("method").type(), QDBusMessage::ErrorMessage);
- QCOMPARE(if1.call(QDBus::BlockWithGui, "method").type(), QDBusMessage::ErrorMessage);
+ {
+ // must fail: no object
+ QDBusInterface if1(con.baseService(), "/", "local.Interface1", con);
+ QCOMPARE(if1.call(QDBus::BlockWithGui, "method").type(), QDBusMessage::ErrorMessage);
+ }
QFETCH(int, nInterfaces);
MyObject obj(nInterfaces);
con.registerObject("/", &obj);
+ QDBusInterface if1(con.baseService(), "/", "local.Interface1", con);
+ QDBusInterface if2(con.baseService(), "/", "local.Interface2", con);
+ QDBusInterface if3(con.baseService(), "/", "local.Interface3", con);
+ QDBusInterface if4(con.baseService(), "/", "local.Interface4", con);
+
// must fail: no such method
QCOMPARE(if1.call(QDBus::BlockWithGui, "method").type(), QDBusMessage::ErrorMessage);
if (!nInterfaces--)
@@ -670,11 +673,11 @@ void tst_QDBusAbstractAdaptor::methodCallScriptable()
QDBusConnection con = QDBusConnection::sessionBus();
QVERIFY(con.isConnected());
- QDBusInterface if2(con.baseService(), "/", "local.Interface2", con);
-
MyObject obj(2);
con.registerObject("/", &obj);
+ QDBusInterface if2(con.baseService(), "/", "local.Interface2", con);
+
QCOMPARE(if2.call(QDBus::BlockWithGui,"scriptableMethod").type(), QDBusMessage::ReplyMessage);
QCOMPARE(slotSpy, "void Interface2::scriptableMethod()");
}
diff --git a/tests/auto/qdbusabstractinterface/com.trolltech.QtDBus.Pinger.xml b/tests/auto/qdbusabstractinterface/com.trolltech.QtDBus.Pinger.xml
new file mode 100644
index 0000000..fb2aab8
--- /dev/null
+++ b/tests/auto/qdbusabstractinterface/com.trolltech.QtDBus.Pinger.xml
@@ -0,0 +1,30 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node>
+ <interface name="com.trolltech.QtDBus.Pinger">
+ <property name="stringProp" type="s" access="readwrite"/>
+ <property name="variantProp" type="v" access="readwrite"/>
+ <property name="complexProp" type="(s)" access="readwrite">
+ <annotation name="com.trolltech.QtDBus.QtTypeName" value="RegisteredType"/>
+ </property>
+ <signal name="voidSignal"/>
+ <signal name="stringSignal">
+ <arg type="s"/>
+ </signal>
+ <signal name="complexSignal">
+ <arg name="" type="(s)"/>
+ <annotation name="com.trolltech.QtDBus.QtTypeName.In0" value="RegisteredType"/>
+ </signal>
+ <method name="voidMethod" />
+ <method name="stringMethod">
+ <arg type="s" direction="out"/>
+ </method>
+ <method name="complexMethod">
+ <arg type="(s)" direction="out"/>
+ <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="RegisteredType"/>
+ </method>
+ <method name="multiOutMethod">
+ <arg type="s" direction="out"/>
+ <arg type="i" direction="out"/
+ </method>
+ </interface>
+</node>
diff --git a/tests/auto/qdbusabstractinterface/interface.cpp b/tests/auto/qdbusabstractinterface/interface.cpp
new file mode 100644
index 0000000..1c391ce
--- /dev/null
+++ b/tests/auto/qdbusabstractinterface/interface.cpp
@@ -0,0 +1,48 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** 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 either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** 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.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "interface.h"
+
+Interface::Interface()
+{
+}
+
+#include "moc_interface.cpp"
diff --git a/tests/auto/qdbusabstractinterface/interface.h b/tests/auto/qdbusabstractinterface/interface.h
new file mode 100644
index 0000000..f6d34a7
--- /dev/null
+++ b/tests/auto/qdbusabstractinterface/interface.h
@@ -0,0 +1,113 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** 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 either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** 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.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef INTERFACE_H
+#define INTERFACE_H
+
+#include <QtCore/QObject>
+#include <QtDBus/QDBusArgument>
+
+struct RegisteredType
+{
+ inline RegisteredType(const QString &str = QString()) : s(str) {}
+ inline bool operator==(const RegisteredType &other) const { return s == other.s; }
+ QString s;
+};
+Q_DECLARE_METATYPE(RegisteredType)
+
+inline QDBusArgument &operator<<(QDBusArgument &s, const RegisteredType &data)
+{
+ s.beginStructure();
+ s << data.s;
+ s.endStructure();
+ return s;
+}
+
+inline const QDBusArgument &operator>>(const QDBusArgument &s, RegisteredType &data)
+{
+ s.beginStructure();
+ s >> data.s;
+ s.endStructure();
+ return s;
+}
+
+struct UnregisteredType
+{
+ QString s;
+};
+Q_DECLARE_METATYPE(UnregisteredType)
+
+class Interface: public QObject
+{
+ Q_OBJECT
+ Q_CLASSINFO("D-Bus Interface", "com.trolltech.QtDBus.Pinger")
+ Q_PROPERTY(QString stringProp READ stringProp WRITE setStringProp SCRIPTABLE true)
+ Q_PROPERTY(QDBusVariant variantProp READ variantProp WRITE setVariantProp SCRIPTABLE true)
+ Q_PROPERTY(RegisteredType complexProp READ complexProp WRITE setComplexProp SCRIPTABLE true)
+
+ friend class tst_QDBusAbstractInterface;
+ QString m_stringProp;
+ QDBusVariant m_variantProp;
+ RegisteredType m_complexProp;
+
+public:
+ Interface();
+
+ QString stringProp() const { return m_stringProp; }
+ void setStringProp(const QString &s) { m_stringProp = s; }
+ QDBusVariant variantProp() const { return m_variantProp; }
+ void setVariantProp(const QDBusVariant &v) { m_variantProp = v; }
+ RegisteredType complexProp() const { return m_complexProp; }
+ void setComplexProp(const RegisteredType &r) { m_complexProp = r; }
+
+public slots:
+ Q_SCRIPTABLE void voidMethod() {}
+ Q_SCRIPTABLE QString stringMethod() { return "Hello, world"; }
+ Q_SCRIPTABLE RegisteredType complexMethod() { return RegisteredType("Hello, world"); }
+ Q_SCRIPTABLE QString multiOutMethod(int &value) { value = 42; return "Hello, world"; }
+
+signals:
+ Q_SCRIPTABLE void voidSignal();
+ Q_SCRIPTABLE void stringSignal(const QString &);
+ Q_SCRIPTABLE void complexSignal(RegisteredType);
+};
+
+#endif // INTERFACE_H
diff --git a/tests/auto/qdbusabstractinterface/pinger.cpp b/tests/auto/qdbusabstractinterface/pinger.cpp
new file mode 100644
index 0000000..4fcb89a
--- /dev/null
+++ b/tests/auto/qdbusabstractinterface/pinger.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** 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 either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** 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.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ * This file was generated by qdbusxml2cpp version 0.7
+ * Command line was: qdbusxml2cpp -i interface.h -p pinger com.trolltech.QtDBus.Pinger.xml
+ *
+ * qdbusxml2cpp is Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+ *
+ * This is an auto-generated file.
+ * This file may have been hand-edited. Look for HAND-EDIT comments
+ * before re-generating it.
+ */
+
+#include "pinger.h"
+
+/*
+ * Implementation of interface class ComTrolltechQtDBusPingerInterface
+ */
+
+ComTrolltechQtDBusPingerInterface::ComTrolltechQtDBusPingerInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
+ : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
+{
+}
+
+ComTrolltechQtDBusPingerInterface::~ComTrolltechQtDBusPingerInterface()
+{
+}
+
diff --git a/tests/auto/qdbusabstractinterface/pinger.h b/tests/auto/qdbusabstractinterface/pinger.h
new file mode 100644
index 0000000..fb8adda
--- /dev/null
+++ b/tests/auto/qdbusabstractinterface/pinger.h
@@ -0,0 +1,145 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** 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 either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** 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.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*
+ * This file was generated by qdbusxml2cpp version 0.7
+ * Command line was: qdbusxml2cpp -i interface.h -p pinger com.trolltech.QtDBus.Pinger.xml
+ *
+ * qdbusxml2cpp is Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+ *
+ * This is an auto-generated file.
+ * Do not edit! All changes made to it will be lost.
+ */
+
+#ifndef PINGER_H_1246463415
+#define PINGER_H_1246463415
+
+#include <QtCore/QObject>
+#include <QtCore/QByteArray>
+#include <QtCore/QList>
+#include <QtCore/QMap>
+#include <QtCore/QString>
+#include <QtCore/QStringList>
+#include <QtCore/QVariant>
+#include <QtDBus/QtDBus>
+#include "interface.h"
+
+/*
+ * Proxy class for interface com.trolltech.QtDBus.Pinger
+ */
+class ComTrolltechQtDBusPingerInterface: public QDBusAbstractInterface
+{
+ Q_OBJECT
+public:
+ static inline const char *staticInterfaceName()
+ { return "com.trolltech.QtDBus.Pinger"; }
+
+public:
+ ComTrolltechQtDBusPingerInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
+
+ ~ComTrolltechQtDBusPingerInterface();
+
+ Q_PROPERTY(RegisteredType complexProp READ complexProp WRITE setComplexProp)
+ inline RegisteredType complexProp() const
+ { return qvariant_cast< RegisteredType >(property("complexProp")); }
+ inline void setComplexProp(RegisteredType value)
+ { setProperty("complexProp", qVariantFromValue(value)); }
+
+ Q_PROPERTY(QString stringProp READ stringProp WRITE setStringProp)
+ inline QString stringProp() const
+ { return qvariant_cast< QString >(property("stringProp")); }
+ inline void setStringProp(const QString &value)
+ { setProperty("stringProp", qVariantFromValue(value)); }
+
+ Q_PROPERTY(QDBusVariant variantProp READ variantProp WRITE setVariantProp)
+ inline QDBusVariant variantProp() const
+ { return qvariant_cast< QDBusVariant >(property("variantProp")); }
+ inline void setVariantProp(const QDBusVariant &value)
+ { setProperty("variantProp", qVariantFromValue(value)); }
+
+public Q_SLOTS: // METHODS
+ inline QDBusPendingReply<RegisteredType> complexMethod()
+ {
+ QList<QVariant> argumentList;
+ return asyncCallWithArgumentList(QLatin1String("complexMethod"), argumentList);
+ }
+
+ inline QDBusPendingReply<QString, int> multiOutMethod()
+ {
+ QList<QVariant> argumentList;
+ return asyncCallWithArgumentList(QLatin1String("multiOutMethod"), argumentList);
+ }
+ inline QDBusReply<QString> multiOutMethod(int &out1)
+ {
+ QList<QVariant> argumentList;
+ QDBusMessage reply = callWithArgumentList(QDBus::Block, QLatin1String("multiOutMethod"), argumentList);
+ if (reply.type() == QDBusMessage::ReplyMessage && reply.arguments().count() == 2) {
+ out1 = qdbus_cast<int>(reply.arguments().at(1));
+ }
+ return reply;
+ }
+
+ inline QDBusPendingReply<QString> stringMethod()
+ {
+ QList<QVariant> argumentList;
+ return asyncCallWithArgumentList(QLatin1String("stringMethod"), argumentList);
+ }
+
+ inline QDBusPendingReply<> voidMethod()
+ {
+ QList<QVariant> argumentList;
+ return asyncCallWithArgumentList(QLatin1String("voidMethod"), argumentList);
+ }
+
+Q_SIGNALS: // SIGNALS
+ void complexSignal(RegisteredType in0);
+ void stringSignal(const QString &in0);
+ void voidSignal();
+};
+
+namespace com {
+ namespace trolltech {
+ namespace QtDBus {
+ typedef ::ComTrolltechQtDBusPingerInterface Pinger;
+ }
+ }
+}
+#endif
diff --git a/tests/auto/qdbusabstractinterface/qdbusabstractinterface.pro b/tests/auto/qdbusabstractinterface/qdbusabstractinterface.pro
new file mode 100644
index 0000000..a4853b8
--- /dev/null
+++ b/tests/auto/qdbusabstractinterface/qdbusabstractinterface.pro
@@ -0,0 +1,15 @@
+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
+}
+else:SOURCES += ../qdbusmarshall/dummy.cpp
+
+OTHER_FILES += com.trolltech.QtDBus.Pinger.xml
diff --git a/tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp b/tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp
new file mode 100644
index 0000000..fa5e332
--- /dev/null
+++ b/tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp
@@ -0,0 +1,576 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** 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 either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** 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.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <qcoreapplication.h>
+#include <qdebug.h>
+#include <qsharedpointer.h>
+
+#include <QtTest/QtTest>
+
+#include <QtDBus>
+
+#include "interface.h"
+#include "pinger.h"
+
+typedef QSharedPointer<com::trolltech::QtDBus::Pinger> Pinger;
+
+class tst_QDBusAbstractInterface: public QObject
+{
+ Q_OBJECT
+ Interface targetObj;
+
+ Pinger getPinger(QString service = "", const QString &path = "/")
+ {
+ QDBusConnection con = QDBusConnection::sessionBus();
+ if (!con.isConnected())
+ return Pinger();
+ if (service.isEmpty() && !service.isNull())
+ service = con.baseService();
+ return Pinger(new com::trolltech::QtDBus::Pinger(service, path, con));
+ }
+
+public:
+ tst_QDBusAbstractInterface();
+
+private slots:
+ void initTestCase();
+
+ void makeVoidCall();
+ void makeStringCall();
+ void makeComplexCall();
+ void makeMultiOutCall();
+
+ void makeAsyncVoidCall();
+ void makeAsyncStringCall();
+ void makeAsyncComplexCall();
+ void makeAsyncMultiOutCall();
+
+ void stringPropRead();
+ void stringPropWrite();
+ void variantPropRead();
+ void variantPropWrite();
+ void complexPropRead();
+ void complexPropWrite();
+
+ void stringPropDirectRead();
+ void stringPropDirectWrite();
+ void variantPropDirectRead();
+ void variantPropDirectWrite();
+ void complexPropDirectRead();
+ void complexPropDirectWrite();
+
+ void getVoidSignal_data();
+ void getVoidSignal();
+ void getStringSignal_data();
+ void getStringSignal();
+ void getComplexSignal_data();
+ void getComplexSignal();
+
+ void createErrors_data();
+ void createErrors();
+
+ void callErrors_data();
+ void callErrors();
+ void asyncCallErrors_data();
+ void asyncCallErrors();
+
+ void propertyReadErrors_data();
+ void propertyReadErrors();
+ void propertyWriteErrors_data();
+ void propertyWriteErrors();
+ void directPropertyReadErrors_data();
+ void directPropertyReadErrors();
+ void directPropertyWriteErrors_data();
+ void directPropertyWriteErrors();
+};
+
+tst_QDBusAbstractInterface::tst_QDBusAbstractInterface()
+{
+ // register the meta types
+ qDBusRegisterMetaType<RegisteredType>();
+ qRegisterMetaType<UnregisteredType>();
+}
+
+void tst_QDBusAbstractInterface::initTestCase()
+{
+ // register the object
+ QDBusConnection con = QDBusConnection::sessionBus();
+ QVERIFY(con.isConnected());
+ con.registerObject("/", &targetObj, QDBusConnection::ExportScriptableContents);
+}
+
+void tst_QDBusAbstractInterface::makeVoidCall()
+{
+ Pinger p = getPinger();
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ QDBusReply<void> r = p->voidMethod();
+ QVERIFY(r.isValid());
+}
+
+void tst_QDBusAbstractInterface::makeStringCall()
+{
+ Pinger p = getPinger();
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ QDBusReply<QString> r = p->stringMethod();
+ QVERIFY(r.isValid());
+ QCOMPARE(r.value(), targetObj.stringMethod());
+}
+
+void tst_QDBusAbstractInterface::makeComplexCall()
+{
+ Pinger p = getPinger();
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ QDBusReply<RegisteredType> r = p->complexMethod();
+ QVERIFY(r.isValid());
+ QCOMPARE(r.value(), targetObj.complexMethod());
+}
+
+void tst_QDBusAbstractInterface::makeMultiOutCall()
+{
+ Pinger p = getPinger();
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ int value;
+ QDBusReply<QString> r = p->multiOutMethod(value);
+ QVERIFY(r.isValid());
+
+ int expectedValue;
+ QCOMPARE(r.value(), targetObj.multiOutMethod(expectedValue));
+ QCOMPARE(value, expectedValue);
+}
+
+void tst_QDBusAbstractInterface::makeAsyncVoidCall()
+{
+ Pinger p = getPinger();
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ QDBusPendingReply<void> r = p->voidMethod();
+ r.waitForFinished();
+ QVERIFY(r.isValid());
+}
+
+void tst_QDBusAbstractInterface::makeAsyncStringCall()
+{
+ Pinger p = getPinger();
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ QDBusPendingReply<QString> r = p->stringMethod();
+ r.waitForFinished();
+ QVERIFY(r.isValid());
+ QCOMPARE(r.value(), targetObj.stringMethod());
+}
+
+void tst_QDBusAbstractInterface::makeAsyncComplexCall()
+{
+ Pinger p = getPinger();
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ QDBusPendingReply<RegisteredType> r = p->complexMethod();
+ r.waitForFinished();
+ QVERIFY(r.isValid());
+ QCOMPARE(r.value(), targetObj.complexMethod());
+}
+
+void tst_QDBusAbstractInterface::makeAsyncMultiOutCall()
+{
+ Pinger p = getPinger();
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ QDBusPendingReply<QString, int> r = p->multiOutMethod();
+ r.waitForFinished();
+ QVERIFY(r.isValid());
+
+ int expectedValue;
+ QCOMPARE(r.value(), targetObj.multiOutMethod(expectedValue));
+ QCOMPARE(r.argumentAt<1>(), expectedValue);
+}
+
+void tst_QDBusAbstractInterface::stringPropRead()
+{
+ Pinger p = getPinger();
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ QString expectedValue = targetObj.m_stringProp = "This is a test";
+ QVariant v = p->property("stringProp");
+ QVERIFY(v.isValid());
+ QCOMPARE(v.toString(), expectedValue);
+}
+
+void tst_QDBusAbstractInterface::stringPropWrite()
+{
+ Pinger p = getPinger();
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ QString expectedValue = "This is a value";
+ QVERIFY(p->setProperty("stringProp", expectedValue));
+ QCOMPARE(targetObj.m_stringProp, expectedValue);
+}
+
+void tst_QDBusAbstractInterface::variantPropRead()
+{
+ Pinger p = getPinger();
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ QDBusVariant expectedValue = targetObj.m_variantProp = QDBusVariant(QVariant(42));
+ QVariant v = p->property("variantProp");
+ QVERIFY(v.isValid());
+ QDBusVariant value = v.value<QDBusVariant>();
+ QCOMPARE(value.variant().userType(), expectedValue.variant().userType());
+ QCOMPARE(value.variant(), expectedValue.variant());
+}
+
+void tst_QDBusAbstractInterface::variantPropWrite()
+{
+ Pinger p = getPinger();
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ QDBusVariant expectedValue = QDBusVariant(Q_INT64_C(-47));
+ QVERIFY(p->setProperty("variantProp", qVariantFromValue(expectedValue)));
+ QCOMPARE(targetObj.m_variantProp.variant(), expectedValue.variant());
+}
+
+void tst_QDBusAbstractInterface::complexPropRead()
+{
+ Pinger p = getPinger();
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ RegisteredType expectedValue = targetObj.m_complexProp = RegisteredType("This is a test");
+ QVariant v = p->property("complexProp");
+ QVERIFY(v.userType() == qMetaTypeId<RegisteredType>());
+ QCOMPARE(v.value<RegisteredType>(), targetObj.m_complexProp);
+}
+
+void tst_QDBusAbstractInterface::complexPropWrite()
+{
+ Pinger p = getPinger();
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ RegisteredType expectedValue = RegisteredType("This is a value");
+ QVERIFY(p->setProperty("complexProp", qVariantFromValue(expectedValue)));
+ QCOMPARE(targetObj.m_complexProp, expectedValue);
+}
+
+void tst_QDBusAbstractInterface::stringPropDirectRead()
+{
+ Pinger p = getPinger();
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ QString expectedValue = targetObj.m_stringProp = "This is a test";
+ QCOMPARE(p->stringProp(), expectedValue);
+}
+
+void tst_QDBusAbstractInterface::stringPropDirectWrite()
+{
+ Pinger p = getPinger();
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ QString expectedValue = "This is a value";
+ p->setStringProp(expectedValue);
+ QCOMPARE(targetObj.m_stringProp, expectedValue);
+}
+
+void tst_QDBusAbstractInterface::variantPropDirectRead()
+{
+ Pinger p = getPinger();
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ QDBusVariant expectedValue = targetObj.m_variantProp = QDBusVariant(42);
+ QCOMPARE(p->variantProp().variant(), expectedValue.variant());
+}
+
+void tst_QDBusAbstractInterface::variantPropDirectWrite()
+{
+ Pinger p = getPinger();
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ QDBusVariant expectedValue = QDBusVariant(Q_INT64_C(-47));
+ p->setVariantProp(expectedValue);
+ QCOMPARE(targetObj.m_variantProp.variant().userType(), expectedValue.variant().userType());
+ QCOMPARE(targetObj.m_variantProp.variant(), expectedValue.variant());
+}
+
+void tst_QDBusAbstractInterface::complexPropDirectRead()
+{
+ Pinger p = getPinger();
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ RegisteredType expectedValue = targetObj.m_complexProp = RegisteredType("This is a test");
+ QCOMPARE(p->complexProp(), targetObj.m_complexProp);
+}
+
+void tst_QDBusAbstractInterface::complexPropDirectWrite()
+{
+ Pinger p = getPinger();
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ RegisteredType expectedValue = RegisteredType("This is a value");
+ p->setComplexProp(expectedValue);
+ QCOMPARE(targetObj.m_complexProp, expectedValue);
+}
+
+void tst_QDBusAbstractInterface::getVoidSignal_data()
+{
+ QTest::addColumn<QString>("service");
+ QTest::addColumn<QString>("path");
+
+ QTest::newRow("specific") << QDBusConnection::sessionBus().baseService() << "/";
+ QTest::newRow("service-wildcard") << QString() << "/";
+ QTest::newRow("path-wildcard") << QDBusConnection::sessionBus().baseService() << QString();
+ QTest::newRow("full-wildcard") << QString() << QString();
+}
+
+void tst_QDBusAbstractInterface::getVoidSignal()
+{
+ QFETCH(QString, service);
+ QFETCH(QString, path);
+ Pinger p = getPinger(service, path);
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ // we need to connect the signal somewhere in order for D-Bus to enable the rules
+ QTestEventLoop::instance().connect(p.data(), SIGNAL(voidSignal()), SLOT(exitLoop()));
+ QSignalSpy s(p.data(), SIGNAL(voidSignal()));
+
+ emit targetObj.voidSignal();
+ QTestEventLoop::instance().enterLoop(2);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+
+ QVERIFY(s.size() == 1);
+ QVERIFY(s.at(0).size() == 0);
+}
+
+void tst_QDBusAbstractInterface::getStringSignal_data()
+{
+ getVoidSignal_data();
+}
+
+void tst_QDBusAbstractInterface::getStringSignal()
+{
+ QFETCH(QString, service);
+ QFETCH(QString, path);
+ Pinger p = getPinger(service, path);
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ // we need to connect the signal somewhere in order for D-Bus to enable the rules
+ QTestEventLoop::instance().connect(p.data(), SIGNAL(stringSignal(QString)), SLOT(exitLoop()));
+ QSignalSpy s(p.data(), SIGNAL(stringSignal(QString)));
+
+ QString expectedValue = "Good morning";
+ emit targetObj.stringSignal(expectedValue);
+ QTestEventLoop::instance().enterLoop(2);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+
+ QVERIFY(s.size() == 1);
+ QVERIFY(s[0].size() == 1);
+ QCOMPARE(s[0][0].userType(), int(QVariant::String));
+ QCOMPARE(s[0][0].toString(), expectedValue);
+}
+
+void tst_QDBusAbstractInterface::getComplexSignal_data()
+{
+ getVoidSignal_data();
+}
+
+void tst_QDBusAbstractInterface::getComplexSignal()
+{
+ QFETCH(QString, service);
+ QFETCH(QString, path);
+ Pinger p = getPinger(service, path);
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ // we need to connect the signal somewhere in order for D-Bus to enable the rules
+ QTestEventLoop::instance().connect(p.data(), SIGNAL(complexSignal(RegisteredType)), SLOT(exitLoop()));
+ QSignalSpy s(p.data(), SIGNAL(complexSignal(RegisteredType)));
+
+ RegisteredType expectedValue("Good evening");
+ emit targetObj.complexSignal(expectedValue);
+ QTestEventLoop::instance().enterLoop(2);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+
+ QVERIFY(s.size() == 1);
+ QVERIFY(s[0].size() == 1);
+ QCOMPARE(s[0][0].userType(), qMetaTypeId<RegisteredType>());
+ QCOMPARE(s[0][0].value<RegisteredType>(), expectedValue);
+}
+
+void tst_QDBusAbstractInterface::createErrors_data()
+{
+ QTest::addColumn<QString>("service");
+ QTest::addColumn<QString>("path");
+ QTest::addColumn<QString>("errorName");
+
+ QTest::newRow("invalid-service") << "this isn't valid" << "/" << "com.trolltech.QtDBus.Error.InvalidService";
+ QTest::newRow("invalid-path") << QDBusConnection::sessionBus().baseService() << "this isn't valid"
+ << "com.trolltech.QtDBus.Error.InvalidObjectPath";
+}
+
+void tst_QDBusAbstractInterface::createErrors()
+{
+ QFETCH(QString, service);
+ QFETCH(QString, path);
+ Pinger p = getPinger(service, path);
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ QVERIFY(!p->isValid());
+ QTEST(p->lastError().name(), "errorName");
+}
+
+void tst_QDBusAbstractInterface::callErrors_data()
+{
+ createErrors_data();
+ QTest::newRow("service-wildcard") << QString() << "/" << "com.trolltech.QtDBus.Error.InvalidService";
+ QTest::newRow("path-wildcard") << QDBusConnection::sessionBus().baseService() << QString()
+ << "com.trolltech.QtDBus.Error.InvalidObjectPath";
+ QTest::newRow("full-wildcard") << QString() << QString() << "com.trolltech.QtDBus.Error.InvalidService";
+}
+
+void tst_QDBusAbstractInterface::callErrors()
+{
+ QFETCH(QString, service);
+ QFETCH(QString, path);
+ Pinger p = getPinger(service, path);
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ // we shouldn't be able to make this call:
+ QDBusReply<QString> r = p->stringMethod();
+ QVERIFY(!r.isValid());
+ QTEST(r.error().name(), "errorName");
+ QCOMPARE(p->lastError().name(), r.error().name());
+}
+
+void tst_QDBusAbstractInterface::asyncCallErrors_data()
+{
+ callErrors_data();
+}
+
+void tst_QDBusAbstractInterface::asyncCallErrors()
+{
+ QFETCH(QString, service);
+ QFETCH(QString, path);
+ Pinger p = getPinger(service, path);
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ // we shouldn't be able to make this call:
+ QDBusPendingReply<QString> r = p->stringMethod();
+ QVERIFY(r.isError());
+ QTEST(r.error().name(), "errorName");
+ QCOMPARE(p->lastError().name(), r.error().name());
+}
+
+void tst_QDBusAbstractInterface::propertyReadErrors_data()
+{
+ callErrors_data();
+}
+
+void tst_QDBusAbstractInterface::propertyReadErrors()
+{
+ QFETCH(QString, service);
+ QFETCH(QString, path);
+ Pinger p = getPinger(service, path);
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ // we shouldn't be able to get this value:
+ QVariant v = p->property("stringProp");
+ QVERIFY(v.isNull());
+ QVERIFY(!v.isValid());
+ QTEST(p->lastError().name(), "errorName");
+}
+
+void tst_QDBusAbstractInterface::propertyWriteErrors_data()
+{
+ callErrors_data();
+}
+
+void tst_QDBusAbstractInterface::propertyWriteErrors()
+{
+ QFETCH(QString, service);
+ QFETCH(QString, path);
+ Pinger p = getPinger(service, path);
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ // we shouldn't be able to get this value:
+ if (p->isValid())
+ QCOMPARE(int(p->lastError().type()), int(QDBusError::NoError));
+ QVERIFY(!p->setProperty("stringProp", ""));
+ QTEST(p->lastError().name(), "errorName");
+}
+
+void tst_QDBusAbstractInterface::directPropertyReadErrors_data()
+{
+ callErrors_data();
+}
+
+void tst_QDBusAbstractInterface::directPropertyReadErrors()
+{
+ QFETCH(QString, service);
+ QFETCH(QString, path);
+ Pinger p = getPinger(service, path);
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ // we shouldn't be able to get this value:
+ QString v = p->stringProp();
+ QVERIFY(v.isNull());
+ QTEST(p->lastError().name(), "errorName");
+}
+
+void tst_QDBusAbstractInterface::directPropertyWriteErrors_data()
+{
+ callErrors_data();
+}
+
+void tst_QDBusAbstractInterface::directPropertyWriteErrors()
+{
+ QFETCH(QString, service);
+ QFETCH(QString, path);
+ Pinger p = getPinger(service, path);
+ QVERIFY2(p, "Not connected to D-Bus");
+
+ // we shouldn't be able to get this value:
+ // but there's no direct way of verifying that the setting failed
+ if (p->isValid())
+ QCOMPARE(int(p->lastError().type()), int(QDBusError::NoError));
+ p->setStringProp("");
+ QTEST(p->lastError().name(), "errorName");
+}
+
+QTEST_MAIN(tst_QDBusAbstractInterface)
+#include "tst_qdbusabstractinterface.moc"
diff --git a/tests/auto/qdbusinterface/tst_qdbusinterface.cpp b/tests/auto/qdbusinterface/tst_qdbusinterface.cpp
index c4d4b08..60afe4e 100644
--- a/tests/auto/qdbusinterface/tst_qdbusinterface.cpp
+++ b/tests/auto/qdbusinterface/tst_qdbusinterface.cpp
@@ -60,6 +60,9 @@ class MyObject: public QObject
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&lt;int&gt;\"/>\n"
+" </property>\n"
" <signal name=\"somethingHappened\" >\n"
" <arg direction=\"out\" type=\"s\" />\n"
" </signal>\n"
@@ -73,8 +76,17 @@ class MyObject: public QObject
" <arg direction=\"out\" type=\"v\" name=\"pong1\" />\n"
" <arg direction=\"out\" type=\"v\" name=\"pong2\" />\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&lt;int&gt;\"/>\n"
+" <annotation name=\"com.trolltech.QtDBus.QtTypeName.Out0\" value=\"QList&lt;int&gt;\"/>\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;
@@ -84,6 +96,30 @@ public:
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;
+ }
+
public slots:
void ping(QDBusMessage msg)
@@ -144,8 +180,16 @@ private slots:
void introspect();
void callMethod();
void invokeMethod();
+ void invokeMethodWithReturn();
+ void invokeMethodWithMultiReturn();
+ void invokeMethodWithComplexReturn();
void signal();
+
+ void propertyRead();
+ void propertyWrite();
+ void complexPropertyRead();
+ void complexPropertyWrite();
};
void tst_QDBusInterface::initTestCase()
@@ -154,7 +198,7 @@ void tst_QDBusInterface::initTestCase()
QVERIFY(con.isConnected());
QTest::qWait(500);
- con.registerObject("/", &obj, QDBusConnection::ExportAdaptors
+ con.registerObject("/", &obj, QDBusConnection::ExportAllProperties
| QDBusConnection::ExportAllSlots
| QDBusConnection::ExportChildObjects);
}
@@ -228,11 +272,12 @@ void tst_QDBusInterface::introspect()
const QMetaObject *mo = iface.metaObject();
- QCOMPARE(mo->methodCount() - mo->methodOffset(), 3);
+ QCOMPARE(mo->methodCount() - mo->methodOffset(), 4);
QVERIFY(mo->indexOfSignal(TEST_SIGNAL_NAME "(QString)") != -1);
- QCOMPARE(mo->propertyCount() - mo->propertyOffset(), 1);
+ QCOMPARE(mo->propertyCount() - mo->propertyOffset(), 2);
QVERIFY(mo->indexOfProperty("prop1") != -1);
+ QVERIFY(mo->indexOfProperty("complexProp") != -1);
}
void tst_QDBusInterface::callMethod()
@@ -281,6 +326,87 @@ void tst_QDBusInterface::invokeMethod()
QCOMPARE(dv.variant().toString(), QString("foo"));
}
+void tst_QDBusInterface::invokeMethodWithReturn()
+{
+ QDBusConnection con = QDBusConnection::sessionBus();
+ QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"),
+ TEST_INTERFACE_NAME);
+
+ // make the call without a return type
+ MyObject::callCount = 0;
+ QDBusVariant arg("foo");
+ QDBusVariant retArg;
+ QVERIFY(QMetaObject::invokeMethod(&iface, "ping", Q_RETURN_ARG(QDBusVariant, retArg), Q_ARG(QDBusVariant, arg)));
+ QCOMPARE(MyObject::callCount, 1);
+
+ // verify what the callee received
+ QCOMPARE(MyObject::callArgs.count(), 1);
+ QVariant v = MyObject::callArgs.at(0);
+ QDBusVariant dv = qdbus_cast<QDBusVariant>(v);
+ QCOMPARE(dv.variant().type(), QVariant::String);
+ QCOMPARE(dv.variant().toString(), arg.variant().toString());
+
+ // verify that we got the reply as expected
+ QCOMPARE(retArg.variant(), arg.variant());
+}
+
+void tst_QDBusInterface::invokeMethodWithMultiReturn()
+{
+ QDBusConnection con = QDBusConnection::sessionBus();
+ QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"),
+ TEST_INTERFACE_NAME);
+
+ // make the call without a return type
+ MyObject::callCount = 0;
+ QDBusVariant arg("foo"), arg2("bar");
+ QDBusVariant retArg, retArg2;
+ QVERIFY(QMetaObject::invokeMethod(&iface, "ping",
+ Q_RETURN_ARG(QDBusVariant, retArg),
+ Q_ARG(QDBusVariant, arg),
+ Q_ARG(QDBusVariant, arg2),
+ Q_ARG(QDBusVariant&, retArg2)));
+ QCOMPARE(MyObject::callCount, 1);
+
+ // verify what the callee received
+ QCOMPARE(MyObject::callArgs.count(), 2);
+ QVariant v = MyObject::callArgs.at(0);
+ QDBusVariant dv = qdbus_cast<QDBusVariant>(v);
+ QCOMPARE(dv.variant().type(), QVariant::String);
+ QCOMPARE(dv.variant().toString(), arg.variant().toString());
+
+ v = MyObject::callArgs.at(1);
+ dv = qdbus_cast<QDBusVariant>(v);
+ QCOMPARE(dv.variant().type(), QVariant::String);
+ QCOMPARE(dv.variant().toString(), arg2.variant().toString());
+
+ // verify that we got the replies as expected
+ QCOMPARE(retArg.variant(), arg.variant());
+ QCOMPARE(retArg2.variant(), arg2.variant());
+}
+
+void tst_QDBusInterface::invokeMethodWithComplexReturn()
+{
+ QDBusConnection con = QDBusConnection::sessionBus();
+ QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"),
+ TEST_INTERFACE_NAME);
+
+ // make the call without a return type
+ MyObject::callCount = 0;
+ QList<int> arg = QList<int>() << 42 << -47;
+ QList<int> retArg;
+ QVERIFY(QMetaObject::invokeMethod(&iface, "ping", Q_RETURN_ARG(QList<int>, retArg), Q_ARG(QList<int>, arg)));
+ QCOMPARE(MyObject::callCount, 1);
+
+ // verify what the callee received
+ QCOMPARE(MyObject::callArgs.count(), 1);
+ QVariant v = MyObject::callArgs.at(0);
+ QCOMPARE(v.userType(), qMetaTypeId<QDBusArgument>());
+ QCOMPARE(qdbus_cast<QList<int> >(v), arg);
+
+ // verify that we got the reply as expected
+ QCOMPARE(retArg, arg);
+}
+
void tst_QDBusInterface::signal()
{
QDBusConnection con = QDBusConnection::sessionBus();
@@ -322,6 +448,68 @@ void tst_QDBusInterface::signal()
}
}
+void tst_QDBusInterface::propertyRead()
+{
+ QDBusConnection con = QDBusConnection::sessionBus();
+ QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"),
+ TEST_INTERFACE_NAME);
+
+ int arg = obj.m_prop1 = 42;
+ MyObject::callCount = 0;
+
+ QVariant v = iface.property("prop1");
+ QVERIFY(v.isValid());
+ QCOMPARE(v.userType(), int(QVariant::Int));
+ QCOMPARE(v.toInt(), arg);
+ QCOMPARE(MyObject::callCount, 1);
+}
+
+void tst_QDBusInterface::propertyWrite()
+{
+ QDBusConnection con = QDBusConnection::sessionBus();
+ QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"),
+ TEST_INTERFACE_NAME);
+
+ int arg = 42;
+ obj.m_prop1 = 0;
+ MyObject::callCount = 0;
+
+ QVERIFY(iface.setProperty("prop1", arg));
+ QCOMPARE(MyObject::callCount, 1);
+ QCOMPARE(obj.m_prop1, arg);
+}
+
+void tst_QDBusInterface::complexPropertyRead()
+{
+ QDBusConnection con = QDBusConnection::sessionBus();
+ QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"),
+ TEST_INTERFACE_NAME);
+
+ QList<int> arg = obj.m_complexProp = QList<int>() << 42 << -47;
+ MyObject::callCount = 0;
+
+ QVariant v = iface.property("complexProp");
+ QVERIFY(v.isValid());
+ QCOMPARE(v.userType(), qMetaTypeId<QList<int> >());
+ QCOMPARE(v.value<QList<int> >(), arg);
+ QCOMPARE(MyObject::callCount, 1);
+}
+
+void tst_QDBusInterface::complexPropertyWrite()
+{
+ QDBusConnection con = QDBusConnection::sessionBus();
+ QDBusInterface iface(QDBusConnection::sessionBus().baseService(), QLatin1String("/"),
+ TEST_INTERFACE_NAME);
+
+ QList<int> arg = QList<int>() << -47 << 42;
+ obj.m_complexProp.clear();
+ MyObject::callCount = 0;
+
+ QVERIFY(iface.setProperty("complexProp", qVariantFromValue(arg)));
+ QCOMPARE(MyObject::callCount, 1);
+ QCOMPARE(obj.m_complexProp, arg);
+}
+
QTEST_MAIN(tst_QDBusInterface)
#include "tst_qdbusinterface.moc"
diff --git a/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp b/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp
index e5b2ebb..e304712 100644
--- a/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp
+++ b/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp
@@ -84,12 +84,17 @@ private slots:
void sendArgument_data();
void sendArgument();
- void sendErrors();
+ void sendSignalErrors();
+ void sendCallErrors_data();
+ void sendCallErrors();
private:
QProcess proc;
};
+struct UnregisteredType { };
+Q_DECLARE_METATYPE(UnregisteredType)
+
class WaitForQPong: public QObject
{
Q_OBJECT
@@ -784,7 +789,7 @@ void tst_QDBusMarshall::sendArgument()
QCOMPARE(extracted, value);
}
-void tst_QDBusMarshall::sendErrors()
+void tst_QDBusMarshall::sendSignalErrors()
{
QDBusConnection con = QDBusConnection::sessionBus();
@@ -793,7 +798,7 @@ void tst_QDBusMarshall::sendErrors()
"signalName");
msg << qVariantFromValue(QDBusObjectPath());
- QTest::ignoreMessage(QtWarningMsg, "QDBusConnection: error: could not send signal path \"/foo\" interface \"local.interfaceName\" member \"signalName\"");
+ QTest::ignoreMessage(QtWarningMsg, "QDBusConnection: error: could not send signal path \"/foo\" interface \"local.interfaceName\" member \"signalName\": Marshalling failed: Invalid object path passed in arguments");
QVERIFY(!con.send(msg));
msg.setArguments(QVariantList());
@@ -803,9 +808,117 @@ void tst_QDBusMarshall::sendErrors()
path.setPath("abc");
msg << qVariantFromValue(path);
- QTest::ignoreMessage(QtWarningMsg, "QDBusConnection: error: could not send signal path \"/foo\" interface \"local.interfaceName\" member \"signalName\"");
+ QTest::ignoreMessage(QtWarningMsg, "QDBusConnection: error: could not send signal path \"/foo\" interface \"local.interfaceName\" member \"signalName\": Marshalling failed: Invalid object path passed in arguments");
+ QVERIFY(!con.send(msg));
+
+ QDBusSignature sig;
+ msg.setArguments(QVariantList() << qVariantFromValue(sig));
+ QTest::ignoreMessage(QtWarningMsg, "QDBusConnection: error: could not send signal path \"/foo\" interface \"local.interfaceName\" member \"signalName\": Marshalling failed: Invalid signature passed in arguments");
+ QVERIFY(!con.send(msg));
+
+ QTest::ignoreMessage(QtWarningMsg, "QDBusSignature: invalid signature \"a\"");
+ sig.setSignature("a");
+ msg.setArguments(QVariantList());
+ msg << qVariantFromValue(sig);
+ QTest::ignoreMessage(QtWarningMsg, "QDBusConnection: error: could not send signal path \"/foo\" interface \"local.interfaceName\" member \"signalName\": Marshalling failed: Invalid signature passed in arguments");
QVERIFY(!con.send(msg));
}
+void tst_QDBusMarshall::sendCallErrors_data()
+{
+ QTest::addColumn<QString>("service");
+ QTest::addColumn<QString>("path");
+ QTest::addColumn<QString>("interface");
+ QTest::addColumn<QString>("method");
+ QTest::addColumn<QVariantList>("arguments");
+ QTest::addColumn<QString>("errorName");
+ QTest::addColumn<QString>("errorMsg");
+ QTest::addColumn<QString>("ignoreMsg");
+
+ // this error comes from the bus server
+ QTest::newRow("empty-service") << "" << objectPath << interfaceName << "ping" << QVariantList()
+ << "org.freedesktop.DBus.Error.UnknownMethod"
+ << "Method \"ping\" with signature \"\" on interface \"com.trolltech.autotests.qpong\" doesn't exist\n" << (const char*)0;
+
+ QTest::newRow("invalid-service") << "this isn't valid" << objectPath << interfaceName << "ping" << QVariantList()
+ << "com.trolltech.QtDBus.Error.InvalidService"
+ << "Invalid service name: this isn't valid" << "";
+
+ QTest::newRow("empty-path") << serviceName << "" << interfaceName << "ping" << QVariantList()
+ << "com.trolltech.QtDBus.Error.InvalidObjectPath"
+ << "Object path cannot be empty" << "";
+ QTest::newRow("invalid-path") << serviceName << "//" << interfaceName << "ping" << QVariantList()
+ << "com.trolltech.QtDBus.Error.InvalidObjectPath"
+ << "Invalid object path: //" << "";
+
+ // empty interfaces are valid
+ QTest::newRow("invalid-interface") << serviceName << objectPath << "this isn't valid" << "ping" << QVariantList()
+ << "com.trolltech.QtDBus.Error.InvalidInterface"
+ << "Invalid interface class: this isn't valid" << "";
+
+ QTest::newRow("empty-method") << serviceName << objectPath << interfaceName << "" << QVariantList()
+ << "com.trolltech.QtDBus.Error.InvalidMember"
+ << "method name cannot be empty" << "";
+ QTest::newRow("invalid-method") << serviceName << objectPath << interfaceName << "this isn't valid" << QVariantList()
+ << "com.trolltech.QtDBus.Error.InvalidMember"
+ << "Invalid method name: this isn't valid" << "";
+
+ QTest::newRow("invalid-variant1") << serviceName << objectPath << interfaceName << "ping"
+ << (QVariantList() << QVariant())
+ << "org.freedesktop.DBus.Error.Failed"
+ << "Marshalling failed: Variant containing QVariant::Invalid passed in arguments"
+ << "QDBusMarshaller: cannot add an invalid QVariant";
+ QTest::newRow("invalid-variant1") << serviceName << objectPath << interfaceName << "ping"
+ << (QVariantList() << qVariantFromValue(QDBusVariant()))
+ << "org.freedesktop.DBus.Error.Failed"
+ << "Marshalling failed: Variant containing QVariant::Invalid passed in arguments"
+ << "QDBusMarshaller: cannot add a null QDBusVariant";
+
+ QTest::newRow("builtin-unregistered") << serviceName << objectPath << interfaceName << "ping"
+ << (QVariantList() << QLocale::c())
+ << "org.freedesktop.DBus.Error.Failed"
+ << "Marshalling failed: Unregistered type QLocale passed in arguments"
+ << "QDBusMarshaller: type `QLocale' (18) is not registered with D-BUS. Use qDBusRegisterMetaType to register it";
+
+ // this type is known to the meta type system, but not registered with D-Bus
+ qRegisterMetaType<UnregisteredType>();
+ QTest::newRow("extra-unregistered") << serviceName << objectPath << interfaceName << "ping"
+ << (QVariantList() << qVariantFromValue(UnregisteredType()))
+ << "org.freedesktop.DBus.Error.Failed"
+ << "Marshalling failed: Unregistered type UnregisteredType passed in arguments"
+ << QString("QDBusMarshaller: type `UnregisteredType' (%1) is not registered with D-BUS. Use qDBusRegisterMetaType to register it")
+ .arg(qMetaTypeId<UnregisteredType>());
+}
+
+void tst_QDBusMarshall::sendCallErrors()
+{
+ QDBusConnection con = QDBusConnection::sessionBus();
+ QVERIFY(con.isConnected());
+
+ QFETCH(QString, service);
+ QFETCH(QString, path);
+ QFETCH(QString, interface);
+ QFETCH(QString, method);
+ QFETCH(QVariantList, arguments);
+ QFETCH(QString, errorMsg);
+
+ QFETCH(QString, ignoreMsg);
+ if (!ignoreMsg.isEmpty())
+ QTest::ignoreMessage(QtWarningMsg, ignoreMsg.toLatin1());
+ if (!ignoreMsg.isNull())
+ QTest::ignoreMessage(QtWarningMsg,
+ QString("QDBusConnection: error: could not send message to service \"%1\" path \"%2\" interface \"%3\" member \"%4\": %5")
+ .arg(service, path, interface, method, errorMsg)
+ .toLatin1());
+
+ QDBusMessage msg = QDBusMessage::createMethodCall(service, path, interface, method);
+ msg.setArguments(arguments);
+
+ QDBusMessage reply = con.call(msg, QDBus::Block);
+ QCOMPARE(reply.type(), QDBusMessage::ErrorMessage);
+ QTEST(reply.errorName(), "errorName");
+ QCOMPARE(reply.errorMessage(), errorMsg);
+}
+
QTEST_MAIN(tst_QDBusMarshall)
#include "tst_qdbusmarshall.moc"