[SCM] ktp-common-internals packaging branch, master, updated. debian/15.12.1-2-1839-gf0635e9
Maximiliano Curia
maxy at moszumanska.debian.org
Mon May 9 09:07:16 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=4bf685b
The following commit has been merged in the master branch:
commit 4bf685b3cd9d674df6554e2c6d1fd34245b21252
Author: George Goldberg <george.goldberg at collabora.co.uk>
Date: Tue Jan 4 18:57:57 2011 +0000
Account Test: sketch out tests for the new Account Test, and implement the init/shutdown test case.
---
kpeople/nepomuk-feeder/tests/CMakeLists.txt | 13 +-
kpeople/nepomuk-feeder/tests/account-test.cpp | 324 +++++++++++++++-----------
kpeople/nepomuk-feeder/tests/account-test.h | 48 ++--
3 files changed, 220 insertions(+), 165 deletions(-)
diff --git a/kpeople/nepomuk-feeder/tests/CMakeLists.txt b/kpeople/nepomuk-feeder/tests/CMakeLists.txt
index c9dedbc..2360c46 100644
--- a/kpeople/nepomuk-feeder/tests/CMakeLists.txt
+++ b/kpeople/nepomuk-feeder/tests/CMakeLists.txt
@@ -43,10 +43,11 @@ target_link_libraries(storage-test
nepomuktelepathyservice-static)
add_ktelepathy_nepomuk_test(StorageTest ${CMAKE_CURRENT_BINARY_DIR}/storage-test)
-
################################
-# Contact test
-#kde4_add_executable(contact-test contact-test.cpp)
-#target_link_libraries(contact-test tid-base-tests)
-#add_ktelepathy_dbus_test(ContactTest ${CMAKE_CURRENT_BINARY_DIR}/contact-test)
-
+# Account test
+kde4_add_executable(account-test account-test.cpp)
+target_link_libraries(account-test
+ ${KTELEPATHYTESTLIB_LIBRARIES}
+ ${QT_QTTEST_LIBRARY}
+ nepomuktelepathyservice-static)
+add_ktelepathy_dbus_test(AccountTest ${CMAKE_CURRENT_BINARY_DIR}/account-test)
diff --git a/kpeople/nepomuk-feeder/tests/account-test.cpp b/kpeople/nepomuk-feeder/tests/account-test.cpp
index 712932b..9a17747 100644
--- a/kpeople/nepomuk-feeder/tests/account-test.cpp
+++ b/kpeople/nepomuk-feeder/tests/account-test.cpp
@@ -1,8 +1,9 @@
/*
- * This file is part of nepomuktelepathyservice
+ * This file is part of telepathy-nepomuk-service
*
- * Copyright (C) 2009-2010 Collabora Ltd. <info at collabora.co.uk>
+ * Copyright (C) 2009-2011 Collabora Ltd. <info at collabora.co.uk>
* @author Dario Freddi <dario.freddi at collabora.co.uk>
+ * @author George Goldberg <george.goldberg at collabora.co.uk>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -21,171 +22,214 @@
#include "account-test.h"
-#include <KTempDir>
+#include "account.h"
-#include <Soprano/Backend>
-#include <Soprano/PluginManager>
-#include <Soprano/StorageModel>
-#include <Soprano/QueryResultIterator>
+#include <KDebug>
-#include <Nepomuk/ResourceManager>
-#include <Nepomuk/Thing>
-#include <Nepomuk/Variant>
+#include <qtest_kde.h>
-#include "ontologies/nco.h"
-#include "ontologies/dataobject.h"
-#include "ontologies/informationelement.h"
+#include <QtTest/QSignalSpy>
-#include <TelepathyQt4/ConnectionManager>
+#include <TelepathyQt4/PendingAccount>
+#include <TelepathyQt4/PendingOperation>
+#include <TelepathyQt4/PendingReady>
-#include <telepathyaccountmonitor.h>
-
-AccountTest::AccountTest(QObject* parent)
- : TidBaseTest(parent)
+AccountTest::AccountTest(QObject *parent)
+: Test(parent),
+ m_account(0)
{
-
+ kDebug();
}
+
AccountTest::~AccountTest()
{
-
+ kDebug();
}
void AccountTest::initTestCase()
{
initTestCaseImpl();
-}
-
-void AccountTest::testSetupAccountMonitor()
-{
- setupAccountMonitor();
-}
-
-void AccountTest::testAccountCreation()
-{
- createAccount();
-
- // Unfortunately there's no other way: let's wait until the account gets created
- QTimer::singleShot(500, mLoop, SLOT(quit()));
- mLoop->exec();
- // Let's wait for the nepomuk resource to become available
- QString query = QString("select distinct ?a where { %1 %2 ?a . ?a a %3 }")
- .arg(Soprano::Node::resourceToN3(mePersonContact().resourceUri()))
- .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::NCO::hasIMAccount()))
- .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::NCO::IMAccount()));
-
- Soprano::Model *model = Nepomuk::ResourceManager::instance()->mainModel();
-
- Soprano::QueryResultIterator it = model->executeQuery(query, Soprano::Query::QueryLanguageSparql);
-
- // Check that we got some results
- QVERIFY(it.next());
- Nepomuk::IMAccount foundImAccount(it.binding("a").uri());
- // Check for the validity of the resource
- QVERIFY(foundImAccount.isValid());
-
- // See if the Account has the same Telepathy Account Identifier
- QStringList accountIdentifiers = foundImAccount.accountIdentifiers();
- QCOMPARE(accountIdentifiers.size(), 1);
- QCOMPARE(accountIdentifiers.first(), account()->objectPath());
-
- // Check if the specified ID matches
- QCOMPARE(foundImAccount.imIDs().first(), QString("foobar"));
-
- // Check that we got _one_ result
- QVERIFY(!it.next());
-}
-
-void AccountTest::testChangeNickname()
-{
- // Change the nickname to "Hello KDE"
- Tp::PendingOperation *op = account()->setNickname("Hello KDE");
- connect(op, SIGNAL(finished(Tp::PendingOperation*)),
- this, SLOT(expectSuccessfulCall(Tp::PendingOperation*)));
+ // Set up the account manager.
+ Tp::Features fAccountFactory;
+ fAccountFactory << Tp::Account::FeatureCore
+ << Tp::Account::FeatureAvatar
+ << Tp::Account::FeatureCapabilities
+ << Tp::Account::FeatureProfile
+ << Tp::Account::FeatureProtocolInfo;
+
+ Tp::AccountFactoryConstPtr accountFactory = Tp::AccountFactory::create(
+ QDBusConnection::sessionBus(),
+ fAccountFactory);
+
+ m_accountManager = Tp::AccountManager::create(accountFactory);
+
+ // Get the Account Manager ready.
+ connect(m_accountManager->becomeReady(Tp::Features() << Tp::AccountManager::FeatureCore),
+ SIGNAL(finished(Tp::PendingOperation*)),
+ mLoop,
+ SLOT(quit()));
+ QCOMPARE(mLoop->exec(), 0);
+ QVERIFY(m_accountManager->isReady(Tp::Features() << Tp::AccountManager::FeatureCore));
+
+ // Create an account on the account manager
+ QVariantMap parameters;
+ parameters[QLatin1String("account")] = QLatin1String("baz");
+ Tp::PendingAccount *pacc = m_accountManager->createAccount(QLatin1String("foo"),
+ QLatin1String("bar"),
+ QLatin1String("foobar"),
+ parameters);
+ connect(pacc,
+ SIGNAL(finished(Tp::PendingOperation *)),
+ mLoop,
+ SLOT(quit()));
QCOMPARE(mLoop->exec(), 0);
- // Unfortunately there's no other way: let's wait until the account gets created
- QTimer::singleShot(500, mLoop, SLOT(quit()));
- mLoop->exec();
-
- // Let's wait for the nepomuk resource to become available
- QString query = QString("select distinct ?a where { %1 %2 ?a . ?a a %3 }")
- .arg(Soprano::Node::resourceToN3(mePersonContact().resourceUri()))
- .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::NCO::hasIMAccount()))
- .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::NCO::IMAccount()));
-
- Soprano::Model *model = Nepomuk::ResourceManager::instance()->mainModel();
-
- Soprano::QueryResultIterator it = model->executeQuery(query, Soprano::Query::QueryLanguageSparql);
-
- // Check that we got some results
- QVERIFY(it.next());
- Nepomuk::IMAccount foundImAccount(it.binding("a").uri());
- // Check for the validity of the resource
- QVERIFY(foundImAccount.isValid());
-
- // See if the Account has the same Telepathy Account Identifier
- QStringList accountIdentifiers = foundImAccount.accountIdentifiers();
- QCOMPARE(accountIdentifiers.size(), 1);
- QCOMPARE(accountIdentifiers.first(), account()->objectPath());
-
- // Check if the nickname matches the new one
- QCOMPARE(foundImAccount.imNicknames().first(), QString("Hello KDE"));
-
- // Check that we got _one_ result
- QVERIFY(!it.next());
+ // Get the account, and check it worked.
+ m_account = pacc->account();
+ QVERIFY(m_account->isReady(fAccountFactory));
}
-void AccountTest::testChangeAvatar()
+void AccountTest::testInitShutdown()
{
- Tp::Avatar avatar = { QByteArray("adadsdvds"), QLatin1String("image/jpeg") };
- QVERIFY(connect(account()->setAvatar(avatar),
- SIGNAL(finished(Tp::PendingOperation *)),
- SLOT(expectSuccessfulCall(Tp::PendingOperation *))));
+ m_accountObject = new Account(m_account, this);
+
+ // Set up spies for the signals we want to watch.
+ QSignalSpy spyCreated(m_accountObject,
+ SIGNAL(created(QString,QString,QString)));
+ QSignalSpy spyDestroyed(m_accountObject,
+ SIGNAL(accountDestroyed(QString)));
+ QSignalSpy spyNicknameChanged(m_accountObject,
+ SIGNAL(nicknameChanged(QString,QString)));
+ QSignalSpy spyCurrentPresenceChanged(m_accountObject,
+ SIGNAL(currentPresenceChanged(QString, Tp::SimplePresence)));
+
+ // Check the spies are empty at this point.
+ QCOMPARE(spyCreated.size(), 0);
+ QCOMPARE(spyDestroyed.size(), 0);
+ QCOMPARE(spyNicknameChanged.size(), 0);
+ QCOMPARE(spyCurrentPresenceChanged.size(), 0);
+
+ // Initialise the account.
+ m_accountObject->init();
+
+ // Now check the spies.
+ QCOMPARE(spyCreated.size(), 1);
+ QCOMPARE(spyDestroyed.size(), 0);
+ QCOMPARE(spyNicknameChanged.size(), 1);
+ QCOMPARE(spyCurrentPresenceChanged.size(), 1);
+
+ QCOMPARE(spyCreated.first().at(0).toString(), QLatin1String("/org/freedesktop/Telepathy/Account/foo/bar/Account0"));
+ QCOMPARE(spyCreated.first().at(1).toString(), QLatin1String("baz"));
+ QCOMPARE(spyCreated.first().at(2).toString(), QLatin1String("bar"));
+ QCOMPARE(spyNicknameChanged.first().at(0).toString(), QLatin1String("/org/freedesktop/Telepathy/Account/foo/bar/Account0"));
+ QCOMPARE(spyNicknameChanged.first().at(1).toString(), QLatin1String("Bob"));
+ Tp::SimplePresence p1;
+ p1.type = Tp::ConnectionPresenceTypeOffline;
+ p1.status = QLatin1String("offline");
+ QCOMPARE(spyCurrentPresenceChanged.first().at(0).toString(), QLatin1String("/org/freedesktop/Telepathy/Account/foo/bar/Account0"));
+ QCOMPARE(qVariantValue<Tp::SimplePresence>(spyCurrentPresenceChanged.first().at(1)), p1);
+
+ // Clear the spies for the next test.
+ spyCreated.clear();
+ spyDestroyed.clear();
+ spyNicknameChanged.clear();
+ spyCurrentPresenceChanged.clear();
+
+ // Now shutdown the account.
+ m_accountObject->shutdown();
+
+ // Check the spies.
+ QCOMPARE(spyCreated.size(), 0);
+ QCOMPARE(spyDestroyed.size(), 1);
+ QCOMPARE(spyNicknameChanged.size(), 0);
+ QCOMPARE(spyCurrentPresenceChanged.size(), 0);
+
+ QCOMPARE(spyDestroyed.first().at(0).toString(), QLatin1String("/org/freedesktop/Telepathy/Account/foo/bar/Account0"));
+
+ // Clear the spies for the next test
+ spyCreated.clear();
+ spyDestroyed.clear();
+ spyNicknameChanged.clear();
+ spyCurrentPresenceChanged.clear();
+
+ // Destroy the account.
+ connect(m_accountObject, SIGNAL(destroyed()), mLoop, SLOT(quit()));
+ m_accountObject->deleteLater();
QCOMPARE(mLoop->exec(), 0);
+ m_accountObject = 0;
- // Unfortunately there's no other way: let's wait until the account gets created
- QTimer::singleShot(500, mLoop, SLOT(quit()));
- mLoop->exec();
-
- // Let's wait for the nepomuk resource to become available
- QString query = QString("select distinct ?a where { %1 %2 ?a . ?a a %3 }")
- .arg(Soprano::Node::resourceToN3(mePersonContact().resourceUri()))
- .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::NCO::hasIMAccount()))
- .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::NCO::IMAccount()));
-
- Soprano::Model *model = Nepomuk::ResourceManager::instance()->mainModel();
-
- Soprano::QueryResultIterator it = model->executeQuery(query, Soprano::Query::QueryLanguageSparql);
-
- // Check that we got some results
- QVERIFY(it.next());
- Nepomuk::IMAccount foundImAccount(it.binding("a").uri());
- // Check for the validity of the resource
- QVERIFY(foundImAccount.isValid());
-
- // See if the Account has the same Telepathy Account Identifier
- QStringList accountIdentifiers = foundImAccount.accountIdentifiers();
- QCOMPARE(accountIdentifiers.size(), 1);
- QCOMPARE(accountIdentifiers.first(), account()->objectPath());
-
- // Check if the avatar matches the new one
- Nepomuk::Variant vphoto = foundImAccount.property(Nepomuk::Vocabulary::NCO::photo());
- QVERIFY(vphoto.isValid());
- Nepomuk::DataObject photo = vphoto.toResource();
-
- QCOMPARE(photo.interpretedAses().size(), 1);
- QByteArray imgdata = QByteArray::fromBase64(photo.interpretedAses().first().plainTextContents().first().toUtf8());
- QCOMPARE(QByteArray("adadsdvds"), imgdata);
-
- // Check that we got _one_ result
- QVERIFY(!it.next());
+ // Set the nickname and presence of the account to non-default values
+ connect(m_account->setNickname(QLatin1String("Ben")),
+ SIGNAL(finished(Tp::PendingOperation*)),
+ mLoop,
+ SLOT(quit()));
+ QCOMPARE(mLoop->exec(), 0);
+ QCOMPARE(m_account->nickname(), QLatin1String("Ben"));
+
+ Tp::SimplePresence p2;
+ p2.status = QLatin1String("available");
+ p2.statusMessage = QLatin1String("Test");
+ p2.type = Tp::ConnectionPresenceTypeAvailable;
+ connect(m_account.data(),
+ SIGNAL(currentPresenceChanged(Tp::Presence)),
+ mLoop,
+ SLOT(quit()));
+ m_account->setRequestedPresence(Tp::Presence(p2));
+ QCOMPARE(mLoop->exec(), 0);
+ QCOMPARE(m_account->currentPresence().barePresence(), p2);
+
+ // Recreate the accountobject
+ m_accountObject = new Account(m_account, this);
+
+ // Re-setup the spies
+ QSignalSpy spyCreated2(m_accountObject,
+ SIGNAL(created(QString,QString,QString)));
+ QSignalSpy spyDestroyed2(m_accountObject,
+ SIGNAL(accountDestroyed(QString)));
+ QSignalSpy spyNicknameChanged2(m_accountObject,
+ SIGNAL(nicknameChanged(QString,QString)));
+ QSignalSpy spyCurrentPresenceChanged2(m_accountObject,
+ SIGNAL(currentPresenceChanged(QString, Tp::SimplePresence)));
+
+ // Init the new accountObject
+ m_accountObject->init();
+
+ // Check the spies.
+ QCOMPARE(spyCreated2.size(), 1);
+ QCOMPARE(spyDestroyed2.size(), 0);
+ QCOMPARE(spyNicknameChanged2.size(), 1);
+ QCOMPARE(spyCurrentPresenceChanged2.size(), 1);
+
+ QCOMPARE(spyCreated2.first().at(0).toString(), QLatin1String("/org/freedesktop/Telepathy/Account/foo/bar/Account0"));
+ QCOMPARE(spyCreated2.first().at(1).toString(), QLatin1String("baz"));
+ QCOMPARE(spyCreated2.first().at(2).toString(), QLatin1String("bar"));
+ QCOMPARE(spyNicknameChanged2.first().at(0).toString(), QLatin1String("/org/freedesktop/Telepathy/Account/foo/bar/Account0"));
+ QCOMPARE(spyNicknameChanged2.first().at(1).toString(), QLatin1String("Ben"));
+ QCOMPARE(spyCurrentPresenceChanged2.first().at(0).toString(), QLatin1String("/org/freedesktop/Telepathy/Account/foo/bar/Account0"));
+ QCOMPARE(qVariantValue<Tp::SimplePresence>(spyCurrentPresenceChanged2.first().at(1)), p2);
}
void AccountTest::cleanupTestCase()
{
cleanupTestCaseImpl();
+
+ // Clear TP objects
+ m_account.reset();
+ m_accountManager.reset();
+
+ // Reset all per-testcase member vars
+ if (m_accountObject) {
+ connect(m_accountObject, SIGNAL(destroyed()), mLoop, SLOT(quit()));
+ m_accountObject->deleteLater();
+ mLoop->exec();
+ m_accountObject = 0;
+ }
}
-QTEST_MAIN(AccountTest)
+
+QTEST_KDEMAIN(AccountTest, GUI)
+
+
#include "account-test.moc"
+
diff --git a/kpeople/nepomuk-feeder/tests/account-test.h b/kpeople/nepomuk-feeder/tests/account-test.h
index d9a1349..06114a2 100644
--- a/kpeople/nepomuk-feeder/tests/account-test.h
+++ b/kpeople/nepomuk-feeder/tests/account-test.h
@@ -1,8 +1,9 @@
/*
- * This file is part of nepomuktelepathyservice
+ * This file is part of telepathy-nepomuk-service
*
- * Copyright (C) 2009-2010 Collabora Ltd. <info at collabora.co.uk>
+ * Copyright (C) 2009-2011 Collabora Ltd. <info at collabora.co.uk>
* @author Dario Freddi <dario.freddi at collabora.co.uk>
+ * @author George Goldberg <george.goldberg at collabora.co.uk>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -19,37 +20,46 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef ACCOUNT_TEST_H
-#define ACCOUNT_TEST_H
+#ifndef TELEPATHY_NEPOMUK_SERVICE_ACCOUNT_TEST_H
+#define TELEPATHY_NEPOMUK_SERVICE_ACCOUNT_TEST_H
-#include "tid-base-test.h"
+#include <KTelepathy/TestLib/Test>
-#include <TelepathyQt4/Types>
+#include <TelepathyQt4/Account>
+#include <TelepathyQt4/AccountManager>
-#include <Nepomuk/Resource>
+class Account;
-class TelepathyAccountMonitor;
-namespace Soprano {
-class StorageModel;
-}
-
-class KTempDir;
-class AccountTest : public TidBaseTest
+class AccountTest : public Test
{
Q_OBJECT
+
public:
AccountTest(QObject* parent = 0);
virtual ~AccountTest();
+public Q_SLOTS:
+
private Q_SLOTS:
void initTestCase();
- void testSetupAccountMonitor();
- void testAccountCreation();
- void testChangeNickname();
- void testChangeAvatar();
+ void testInitShutdown();
+ //void testOnConnectionStatusChanged();
+ //void testOnCurrentPresenceChanged();
+ //void testOnNicknameChanged();
+ //void testOnAllKnownContactsChanged();
+ //void testOnNewContact();
+ //void testOnContactDestroyed();
+ //void testSignalRelays();
void cleanupTestCase();
+
+private:
+ Tp::AccountManagerPtr m_accountManager;
+ Tp::AccountPtr m_account;
+ Account *m_accountObject;
};
-#endif // ACCOUNT_TEST_H
+
+#endif // Header Guard
+
--
ktp-common-internals packaging
More information about the pkg-kde-commits
mailing list