diff --git a/tests/libkopete/CMakeLists.txt b/tests/libkopete/CMakeLists.txt index 924beec63..63a27b8ca 100755 --- a/tests/libkopete/CMakeLists.txt +++ b/tests/libkopete/CMakeLists.txt @@ -1,22 +1,21 @@ include_directories( ${KOPETE_INCLUDES} ${CMAKE_SOURCE_DIR}/libkopete ) set(BLACKLIST_LIB kopeteblacklistertest.cpp ${CMAKE_SOURCE_DIR}/libkopete/kopeteblacklister.cpp ) set( KOPETE_TEST_LIBRARIES kopete Qt5::Test KF5::KIOCore ) ecm_add_test(kopetetasktest.cpp LINK_LIBRARIES ${KOPETE_TEST_LIBRARIES}) ecm_add_test(kopetestatusmessagetest.cpp LINK_LIBRARIES ${KOPETE_TEST_LIBRARIES}) ecm_add_test(${BLACKLIST_LIB} TEST_NAME blacklisttest LINK_LIBRARIES ${KOPETE_TEST_LIBRARIES}) ecm_add_test(kopetecontactlistelementtest.cpp LINK_LIBRARIES ${KOPETE_TEST_LIBRARIES}) ecm_add_test(kopeteglobaltest.cpp LINK_LIBRARIES ${KOPETE_TEST_LIBRARIES}) - - +ecm_add_test(kopeteidentitytest.cpp LINK_LIBRARIES ${KOPETE_TEST_LIBRARIES}) diff --git a/tests/libkopete/kopeteglobaltest.cpp b/tests/libkopete/kopeteglobaltest.cpp index 308babcd0..26412f7d6 100644 --- a/tests/libkopete/kopeteglobaltest.cpp +++ b/tests/libkopete/kopeteglobaltest.cpp @@ -1,192 +1,109 @@ /* Tests for Kopete::Global::Properties Copyright (c) 2017 by Vijay Krishnavanshi Kopete (c) 2002-2017 by the Kopete developers ************************************************************************* * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ************************************************************************* */ #include "kopeteglobal.h" #include "kopeteproperty.h" #include #include - +Q_DECLARE_METATYPE(Kopete::PropertyTmpl::PropertyOption); class GlobalPropertiesTest : public QObject { Q_OBJECT private slots: void testDefaultProperties(); void testCustomProperties(); + void testDefaultProperties_data(); }; -void GlobalPropertiesTest::testDefaultProperties() +void GlobalPropertiesTest::testDefaultProperties_data() { - Kopete::Global::Properties *A = Kopete::Global::Properties::self(); - - const QString fromattedName = QStringLiteral("FormattedName"); - QVERIFY(A->isRegistered(fromattedName)); - Kopete::PropertyTmpl temp = A->tmpl(fromattedName); - QCOMPARE(temp.key(), fromattedName); - QCOMPARE(temp.label(), QStringLiteral("Full Name")); - QCOMPARE(temp.icon(), QStringLiteral()); - QCOMPARE(temp.options(), Kopete::PropertyTmpl::NoProperty); - - const QString idleTime = QStringLiteral("idleTime"); - QVERIFY(A->isRegistered(idleTime)); - temp = A->tmpl(idleTime); - QCOMPARE(temp.key(), idleTime); - QCOMPARE(temp.label(), QStringLiteral("Idle Time")); - QCOMPARE(temp.icon(), QStringLiteral()); - QCOMPARE(temp.options(), Kopete::PropertyTmpl::NoProperty); - - const QString onlineSince = QStringLiteral("onlineSince"); - QVERIFY(A->isRegistered(onlineSince)); - temp = A->tmpl(onlineSince); - QCOMPARE(temp.key(), onlineSince); - QCOMPARE(temp.label(), QStringLiteral("Online Since")); - QCOMPARE(temp.icon(), QStringLiteral()); - QCOMPARE(temp.options(), Kopete::PropertyTmpl::NoProperty); - - const QString lastSeen = QStringLiteral("lastSeen"); - QVERIFY(A->isRegistered(lastSeen)); - temp = A->tmpl(lastSeen); - QCOMPARE(temp.key(), lastSeen); - QCOMPARE(temp.label(), QStringLiteral("Last Seen")); - QCOMPARE(temp.icon(), QStringLiteral()); - QCOMPARE(temp.options(), Kopete::PropertyTmpl::PersistentProperty); - - const QString statusMessage = QStringLiteral("statusMessage"); - QVERIFY(A->isRegistered(statusMessage)); - temp = A->tmpl(statusMessage); - QCOMPARE(temp.key(), statusMessage); - QCOMPARE(temp.label(), QStringLiteral("Status Message")); - QCOMPARE(temp.icon(), QStringLiteral()); - QCOMPARE(temp.options(), Kopete::PropertyTmpl::NoProperty); - - const QString firstName = QStringLiteral("firstName"); - QVERIFY(A->isRegistered(firstName)); - temp = A->tmpl(firstName); - QCOMPARE(temp.key(), firstName); - QCOMPARE(temp.label(), QStringLiteral("First Name")); - QCOMPARE(temp.icon(), QStringLiteral()); - QCOMPARE(temp.options(), Kopete::PropertyTmpl::PersistentProperty); - - const QString lastName = QStringLiteral("lastName"); - QVERIFY(A->isRegistered(lastName)); - temp = A->tmpl(lastName); - QCOMPARE(temp.key(), lastName); - QCOMPARE(temp.label(), QStringLiteral("Last Name")); - QCOMPARE(temp.icon(), QStringLiteral()); - QCOMPARE(temp.options(), Kopete::PropertyTmpl::PersistentProperty); + QTest::addColumn("PropertyName"); + QTest::addColumn("Key"); + QTest::addColumn("Label"); + QTest::addColumn("Icon"); + QTest::addColumn("Option"); + QTest::newRow("Test Fromatted Name") << QStringLiteral("FormattedName") << QStringLiteral("FormattedName") << QStringLiteral("Full Name") << QString() << Kopete::PropertyTmpl::NoProperty; + QTest::newRow("Test Idle Time") << QStringLiteral("idleTime") << QStringLiteral("idleTime") << QStringLiteral("Idle Time") << QString() << Kopete::PropertyTmpl::NoProperty; + QTest::newRow("Test Online Since") << QStringLiteral("onlineSince") << QStringLiteral("onlineSince") << QStringLiteral("Online Since") << QString() << Kopete::PropertyTmpl::NoProperty; + QTest::newRow("Test Last Seen") << QStringLiteral("lastSeen") << QStringLiteral("lastSeen") << QStringLiteral("Last Seen") << QString() << Kopete::PropertyTmpl::PersistentProperty; + QTest::newRow("Test Status Message") << QStringLiteral("statusMessage") << QStringLiteral("statusMessage") << QStringLiteral("Status Message") << QString() << Kopete::PropertyTmpl::NoProperty; + QTest::newRow("Test First Name") << QStringLiteral("firstName") << QStringLiteral("firstName") << QStringLiteral("First Name") << QString() << Kopete::PropertyTmpl::PersistentProperty; + QTest::newRow("Test Last Name") << QStringLiteral("lastName") << QStringLiteral("lastName") << QStringLiteral("Last Name") << QString() << Kopete::PropertyTmpl::PersistentProperty; + QTest::newRow("Test Private Phone") << QStringLiteral("privatePhoneNumber") << QStringLiteral("privatePhoneNumber") << QStringLiteral("Private Phone") << QString() << Kopete::PropertyTmpl::PersistentProperty; + QTest::newRow("Test Private Mobile Phone") << QStringLiteral("privateMobilePhoneNumber") << QStringLiteral("privateMobilePhoneNumber") << QStringLiteral("Private Mobile Phone") << QString() << Kopete::PropertyTmpl::PersistentProperty; + QTest::newRow("Test Work Phone") << QStringLiteral("workPhoneNumber") << QStringLiteral("workPhoneNumber") << QStringLiteral("Work Phone") << QString() << Kopete::PropertyTmpl::PersistentProperty; + QTest::newRow("Test Work Mobile Phone") << QStringLiteral("workMobilePhoneNumber") << QStringLiteral("workMobilePhoneNumber") << QStringLiteral("Work Mobile Phone") << QString() << Kopete::PropertyTmpl::PersistentProperty; + QTest::newRow("Test Email Address") << QStringLiteral("emailAddress") << QStringLiteral("emailAddress") << QStringLiteral("Email Address") << QStringLiteral("mail") << Kopete::PropertyTmpl::PersistentProperty; + QTest::newRow("Test Nick Name") << QStringLiteral("nickName") << QStringLiteral("nickName") << QStringLiteral("Nick Name") << QString() << Kopete::PropertyTmpl::PersistentProperty; + QTest::newRow("Test Custom Name") << QStringLiteral("customName") << QStringLiteral("customName") << QStringLiteral("Custom Name") << QString() << Kopete::PropertyTmpl::PersistentProperty; + QTest::newRow("Test Photo") << QStringLiteral("photo") << QStringLiteral("photo") << QStringLiteral("Photo") << QString() << Kopete::PropertyTmpl::PersistentProperty; +} - const QString privatePhoneNumber = QStringLiteral("privatePhoneNumber"); - QVERIFY(A->isRegistered(privatePhoneNumber)); - temp = A->tmpl(privatePhoneNumber); - QCOMPARE(temp.key(), privatePhoneNumber); - QCOMPARE(temp.label(), QStringLiteral("Private Phone")); - QCOMPARE(temp.icon(), QStringLiteral()); - QCOMPARE(temp.options(), Kopete::PropertyTmpl::PersistentProperty); +void GlobalPropertiesTest::testDefaultProperties() +{ + Kopete::Global::Properties *dummy = Kopete::Global::Properties::self(); - const QString privateMobilePhoneNumber = QStringLiteral("privateMobilePhoneNumber"); - QVERIFY(A->isRegistered(privateMobilePhoneNumber)); - temp = A->tmpl(privateMobilePhoneNumber); - QCOMPARE(temp.key(), privateMobilePhoneNumber); - QCOMPARE(temp.label(), QStringLiteral("Private Mobile Phone")); - QCOMPARE(temp.icon(), QStringLiteral()); - QCOMPARE(temp.options(), Kopete::PropertyTmpl::PersistentProperty); - - const QString workPhoneNumber = QStringLiteral("workPhoneNumber"); - QVERIFY(A->isRegistered(workPhoneNumber)); - temp = A->tmpl(workPhoneNumber); - QCOMPARE(temp.key(), workPhoneNumber); - QCOMPARE(temp.label(), QStringLiteral("Work Phone")); - QCOMPARE(temp.icon(), QStringLiteral()); - QCOMPARE(temp.options(), Kopete::PropertyTmpl::PersistentProperty); - - const QString workMobilePhoneNumber = QStringLiteral("workMobilePhoneNumber"); - QVERIFY(A->isRegistered(workMobilePhoneNumber)); - temp = A->tmpl(workMobilePhoneNumber); - QCOMPARE(temp.key(), workMobilePhoneNumber); - QCOMPARE(temp.label(), QStringLiteral("Work Mobile Phone")); - QCOMPARE(temp.icon(), QStringLiteral()); - QCOMPARE(temp.options(), Kopete::PropertyTmpl::PersistentProperty); - - const QString emailAddress = QStringLiteral("emailAddress"); - QVERIFY(A->isRegistered(emailAddress)); - temp = A->tmpl(emailAddress); - QCOMPARE(temp.key(), emailAddress); - QCOMPARE(temp.label(), QStringLiteral("Email Address")); - QCOMPARE(temp.icon(), QStringLiteral("mail")); - QCOMPARE(temp.options(), Kopete::PropertyTmpl::PersistentProperty); - - const QString nickName = QStringLiteral("nickName"); - QVERIFY(A->isRegistered(nickName)); - temp = A->tmpl(nickName); - QCOMPARE(temp.key(), nickName); - QCOMPARE(temp.label(), QStringLiteral("Nick Name")); - QCOMPARE(temp.icon(), QStringLiteral()); - QCOMPARE(temp.options(), Kopete::PropertyTmpl::PersistentProperty); - - const QString customName = QStringLiteral("customName"); - QVERIFY(A->isRegistered(customName)); - temp = A->tmpl(customName); - QCOMPARE(temp.key(), customName); - QCOMPARE(temp.label(), QStringLiteral("Custom Name")); - QCOMPARE(temp.icon(), QStringLiteral()); - QCOMPARE(temp.options(), Kopete::PropertyTmpl::PersistentProperty); - - const QString photo QStringLiteral("photo"); - QVERIFY(A->isRegistered(photo)); - temp = A->tmpl(photo); - QCOMPARE(temp.key(), photo); - QCOMPARE(temp.label(), QStringLiteral("Photo")); - QCOMPARE(temp.icon(), QStringLiteral()); - QCOMPARE(temp.options(), Kopete::PropertyTmpl::PersistentProperty); + QFETCH(QString, PropertyName); + QFETCH(QString, Key); + QFETCH(QString, Label); + QFETCH(QString, Icon); + QFETCH(Kopete::PropertyTmpl::PropertyOption, Option); + QVERIFY(dummy->isRegistered(PropertyName)); + Kopete::PropertyTmpl temp = dummy->tmpl(PropertyName); + QCOMPARE(temp.key(), Key); + QCOMPARE(temp.label(), Label); + QCOMPARE(temp.icon(), Icon); + QCOMPARE(temp.options(), Option); } void GlobalPropertiesTest::testCustomProperties() { Kopete::Global::Properties *A = Kopete::Global::Properties::self(); A->isAlwaysVisible(); const QString isAlwaysVisible = QStringLiteral("isAlwaysVisible"); QVERIFY(A->isRegistered(isAlwaysVisible)); Kopete::PropertyTmpl temp = A->tmpl(isAlwaysVisible); QCOMPARE(temp.key(), isAlwaysVisible); QCOMPARE(temp.label(), QStringLiteral("Shown even if offline")); QCOMPARE(temp.icon(), QStringLiteral()); QCOMPARE(temp.options(), Kopete::PropertyTmpl::PersistentProperty); A->statusTitle(); const QString statusTitle = QStringLiteral("statusTitle"); QVERIFY(A->isRegistered(statusTitle)); temp = A->tmpl(statusTitle); QCOMPARE(temp.key(), statusTitle); QCOMPARE(temp.label(), QStringLiteral("Status Title")); QCOMPARE(temp.icon(), QStringLiteral()); QCOMPARE(temp.options(), Kopete::PropertyTmpl::NoProperty); Kopete::PropertyTmpl::Map map = A->templateMap(); Kopete::PropertyTmpl test = map[isAlwaysVisible]; QVERIFY(A->isRegistered(isAlwaysVisible)); QCOMPARE(test.key(), isAlwaysVisible); QCOMPARE(test.label(), QStringLiteral("Shown even if offline")); QCOMPARE(test.icon(), QStringLiteral()); QCOMPARE(test.options(), Kopete::PropertyTmpl::PersistentProperty); } QTEST_MAIN(GlobalPropertiesTest) #include "kopeteglobaltest.moc" diff --git a/tests/libkopete/kopeteidentitytest.cpp b/tests/libkopete/kopeteidentitytest.cpp new file mode 100644 index 000000000..f0dd1c036 --- /dev/null +++ b/tests/libkopete/kopeteidentitytest.cpp @@ -0,0 +1,149 @@ +/* + Tests for Kopete::Identity + + Copyright (c) 2017 by Vijay Krishnavanshi + + Kopete (c) 2002-2017 by the Kopete developers + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include "kopeteidentity.h" +#include "kopeteaccount.h" +#include "kopeteonlinestatus.h" +#include "kopetestatusmessage.h" +#include "kopeteprotocol.h" +#include +#include + +class DummyProtocol : public Kopete::Protocol +{ +public: + DummyProtocol() : Kopete::Protocol(nullptr, false) + { + + } + Kopete::Account *createNewAccount(const QString &accountId) + { + Q_UNUSED(accountId) + return nullptr; + } + AddContactPage *createAddContactWidget(QWidget *parent, Kopete::Account *account) + { + Q_UNUSED(parent) + Q_UNUSED(account) + return nullptr; + } + KopeteEditAccountWidget *createEditAccountWidget(Kopete::Account *account, QWidget *parent) + { + Q_UNUSED(account) + Q_UNUSED(parent) + return nullptr; + } + void setCapability(Protocol::Capabilities capabilities) + { + this->setCapabilities(capabilities); + } +}; + +class TestAccount : public Kopete::Account +{ +public: + TestAccount(const QString ¶m) : Kopete::Account(new DummyProtocol(), param) + { + + } + bool createContact(const QString &contactId, Kopete::MetaContact *parentContact) + { + Q_UNUSED(contactId); + Q_UNUSED(parentContact); + return false; + } + void connect(const Kopete::OnlineStatus &initialStatus = Kopete::OnlineStatus()) + { + Q_UNUSED(initialStatus); + } + void disconnect() + { + + } + void setOnlineStatus(const Kopete::OnlineStatus &status, const Kopete::StatusMessage &reason = Kopete::StatusMessage(), const OnlineStatusOptions &options = None) + { + Q_UNUSED(status); + Q_UNUSED(reason); + Q_UNUSED(options); + } + void setStatusMessage(const Kopete::StatusMessage &statusMessage) + { + Q_UNUSED(statusMessage); + } +}; + +class IdentityTest : public QObject +{ + Q_OBJECT +private slots: + void testIdentity(); + void testIdentityAccounts(); +}; + +void IdentityTest::testIdentity() +{ + const QString Id = QStringLiteral("Id"); + const QString Label = QStringLiteral("Label"); + Kopete::Identity *A = new Kopete::Identity(Id, Label); + // check if unique connection exists + QCOMPARE(A->id(), Id); + QCOMPARE(A->label(), Label); + QSignalSpy spy(A, &Kopete::Identity::identityChanged); + QVERIFY(spy.isValid()); + const QString newLabel = QStringLiteral("newLabel"); + A->setLabel(newLabel); + QCOMPARE(spy.count(), 1); + QCOMPARE(A->label(), newLabel); + A->setLabel(newLabel); // signal is emmitted even if value is same + QCOMPARE(spy.count(), 2); + QVERIFY(!A->excludeConnect()); // check if it still return false + Kopete::OnlineStatus::StatusType test = A->onlineStatus(); + Kopete::OnlineStatus::StatusType expected = Kopete::OnlineStatus::Unknown; + QCOMPARE(test, expected); + QVERIFY(A->statusMessage().isEmpty()); + QString tt = A->toolTip(); + QVERIFY(tt.startsWith("")); + QVERIFY(tt.endsWith("")); + QCOMPARE(A->customIcon(), QStringLiteral("user-identity")); + QVERIFY(A->accounts().empty()); + QSignalSpy spyToolTip(A, &Kopete::Identity::toolTipChanged); + A->updateOnlineStatus(); + QCOMPARE(spyToolTip.count(), 1); + A->updateOnlineStatus(); + QCOMPARE(spyToolTip.count(), 2); +} + +void IdentityTest::testIdentityAccounts() +{ + TestAccount *dummyAccount = new TestAccount(QStringLiteral("dummyAccount")); + const QString Id = QStringLiteral("Id"); + const QString Label = QStringLiteral("Label"); + Kopete::Identity *A = new Kopete::Identity(Id, Label); + QSignalSpy spyIdentityChanged(A, &Kopete::Identity::identityChanged); + QSignalSpy spyToolTip(A, &Kopete::Identity::toolTipChanged); + A->addAccount(dummyAccount); + QCOMPARE(spyIdentityChanged.count(), 1); + QCOMPARE(spyToolTip.count(), 2); + QList list = A->accounts(); + QVERIFY(list.indexOf(dummyAccount) != 1); + A->removeAccount(dummyAccount); + QCOMPARE(spyIdentityChanged.count(), 2); + QCOMPARE(spyToolTip.count(), 4); +} + +QTEST_MAIN(IdentityTest) +#include "kopeteidentitytest.moc"