[Telepathy-commits] [telepathy-qt4/master] PinocchioTest: add more test preparation stuff
Simon McVittie
simon.mcvittie at collabora.co.uk
Thu Nov 27 09:38:38 PST 2008
---
tests/pinocchio/lib.cpp | 76 +++++++++++++++++++++++++++++++++++++++++++++++
tests/pinocchio/lib.h | 22 +++++++++++++-
2 files changed, 97 insertions(+), 1 deletions(-)
diff --git a/tests/pinocchio/lib.cpp b/tests/pinocchio/lib.cpp
index 1a0f5b2..d2873f6 100644
--- a/tests/pinocchio/lib.cpp
+++ b/tests/pinocchio/lib.cpp
@@ -2,8 +2,25 @@
#include <cstdlib>
+#include <QtCore/QTimer>
+
+#include <TelepathyQt4/Types>
+#include <TelepathyQt4/Debug>
+#include <TelepathyQt4/Client/DBus>
+
+using namespace Telepathy::Client::DBus;
+
+PinocchioTest::~PinocchioTest()
+{
+ delete mLoop;
+}
+
void PinocchioTest::initTestCaseImpl()
{
+ Telepathy::registerTypes();
+ Telepathy::enableDebug(true);
+ Telepathy::enableWarnings(true);
+
mPinocchioPath = QString::fromLocal8Bit(::getenv("PINOCCHIO"));
mPinocchioCtlPath = QString::fromLocal8Bit(::getenv("PINOCCHIO_CTL"));
@@ -32,6 +49,65 @@ void PinocchioTest::cleanupImpl()
}
+void PinocchioTest::gotNameOwner(QDBusPendingCallWatcher* watcher)
+{
+ QDBusPendingReply<QString> reply = *watcher;
+
+ if (reply.isError()) {
+ return;
+ }
+
+ if (reply.value() != "") {
+ // it has an owner now
+ mLoop->exit(1);
+ }
+}
+
+
+void PinocchioTest::onNameOwnerChanged(const QString& name,
+ const QString& old, const QString& owner)
+{
+ if (name != pinocchioBusName()) {
+ return;
+ }
+
+ if (owner != "") {
+ // it has an owner now
+ mLoop->exit(1);
+ }
+}
+
+
+bool PinocchioTest::waitForPinocchio(uint timeoutMs)
+{
+ QTimer timer;
+
+ connect(&timer, SIGNAL(timeout()), mLoop, SLOT(quit()));
+ timer.setSingleShot(true);
+ timer.start(timeoutMs);
+ QTimer::singleShot(timeoutMs, mLoop, SLOT(quit()));
+
+ DBusDaemonInterface busDaemon("org.freedesktop.DBus", "/org/freedesktop/DBus");
+ connect(&busDaemon,
+ SIGNAL(NameOwnerChanged(const QString&, const QString&, const QString&)),
+ this,
+ SLOT(onNameOwnerChanged(const QString&, const QString&, const QString&)));
+ QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(
+ busDaemon.GetNameOwner(pinocchioBusName()));
+ connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
+ this, SLOT(gotNameOwner(QDBusPendingCallWatcher*)));
+
+ bool ret = (mLoop->exec() == 1);
+
+ timer.stop();
+
+ // signals will automatically be disconnected as timer and busDaemon
+ // go out of scope
+
+ return ret;
+}
+
+
void PinocchioTest::cleanupTestCaseImpl()
{
qDebug() << "Terminating Pinocchio";
diff --git a/tests/pinocchio/lib.h b/tests/pinocchio/lib.h
index 77b7219..1889bc0 100644
--- a/tests/pinocchio/lib.h
+++ b/tests/pinocchio/lib.h
@@ -9,20 +9,40 @@ class PinocchioTest : public QObject
Q_OBJECT
public:
+
PinocchioTest(QObject *parent = 0)
: QObject(parent), mLoop(new QEventLoop(this))
{ }
+ virtual ~PinocchioTest();
+
+ static inline QLatin1String pinocchioBusName()
+ {
+ return QLatin1String(
+ "org.freedesktop.Telepathy.ConnectionManager.pinocchio");
+ }
+
+ static inline QLatin1String pinocchioObjectPath()
+ {
+ return QLatin1String(
+ "/org/freedesktop/Telepathy/ConnectionManager/pinocchio");
+ }
+
+ bool waitForPinocchio(uint timeoutMs = 5000);
+
protected:
QString mPinocchioPath;
QString mPinocchioCtlPath;
QProcess mPinocchio;
QEventLoop *mLoop;
-protected slots:
+protected Q_SLOTS:
virtual void initTestCaseImpl();
virtual void initImpl();
virtual void cleanupImpl();
virtual void cleanupTestCaseImpl();
+
+ void gotNameOwner(QDBusPendingCallWatcher* watcher);
+ void onNameOwnerChanged(const QString&, const QString&, const QString&);
};
--
1.5.6.5
More information about the Telepathy-commits
mailing list