diff options
author | David Faure <faure@kde.org> | 2013-05-04 15:13:47 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-05-10 09:03:29 +0200 |
commit | 2116f9904afca7b3942433269b66a9756d5876bc (patch) | |
tree | b3b5a45ef56874da365d91b6df12f70e793a68ef /tests | |
parent | 1b2d3be446df492c009bd575637a0f103241ce4d (diff) |
QDBus: Add test for a{sv} and an annotation pointing to QVariantHash.
QVariantMap would work too; I presume this is why the annotation is needed,
rather than QtDBus automatically figuring out which type to use.
This even checks that QHash<QString,QVariant> works in the annotation,
although QVariantHash would be simpler to write, obviously.
Change-Id: I7a339ca90f10e5ec97dcea1bb4dbba3c515e6b23
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Kevin Ottens <kevin.ottens@kdab.com>
Diffstat (limited to 'tests')
3 files changed, 20 insertions, 9 deletions
diff --git a/tests/auto/dbus/qdbusabstractinterface/interface.h b/tests/auto/dbus/qdbusabstractinterface/interface.h index 5db59b19eb..ecf732ce2d 100644 --- a/tests/auto/dbus/qdbusabstractinterface/interface.h +++ b/tests/auto/dbus/qdbusabstractinterface/interface.h @@ -43,6 +43,7 @@ #define INTERFACE_H #include <QtCore/QObject> +#include <QtCore/QHash> #include <QtDBus/QDBusArgument> struct RegisteredType @@ -103,7 +104,7 @@ public slots: Q_SCRIPTABLE void voidMethod() {} Q_SCRIPTABLE int sleepMethod(int); Q_SCRIPTABLE QString stringMethod() { return "Hello, world"; } - Q_SCRIPTABLE RegisteredType complexMethod() { return RegisteredType("Hello, world"); } + Q_SCRIPTABLE RegisteredType complexMethod(const QVariantHash &vars) { return RegisteredType(vars.value("arg1").toString()); } Q_SCRIPTABLE QString multiOutMethod(int &value) { value = 42; return "Hello, world"; } signals: diff --git a/tests/auto/dbus/qdbusabstractinterface/org.qtproject.QtDBus.Pinger.xml b/tests/auto/dbus/qdbusabstractinterface/org.qtproject.QtDBus.Pinger.xml index 845e7be5b4..d5f5c6cebd 100644 --- a/tests/auto/dbus/qdbusabstractinterface/org.qtproject.QtDBus.Pinger.xml +++ b/tests/auto/dbus/qdbusabstractinterface/org.qtproject.QtDBus.Pinger.xml @@ -23,6 +23,8 @@ <arg type="s" direction="out"/> </method> <method name="complexMethod"> + <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QHash<QString,QVariant>"/> + <arg type='a{sv}' name='platform_data' direction='in'/> <arg type="(s)" direction="out"/> <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="RegisteredType"/> </method> diff --git a/tests/auto/dbus/qdbusabstractinterface/tst_qdbusabstractinterface.cpp b/tests/auto/dbus/qdbusabstractinterface/tst_qdbusabstractinterface.cpp index dc4ed89c1e..54aa563d99 100644 --- a/tests/auto/dbus/qdbusabstractinterface/tst_qdbusabstractinterface.cpp +++ b/tests/auto/dbus/qdbusabstractinterface/tst_qdbusabstractinterface.cpp @@ -304,14 +304,22 @@ void tst_QDBusAbstractInterface::makeStringCall() QCOMPARE(r.value(), targetObj.stringMethod()); } +static QHash<QString, QVariant> complexMethodArgs() +{ + QHash<QString, QVariant> args; + args.insert("arg1", "Hello world"); + args.insert("arg2", 12345); + return args; +} + void tst_QDBusAbstractInterface::makeComplexCall() { Pinger p = getPinger(); QVERIFY2(p, "Not connected to D-Bus"); - QDBusReply<RegisteredType> r = p->complexMethod(); + QDBusReply<RegisteredType> r = p->complexMethod(complexMethodArgs()); QVERIFY(r.isValid()); - QCOMPARE(r.value(), targetObj.complexMethod()); + QCOMPARE(r.value(), targetObj.complexMethod(complexMethodArgs())); } void tst_QDBusAbstractInterface::makeMultiOutCall() @@ -352,9 +360,9 @@ void tst_QDBusAbstractInterface::makeComplexCallPeer() Pinger p = getPingerPeer(); QVERIFY2(p, "Not connected to D-Bus"); - QDBusReply<RegisteredType> r = p->complexMethod(); + QDBusReply<RegisteredType> r = p->complexMethod(complexMethodArgs()); QVERIFY(r.isValid()); - QCOMPARE(r.value(), targetObj.complexMethod()); + QCOMPARE(r.value(), targetObj.complexMethod(complexMethodArgs())); } void tst_QDBusAbstractInterface::makeMultiOutCallPeer() @@ -397,10 +405,10 @@ void tst_QDBusAbstractInterface::makeAsyncComplexCall() Pinger p = getPinger(); QVERIFY2(p, "Not connected to D-Bus"); - QDBusPendingReply<RegisteredType> r = p->complexMethod(); + QDBusPendingReply<RegisteredType> r = p->complexMethod(complexMethodArgs()); r.waitForFinished(); QVERIFY(r.isValid()); - QCOMPARE(r.value(), targetObj.complexMethod()); + QCOMPARE(r.value(), targetObj.complexMethod(complexMethodArgs())); } void tst_QDBusAbstractInterface::makeAsyncMultiOutCall() @@ -445,10 +453,10 @@ void tst_QDBusAbstractInterface::makeAsyncComplexCallPeer() Pinger p = getPingerPeer(); QVERIFY2(p, "Not connected to D-Bus"); - QDBusPendingReply<RegisteredType> r = p->complexMethod(); + QDBusPendingReply<RegisteredType> r = p->complexMethod(complexMethodArgs()); r.waitForFinished(); QVERIFY(r.isValid()); - QCOMPARE(r.value(), targetObj.complexMethod()); + QCOMPARE(r.value(), targetObj.complexMethod(complexMethodArgs())); } void tst_QDBusAbstractInterface::makeAsyncMultiOutCallPeer() |