diff --git a/protocols/jabber/CMakeLists.txt b/protocols/jabber/CMakeLists.txt --- a/protocols/jabber/CMakeLists.txt +++ b/protocols/jabber/CMakeLists.txt @@ -163,8 +163,8 @@ ) endif(BUILD_JINGLE) -add_library(kopete_jabber MODULE ${kopete_jabber_PART_SRCS}) -generate_export_header(kopete_jabber BASE_NAME jabber) +add_library(kopete_jabber STATIC ${kopete_jabber_PART_SRCS}) +generate_export_header(kopete_jabber BASE_NAME kopete_jabber) target_link_libraries(kopete_jabber KF5::KIOCore ${QCA2_LIBRARIES} kopete iris_kopete) if(BUILD_JINGLE) diff --git a/tests/protocols/CMakeLists.txt b/tests/protocols/CMakeLists.txt --- a/tests/protocols/CMakeLists.txt +++ b/tests/protocols/CMakeLists.txt @@ -1 +1,2 @@ add_subdirectory(oscar) +add_subdirectory(jabber) diff --git a/tests/protocols/jabber/CMakeLists.txt b/tests/protocols/jabber/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/tests/protocols/jabber/CMakeLists.txt @@ -0,0 +1,22 @@ +include_directories( + ${KOPETE_INCLUDES} + ${CMAKE_SOURCE_DIR}/protocols/jabber/ + ${CMAKE_SOURCE_DIR}/protocols/jabber/ui/ + ${CMAKE_SOURCE_DIR}/protocols/jabber/tasks/ + ${CMAKE_SOURCE_DIR}/protocols/jabber/libiris/include/iris + ${CMAKE_SOURCE_DIR}/protocols/jabber/libiris/src + ${QCA2_INCLUDE_DIR} + ${QJSON_INCLUDE_DIR} + ) + +set( JABBER_TEST_LIBRARIES + kopete + kopete_jabber + qca-qt5 + Qt5::Test + Qt5::Core + KF5::KIOCore + #${CMAKE_SOURCE_DIR}/protocols/jabber/jabberprotocol.cpp + ) + +ecm_add_test(jabberprotocoltest.cpp LINK_LIBRARIES ${JABBER_TEST_LIBRARIES}) diff --git a/tests/protocols/jabber/jabberprotocoltest.cpp b/tests/protocols/jabber/jabberprotocoltest.cpp new file mode 100644 --- /dev/null +++ b/tests/protocols/jabber/jabberprotocoltest.cpp @@ -0,0 +1,119 @@ +#include "jabbercontact.h" +#include "jabberprotocol.h" +#include "jabberaccount.h" + +#include +#include + +Q_DECLARE_METATYPE(Kopete::OnlineStatus); +Q_DECLARE_METATYPE(XMPP::Status::Type); + +class JabberProtocolTest : public QObject +{ + Q_OBJECT +private slots: + void resourceToKOSTest(); + void resourceToKOSTest_data(); + void kosToStatusTest(); + void kosToStatusTest_data(); + void createNewAccount(); + void createNewAccount_data(); +}; + +void JabberProtocolTest::createNewAccount_data() +{ + QTest::addColumn("accountId"); + + QTest::newRow("jabberId_with_slash") << QStringLiteral("jabber@jabber.org/device") ; + QTest::newRow("jabberId_without_slash") << QStringLiteral("jabber@jabber.org") ; + QTest::newRow("Empty_Id") << QStringLiteral("") ; +} + +void JabberProtocolTest::createNewAccount() +{ + QFETCH(QString, accountId); + + const QVariantList list; + JabberProtocol* jabberprotocol = new JabberProtocol(nullptr, list); + Kopete::Account* account = jabberprotocol->createNewAccount (accountId); + bool IsAccountCreated = false; + if(account) + IsAccountCreated = true; + QVERIFY(IsAccountCreated); + QCOMPARE(account->protocol(), jabberprotocol); + QCOMPARE(account->protocol(), jabberprotocol); + QCOMPARE(jabberprotocol->protocol(), jabberprotocol); + QVERIFY(jabberprotocol->canSendOffline()); + delete jabberprotocol; +} + +void JabberProtocolTest::resourceToKOSTest_data() +{ + const QVariantList list; + JabberProtocol* jabberprotocol = new JabberProtocol(nullptr, list); + + QTest::addColumn("KopeteOnlineStatus_Result"); + QTest::addColumn("StatusMessage"); + QTest::addColumn("xmppstatus_type"); + + QTest::newRow("Offline") << jabberprotocol->JabberKOSOffline << QStringLiteral("Offline") << XMPP::Status::Offline ; + QTest::newRow("Chatty") << jabberprotocol->JabberKOSChatty << QStringLiteral("Chatty") << XMPP::Status::FFC ; + QTest::newRow("Online") << jabberprotocol->JabberKOSOnline << QStringLiteral("Online") << XMPP::Status::Online ; + QTest::newRow("Away") << jabberprotocol->JabberKOSAway << QStringLiteral("Away") << XMPP::Status::Away ; + QTest::newRow("XA") << jabberprotocol->JabberKOSXA << QStringLiteral("XA") << XMPP::Status::XA ; + QTest::newRow("DND") << jabberprotocol->JabberKOSDND << QStringLiteral("DND") << XMPP::Status::DND ; + QTest::newRow("Invisible") << jabberprotocol->JabberKOSInvisible << QStringLiteral("Invisible") << XMPP::Status::Invisible ; + delete jabberprotocol; +} + +void JabberProtocolTest::resourceToKOSTest() +{ + QFETCH(Kopete::OnlineStatus, KopeteOnlineStatus_Result); + QFETCH(QString, StatusMessage); + QFETCH(XMPP::Status::Type, xmppstatus_type); + + const QVariantList list; + JabberProtocol* jabberprotocol = new JabberProtocol(nullptr, list); + QString name = QStringLiteral("ResourceStatus"); + XMPP::Status xmppStatus ( QLatin1String(""), StatusMessage ); + xmppStatus.setType(xmppstatus_type); + XMPP::Resource resource(name, xmppStatus); + Kopete::OnlineStatus status = jabberprotocol->resourceToKOS ( resource ); + QCOMPARE(status, KopeteOnlineStatus_Result); + delete jabberprotocol; +} + +void JabberProtocolTest::kosToStatusTest_data() +{ + const QVariantList list; + JabberProtocol* jabberprotocol = new JabberProtocol(nullptr, list); + + QTest::addColumn("KopeteOnlineStatus_input"); + QTest::addColumn("message"); + QTest::addColumn("xmppstatus_type_result"); + + QTest::newRow("Offline") << jabberprotocol->JabberKOSOffline << QStringLiteral("Offline") << XMPP::Status::Offline ; + QTest::newRow("Chatty") << jabberprotocol->JabberKOSChatty << QStringLiteral("Chatty") << XMPP::Status::FFC ; + QTest::newRow("Online") << jabberprotocol->JabberKOSOnline << QStringLiteral("Online") << XMPP::Status::Online ; + QTest::newRow("Away") << jabberprotocol->JabberKOSAway << QStringLiteral("Away") << XMPP::Status::Away ; + QTest::newRow("XA") << jabberprotocol->JabberKOSXA << QStringLiteral("XA") << XMPP::Status::XA ; + QTest::newRow("DND") << jabberprotocol->JabberKOSDND << QStringLiteral("DND") << XMPP::Status::DND ; + QTest::newRow("Invisible") << jabberprotocol->JabberKOSInvisible << QStringLiteral("Invisible") << XMPP::Status::Invisible ; + delete jabberprotocol; +} + +void JabberProtocolTest::kosToStatusTest() +{ + QFETCH(Kopete::OnlineStatus, KopeteOnlineStatus_input); + QFETCH(QString, message); + QFETCH(XMPP::Status::Type, xmppstatus_type_result); + + const QVariantList list; + JabberProtocol* jabberprotocol = new JabberProtocol(nullptr, list); + XMPP::Status xmppstatus = jabberprotocol->kosToStatus(KopeteOnlineStatus_input, message); + QCOMPARE(xmppstatus.type(), xmppstatus_type_result); + delete jabberprotocol; +} + +QTEST_MAIN(JabberProtocolTest) +#include "jabberprotocoltest.moc"