summaryrefslogtreecommitdiffstats
path: root/tests/auto/qdbusinterface
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qdbusinterface')
-rw-r--r--tests/auto/qdbusinterface/tst_qdbusinterface.cpp202
1 files changed, 195 insertions, 7 deletions
diff --git a/tests/auto/qdbusinterface/tst_qdbusinterface.cpp b/tests/auto/qdbusinterface/tst_qdbusinterface.cpp
index 587a910..2e8e646 100644
--- a/tests/auto/qdbusinterface/tst_qdbusinterface.cpp
+++ b/tests/auto/qdbusinterface/tst_qdbusinterface.cpp
@@ -1,7 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2009 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.
@@ -21,9 +20,10 @@
** 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.
+** 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.
@@ -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"