[Telepathy-commits] [telepathy-qt4/master] Added tests for account creation.
Andre Moreira Magalhaes (andrunko)
andre.magalhaes at collabora.co.uk
Fri Jan 9 12:46:28 PST 2009
---
tests/dbus/account-basics.cpp | 89 +++++++++++++++++++++++++++++++++++------
1 files changed, 76 insertions(+), 13 deletions(-)
diff --git a/tests/dbus/account-basics.cpp b/tests/dbus/account-basics.cpp
index 420a884..060bafd 100644
--- a/tests/dbus/account-basics.cpp
+++ b/tests/dbus/account-basics.cpp
@@ -1,14 +1,26 @@
#include <QtCore/QEventLoop>
#include <QtTest/QtTest>
+#include <QtDBus/QDBusObjectPath>
#include <TelepathyQt4/Debug>
#include <TelepathyQt4/Types>
+#include <TelepathyQt4/Client/Account>
#include <TelepathyQt4/Client/AccountManager>
+#include <TelepathyQt4/Client/PendingAccount>
#include <TelepathyQt4/Client/PendingOperation>
using namespace Telepathy;
using namespace Telepathy::Client;
+static QStringList objectPathListToStringList(const ObjectPathList &paths)
+{
+ QStringList result;
+ Q_FOREACH (const QDBusObjectPath &path, paths) {
+ result << path.path();
+ }
+ return result;
+}
+
class TestAccountBasics : public QObject
{
Q_OBJECT
@@ -19,6 +31,8 @@ public:
protected Q_SLOTS:
void expectSuccessfulCall(Telepathy::Client::PendingOperation *);
+ void onAccountCreated(Telepathy::Client::PendingOperation *);
+ void onAccountReady(Telepathy::Client::PendingOperation *);
private Q_SLOTS:
void init();
@@ -29,13 +43,13 @@ private Q_SLOTS:
private:
QEventLoop *mLoop;
- AccountManager *mAccount;
+ AccountManager *mAM;
};
TestAccountBasics::TestAccountBasics(QObject *parent)
: QObject(parent),
mLoop(new QEventLoop(this)),
- mAccount(0)
+ mAM(0)
{
}
@@ -56,6 +70,30 @@ void TestAccountBasics::expectSuccessfulCall(PendingOperation *operation)
mLoop->exit(0);
}
+void TestAccountBasics::onAccountCreated(Telepathy::Client::PendingOperation *operation)
+{
+ if (operation->isError()) {
+ qWarning().nospace() << operation->errorName()
+ << ": " << operation->errorMessage();
+ mLoop->exit(1);
+ return;
+ }
+
+ mLoop->exit(0);
+}
+
+void TestAccountBasics::onAccountReady(Telepathy::Client::PendingOperation *operation)
+{
+ if (operation->isError()) {
+ qWarning().nospace() << operation->errorName()
+ << ": " << operation->errorMessage();
+ mLoop->exit(1);
+ return;
+ }
+
+ mLoop->exit(0);
+}
+
void TestAccountBasics::init()
{
Telepathy::registerTypes();
@@ -65,29 +103,54 @@ void TestAccountBasics::init()
void TestAccountBasics::testBasics()
{
- mAccount = new AccountManager();
- QCOMPARE(mAccount->isReady(), false);
+ mAM = new AccountManager();
+ QCOMPARE(mAM->isReady(), false);
- connect(mAccount->becomeReady(),
+ connect(mAM->becomeReady(),
SIGNAL(finished(Telepathy::Client::PendingOperation *)),
this,
SLOT(expectSuccessfulCall(Telepathy::Client::PendingOperation *)));
qDebug() << "enter main loop";
QCOMPARE(mLoop->exec(), 0);
- QCOMPARE(mAccount->isReady(), true);
+ QCOMPARE(mAM->isReady(), true);
- QCOMPARE(mAccount->interfaces(), QStringList());
+ QVariantMap parameters;
+ parameters["account"] = "foobar";
+ PendingAccount *pacc = mAM->createAccount("foo",
+ "bar", "foobar", parameters);
+ connect(pacc,
+ SIGNAL(finished(Telepathy::Client::PendingOperation *)),
+ this,
+ SLOT(onAccountCreated(Telepathy::Client::PendingOperation *)));
+ QCOMPARE(mLoop->exec(), 0);
+
+ QCOMPARE(mAM->interfaces(), QStringList());
+
+ QCOMPARE(objectPathListToStringList(mAM->validAccountPaths()),
+ QStringList() <<
+ "/org/freedesktop/Telepathy/Account/foo/bar/Account0");
+ QCOMPARE(objectPathListToStringList(mAM->invalidAccountPaths()),
+ QStringList());
+ QCOMPARE(objectPathListToStringList(mAM->allAccountPaths()),
+ QStringList() <<
+ "/org/freedesktop/Telepathy/Account/foo/bar/Account0");
+
+ Account *acc = mAM->accountForPath(
+ QDBusObjectPath("/org/freedesktop/Telepathy/Account/foo/bar/Account0"));
+ connect(acc->becomeReady(),
+ SIGNAL(finished(Telepathy::Client::PendingOperation *)),
+ this,
+ SLOT(onAccountReady(Telepathy::Client::PendingOperation *)));
+ QCOMPARE(mLoop->exec(), 0);
- QCOMPARE(mAccount->validAccountPaths(), ObjectPathList());
- QCOMPARE(mAccount->invalidAccountPaths(), ObjectPathList());
- QCOMPARE(mAccount->allAccountPaths(), ObjectPathList());
+ QCOMPARE(acc->displayName(), QString("foobar (account 0)"));
}
void TestAccountBasics::cleanup()
{
- if (mAccount) {
- delete mAccount;
- mAccount = 0;
+ if (mAM) {
+ delete mAM;
+ mAM = 0;
}
}
--
1.5.6.5
More information about the Telepathy-commits
mailing list