summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--qt4/tests/lib/test.cpp14
-rw-r--r--qt4/tests/lib/test.h25
2 files changed, 39 insertions, 0 deletions
diff --git a/qt4/tests/lib/test.cpp b/qt4/tests/lib/test.cpp
index ca2ed88db..f6032a81e 100644
--- a/qt4/tests/lib/test.cpp
+++ b/qt4/tests/lib/test.cpp
@@ -80,6 +80,20 @@ void Test::expectFailure(PendingOperation *op)
mLoop->exit(0);
}
+void Test::expectSuccessfulProperty(PendingOperation *op)
+{
+ if (op->isError()) {
+ qWarning().nospace() << op->errorName()
+ << ": " << op->errorMessage();
+ mPropertyValue = QVariant();
+ mLoop->exit(1);
+ } else {
+ Tp::PendingVariant *pv = qobject_cast<Tp::PendingVariant*>(op);
+ mPropertyValue = pv->result();
+ mLoop->exit(0);
+ }
+}
+
void Test::processDBusQueue(Tp::DBusProxy *proxy)
{
// Call method Ping on the D-Bus Peer interface
diff --git a/qt4/tests/lib/test.h b/qt4/tests/lib/test.h
index 736213e72..77b3d34e8 100644
--- a/qt4/tests/lib/test.h
+++ b/qt4/tests/lib/test.h
@@ -3,6 +3,7 @@
#include <QtTest>
#include <TelepathyQt4/PendingOperation>
+#include <TelepathyQt4/PendingVariant>
#include <TelepathyQt4/Constants>
namespace Tp
@@ -23,10 +24,14 @@ public:
QEventLoop *mLoop;
void processDBusQueue(Tp::DBusProxy *proxy);
+protected:
+ template<typename T> bool waitForProperty(Tp::PendingVariant *pv, T *value);
+
protected Q_SLOTS:
void expectSuccessfulCall(QDBusPendingCallWatcher*);
void expectSuccessfulCall(Tp::PendingOperation*);
void expectFailure(Tp::PendingOperation*);
+ void expectSuccessfulProperty(Tp::PendingOperation *op);
void onWatchdog();
virtual void initTestCaseImpl();
@@ -34,4 +39,24 @@ protected Q_SLOTS:
virtual void cleanupImpl();
virtual void cleanupTestCaseImpl();
+
+private:
+ // The property retrieved by expectSuccessfulProperty()
+ QVariant mPropertyValue;
};
+
+template<typename T>
+bool Test::waitForProperty(Tp::PendingVariant *pv, T *value)
+{
+ connect(pv,
+ SIGNAL(finished(Tp::PendingOperation*)),
+ SLOT(expectSuccessfulProperty(Tp::PendingOperation*)));
+ if (mLoop->exec() == 0) {
+ *value = qdbus_cast<T>(mPropertyValue);
+ return true;
+ }
+ else {
+ *value = T();
+ return false;
+ }
+}