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>
bb10
David Faure 2013-05-04 15:13:47 +02:00 committed by The Qt Project
parent 1b2d3be446
commit 2116f9904a
3 changed files with 20 additions and 9 deletions

View File

@ -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:

View File

@ -23,6 +23,8 @@
<arg type="s" direction="out"/>
</method>
<method name="complexMethod">
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QHash&lt;QString,QVariant&gt;"/>
<arg type='a{sv}' name='platform_data' direction='in'/>
<arg type="(s)" direction="out"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="RegisteredType"/>
</method>

View File

@ -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()