summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qdbusabstractinterface/com.trolltech.QtDBus.Pinger.xml4
-rw-r--r--tests/auto/qdbusabstractinterface/interface.cpp14
-rw-r--r--tests/auto/qdbusabstractinterface/interface.h1
-rw-r--r--tests/auto/qdbusabstractinterface/pinger.h7
-rw-r--r--tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp92
5 files changed, 118 insertions, 0 deletions
diff --git a/tests/auto/qdbusabstractinterface/com.trolltech.QtDBus.Pinger.xml b/tests/auto/qdbusabstractinterface/com.trolltech.QtDBus.Pinger.xml
index 1667591..d945ec9 100644
--- a/tests/auto/qdbusabstractinterface/com.trolltech.QtDBus.Pinger.xml
+++ b/tests/auto/qdbusabstractinterface/com.trolltech.QtDBus.Pinger.xml
@@ -15,6 +15,10 @@
<annotation name="com.trolltech.QtDBus.QtTypeName.In0" value="RegisteredType"/>
</signal>
<method name="voidMethod" />
+ <method name="sleepMethod">
+ <arg type="i" />
+ <arg type="i" direction="out"/>
+ </method>
<method name="stringMethod">
<arg type="s" direction="out"/>
</method>
diff --git a/tests/auto/qdbusabstractinterface/interface.cpp b/tests/auto/qdbusabstractinterface/interface.cpp
index 0326177..849db93 100644
--- a/tests/auto/qdbusabstractinterface/interface.cpp
+++ b/tests/auto/qdbusabstractinterface/interface.cpp
@@ -40,9 +40,23 @@
****************************************************************************/
#include "interface.h"
+#include <QThread>
Interface::Interface()
{
}
+// Export the sleep function
+// TODO QT5: remove this class, QThread::msleep is now public
+class FriendlySleepyThread : public QThread {
+public:
+ using QThread::msleep;
+};
+
+int Interface::sleepMethod(int msec)
+{
+ FriendlySleepyThread::msleep(msec);
+ return 42;
+}
+
#include "moc_interface.cpp"
diff --git a/tests/auto/qdbusabstractinterface/interface.h b/tests/auto/qdbusabstractinterface/interface.h
index b840a38..0fb15fe 100644
--- a/tests/auto/qdbusabstractinterface/interface.h
+++ b/tests/auto/qdbusabstractinterface/interface.h
@@ -101,6 +101,7 @@ public:
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 QString multiOutMethod(int &value) { value = 42; return "Hello, world"; }
diff --git a/tests/auto/qdbusabstractinterface/pinger.h b/tests/auto/qdbusabstractinterface/pinger.h
index 6245a5a..739a142 100644
--- a/tests/auto/qdbusabstractinterface/pinger.h
+++ b/tests/auto/qdbusabstractinterface/pinger.h
@@ -117,6 +117,13 @@ public Q_SLOTS: // METHODS
return reply;
}
+ inline QDBusPendingReply<int> sleepMethod(int in0)
+ {
+ QList<QVariant> argumentList;
+ argumentList << qVariantFromValue(in0);
+ return asyncCallWithArgumentList(QLatin1String("sleepMethod"), argumentList);
+ }
+
inline QDBusPendingReply<QString> stringMethod()
{
QList<QVariant> argumentList;
diff --git a/tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp b/tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp
index 00e3a76..994df05 100644
--- a/tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp
+++ b/tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp
@@ -111,6 +111,8 @@ private slots:
void makeAsyncComplexCallPeer();
void makeAsyncMultiOutCallPeer();
+ void callWithTimeout();
+
void stringPropRead();
void stringPropWrite();
void variantPropRead();
@@ -458,6 +460,96 @@ void tst_QDBusAbstractInterface::makeAsyncMultiOutCallPeer()
QCoreApplication::instance()->processEvents();
}
+static const char server_serviceName[] = "com.trolltech.autotests.dbusserver";
+static const char server_objectPath[] = "/com/trolltech/server";
+static const char server_interfaceName[] = "com.trolltech.QtDBus.Pinger";
+
+class DBusServerThread : public QThread
+{
+public:
+ DBusServerThread() {
+ start();
+ m_ready.acquire();
+ }
+ ~DBusServerThread() {
+ quit();
+ wait();
+ }
+
+ void run()
+ {
+ QDBusConnection con = QDBusConnection::connectToBus(QDBusConnection::SessionBus, "ThreadConnection");
+ if (!con.isConnected())
+ qWarning("Error registering to DBus");
+ if (!con.registerService(server_serviceName))
+ qWarning("Error registering service name");
+ Interface targetObj;
+ con.registerObject(server_objectPath, &targetObj, QDBusConnection::ExportScriptableContents);
+ m_ready.release();
+ exec();
+
+ QDBusConnection::disconnectFromBus( con.name() );
+ }
+private:
+ QSemaphore m_ready;
+};
+
+void tst_QDBusAbstractInterface::callWithTimeout()
+{
+ QDBusConnection con = QDBusConnection::sessionBus();
+ QVERIFY2(con.isConnected(), "Not connected to D-Bus");
+
+ DBusServerThread serverThread;
+
+ QDBusMessage msg = QDBusMessage::createMethodCall(server_serviceName,
+ server_objectPath, server_interfaceName, "sleepMethod");
+ msg << 100;
+
+ {
+ // Call with no timeout -> works
+ QDBusMessage reply = con.call(msg);
+ QCOMPARE((int)reply.type(), (int)QDBusMessage::ReplyMessage);
+ QCOMPARE(reply.arguments().at(0).toInt(), 42);
+ }
+
+ {
+ // Call with 1 sec timeout -> fails
+ QDBusMessage reply = con.call(msg, QDBus::Block, 1);
+ QCOMPARE(reply.type(), QDBusMessage::ErrorMessage);
+ }
+
+ // Now using QDBusInterface
+
+ QDBusInterface iface(server_serviceName, server_objectPath, server_interfaceName, con);
+ {
+ // Call with no timeout
+ QDBusMessage reply = iface.call("sleepMethod", 100);
+ QCOMPARE(reply.type(), QDBusMessage::ReplyMessage);
+ QCOMPARE(reply.arguments().at(0).toInt(), 42);
+ }
+ {
+ // Call with 1 sec timeout -> fails
+ iface.setTimeout(1);
+ QDBusMessage reply = iface.call("sleepMethod", 100);
+ QCOMPARE(reply.type(), QDBusMessage::ErrorMessage);
+ }
+
+ // Now using generated code
+ com::trolltech::QtDBus::Pinger p(server_serviceName, server_objectPath, QDBusConnection::sessionBus());
+ {
+ // Call with no timeout
+ QDBusReply<int> reply = p.sleepMethod(100);
+ QVERIFY(reply.isValid());
+ QCOMPARE(int(reply), 42);
+ }
+ {
+ // Call with 1 sec timeout -> fails
+ p.setTimeout(1);
+ QDBusReply<int> reply = p.sleepMethod(100);
+ QVERIFY(!reply.isValid());
+ }
+}
+
void tst_QDBusAbstractInterface::stringPropRead()
{
Pinger p = getPinger();