31 #include <QTestEventLoop>
36 #include <QDBusAbstractAdaptor>
37 #include <QDBusMessage>
38 #include <QDBusConnection>
39 #include <QDBusPendingCallWatcher>
40 #include <QDBusInterface>
42 #define TEST_INTERFACE_NAME "org.qtproject.QtDBus.MyObject"
47 Q_CLASSINFO(
"D-Bus Interface",
"org.qtproject.QtDBus.MyObject")
60 msg.setDelayedReply(
true);
80 void waitForFinished();
81 void waitForFinished_error();
84 void watcher_waitForFinished();
85 void watcher_waitForFinished_threaded();
86 void watcher_waitForFinished_alreadyFinished();
87 void watcher_waitForFinished_alreadyFinished_eventLoop();
88 void watcher_waitForFinished_error();
89 void callInsideWaitForFinished();
91 void callWithCallback_localLoop();
92 void callWithCallback_localLoop_errorReply();
100 enum { CallbackCalled, ErrorCallbackCalled, FinishCalled, MakeCallCalled };
117 slotCalled = FinishCalled;
119 watchArgument = call;
126 slotCalled = CallbackCalled;
128 callbackArgument =
list;
134 slotCalled = ErrorCallbackCalled;
136 errorArgument =
error;
143 slotCalled = MakeCallCalled;
149 void tst_QDBusPendingCall::initTestCase()
159 "org.freedesktop.DBus",
168 "org.freedesktop.DBus",
169 "ThisNameWontExist");
173 void tst_QDBusPendingCall::waitForFinished()
192 void tst_QDBusPendingCall::waitForFinished_error()
205 void tst_QDBusPendingCall::callWithCallback_localLoop()
223 void tst_QDBusPendingCall::callWithCallback_localLoop_errorReply()
232 callbackArgument.clear();
238 if (errorArgument.
name() !=
"dbuspendingcall_error") {
244 QVERIFY(callbackArgument.isEmpty());
247 void tst_QDBusPendingCall::watcher()
264 QCOMPARE(slotCalled, (
int)FinishCalled);
273 void tst_QDBusPendingCall::watcher_error()
290 QCOMPARE(slotCalled, (
int)FinishCalled);
297 void tst_QDBusPendingCall::watcher_waitForFinished()
307 watch.waitForFinished();
313 QCOMPARE(slotCalled, (
int)FinishCalled);
322 void tst_QDBusPendingCall::watcher_waitForFinished_threaded()
351 watch.waitForFinished();
356 QCOMPARE(tst->slotCalled, (
int)FinishCalled);
372 void tst_QDBusPendingCall::watcher_waitForFinished_alreadyFinished()
387 watch.waitForFinished();
393 QCOMPARE(slotCalled, (
int)FinishCalled);
402 void tst_QDBusPendingCall::watcher_waitForFinished_alreadyFinished_eventLoop()
426 QCOMPARE(slotCalled, (
int)FinishCalled);
435 void tst_QDBusPendingCall::watcher_waitForFinished_error()
445 watch.waitForFinished();
451 QCOMPARE(slotCalled, (
int)FinishCalled);
458 void tst_QDBusPendingCall::callInsideWaitForFinished()
468 watch.waitForFinished();
471 QCOMPARE(slotCalled, (
int)MakeCallCalled);
480 #include "tst_qdbuspendingcall.moc"
MyObject(QObject *parent=0)
void returnError(const QDBusMessage &msg) const
QStringList returnFoo() const
The QDBusAbstractAdaptor class is the base class of D-Bus adaptor classes.
The QDBusConnection class represents a connection to the D-Bus bus daemon.
bool send(const QDBusMessage &message) const
static QDBusConnection sessionBus()
QString baseService() const
QDBusPendingCall asyncCall(const QDBusMessage &message, int timeout=-1) const
bool registerObject(const QString &path, QObject *object, RegisterOptions options=ExportAdaptors)
The QDBusError class represents an error received from the D-Bus bus or from remote applications foun...
The QDBusInterface class is a proxy for interfaces on remote objects.
The QDBusMessage class represents one message sent or received over the D-Bus bus.
QList< QVariant > arguments() const
static QDBusMessage createMethodCall(const QString &destination, const QString &path, const QString &interface, const QString &method)
The QDBusPendingCall class refers to one pending asynchronous call.
QDBusMessage reply() const
The QDBusPendingCallWatcher class provides a convenient way for waiting for asynchronous replies.
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
bool isEmpty() const noexcept
const_reference at(qsizetype i) const noexcept
The QObject class is the base class of all Qt objects.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
The QString class provides a Unicode character string.
static QString fromLatin1(QByteArrayView ba)
The QStringList class provides a list of strings.
static QTestEventLoop & instance()
void start(Priority=InheritPriority)
static QThread * currentThread()
bool wait(QDeadlineTimer deadline=QDeadlineTimer(QDeadlineTimer::Forever))
The QVariant class acts like a union for the most common Qt data types.
QStringList toStringList() const
void errorCallback(const QDBusError &error)
void finished(QDBusPendingCallWatcher *call)
void callback(const QStringList &list)
Q_CORE_EXPORT void qSleep(int ms)
QList< QString > QStringList
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch * watch
GLbitfield GLuint64 timeout
[4]
#define QTEST_MAIN(TestObject)
#define QVERIFY(statement)
bool run(const QString &name, QString *errorMessage)
#define TEST_INTERFACE_NAME