1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
#include <QtDBus>
#include <QtTest>
#include <TelepathyQt/PendingOperation>
#include <TelepathyQt/PendingVariant>
#include <TelepathyQt/Constants>
namespace Tp
{
class DBusProxy;
}
class Test : public QObject
{
Q_OBJECT
public:
Test(QObject *parent = 0);
virtual ~Test();
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();
virtual void initImpl();
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;
}
}
|