Changeset View
Changeset View
Standalone View
Standalone View
tests/protocols/jabber/jabberprotocoltest.cpp
- This file was added.
1 | #include "jabbercontact.h" | ||||
---|---|---|---|---|---|
2 | #include "jabberprotocol.h" | ||||
3 | #include "jabberaccount.h" | ||||
4 | | ||||
5 | #include <QObject> | ||||
6 | #include <QtTest> | ||||
7 | | ||||
8 | Q_DECLARE_METATYPE(Kopete::OnlineStatus); | ||||
9 | Q_DECLARE_METATYPE(XMPP::Status::Type); | ||||
10 | | ||||
11 | class JabberProtocolTest : public QObject | ||||
12 | { | ||||
13 | Q_OBJECT | ||||
14 | private slots: | ||||
15 | void resourceToKOSTest(); | ||||
16 | void resourceToKOSTest_data(); | ||||
17 | void kosToStatusTest(); | ||||
18 | void kosToStatusTest_data(); | ||||
19 | void createNewAccount(); | ||||
20 | void createNewAccount_data(); | ||||
21 | }; | ||||
22 | | ||||
23 | void JabberProtocolTest::createNewAccount_data() | ||||
24 | { | ||||
25 | QTest::addColumn<QString>("accountId"); | ||||
26 | | ||||
27 | QTest::newRow("jabberId_with_slash") << QStringLiteral("jabber@jabber.org/device") ; | ||||
28 | QTest::newRow("jabberId_without_slash") << QStringLiteral("jabber@jabber.org") ; | ||||
29 | QTest::newRow("Empty_Id") << QStringLiteral("") ; | ||||
30 | } | ||||
31 | | ||||
32 | void JabberProtocolTest::createNewAccount() | ||||
33 | { | ||||
34 | QFETCH(QString, accountId); | ||||
35 | | ||||
36 | const QVariantList list; | ||||
37 | JabberProtocol* jabberprotocol = new JabberProtocol(nullptr, list); | ||||
38 | Kopete::Account* account = jabberprotocol->createNewAccount (accountId); | ||||
39 | bool IsAccountCreated = false; | ||||
40 | if(account) | ||||
41 | IsAccountCreated = true; | ||||
42 | QVERIFY(IsAccountCreated); | ||||
43 | QCOMPARE(account->protocol(), jabberprotocol); | ||||
44 | QCOMPARE(account->protocol(), jabberprotocol); | ||||
45 | QCOMPARE(jabberprotocol->protocol(), jabberprotocol); | ||||
46 | QVERIFY(jabberprotocol->canSendOffline()); | ||||
47 | delete jabberprotocol; | ||||
48 | } | ||||
49 | | ||||
50 | void JabberProtocolTest::resourceToKOSTest_data() | ||||
51 | { | ||||
52 | const QVariantList list; | ||||
53 | JabberProtocol* jabberprotocol = new JabberProtocol(nullptr, list); | ||||
54 | | ||||
55 | QTest::addColumn<Kopete::OnlineStatus>("KopeteOnlineStatus_Result"); | ||||
56 | QTest::addColumn<QString>("StatusMessage"); | ||||
57 | QTest::addColumn<XMPP::Status::Type>("xmppstatus_type"); | ||||
58 | | ||||
59 | QTest::newRow("Offline") << jabberprotocol->JabberKOSOffline << QStringLiteral("Offline") << XMPP::Status::Offline ; | ||||
60 | QTest::newRow("Chatty") << jabberprotocol->JabberKOSChatty << QStringLiteral("Chatty") << XMPP::Status::FFC ; | ||||
61 | QTest::newRow("Online") << jabberprotocol->JabberKOSOnline << QStringLiteral("Online") << XMPP::Status::Online ; | ||||
62 | QTest::newRow("Away") << jabberprotocol->JabberKOSAway << QStringLiteral("Away") << XMPP::Status::Away ; | ||||
63 | QTest::newRow("XA") << jabberprotocol->JabberKOSXA << QStringLiteral("XA") << XMPP::Status::XA ; | ||||
64 | QTest::newRow("DND") << jabberprotocol->JabberKOSDND << QStringLiteral("DND") << XMPP::Status::DND ; | ||||
65 | QTest::newRow("Invisible") << jabberprotocol->JabberKOSInvisible << QStringLiteral("Invisible") << XMPP::Status::Invisible ; | ||||
66 | delete jabberprotocol; | ||||
67 | } | ||||
68 | | ||||
69 | void JabberProtocolTest::resourceToKOSTest() | ||||
70 | { | ||||
71 | QFETCH(Kopete::OnlineStatus, KopeteOnlineStatus_Result); | ||||
72 | QFETCH(QString, StatusMessage); | ||||
73 | QFETCH(XMPP::Status::Type, xmppstatus_type); | ||||
74 | | ||||
75 | const QVariantList list; | ||||
76 | JabberProtocol* jabberprotocol = new JabberProtocol(nullptr, list); | ||||
77 | QString name = QStringLiteral("ResourceStatus"); | ||||
78 | XMPP::Status xmppStatus ( QLatin1String(""), StatusMessage ); | ||||
79 | xmppStatus.setType(xmppstatus_type); | ||||
80 | XMPP::Resource resource(name, xmppStatus); | ||||
81 | Kopete::OnlineStatus status = jabberprotocol->resourceToKOS ( resource ); | ||||
82 | QCOMPARE(status, KopeteOnlineStatus_Result); | ||||
83 | delete jabberprotocol; | ||||
84 | } | ||||
85 | | ||||
86 | void JabberProtocolTest::kosToStatusTest_data() | ||||
87 | { | ||||
88 | const QVariantList list; | ||||
89 | JabberProtocol* jabberprotocol = new JabberProtocol(nullptr, list); | ||||
90 | | ||||
91 | QTest::addColumn<Kopete::OnlineStatus>("KopeteOnlineStatus_input"); | ||||
92 | QTest::addColumn<QString>("message"); | ||||
93 | QTest::addColumn<XMPP::Status::Type>("xmppstatus_type_result"); | ||||
94 | | ||||
95 | QTest::newRow("Offline") << jabberprotocol->JabberKOSOffline << QStringLiteral("Offline") << XMPP::Status::Offline ; | ||||
96 | QTest::newRow("Chatty") << jabberprotocol->JabberKOSChatty << QStringLiteral("Chatty") << XMPP::Status::FFC ; | ||||
97 | QTest::newRow("Online") << jabberprotocol->JabberKOSOnline << QStringLiteral("Online") << XMPP::Status::Online ; | ||||
98 | QTest::newRow("Away") << jabberprotocol->JabberKOSAway << QStringLiteral("Away") << XMPP::Status::Away ; | ||||
99 | QTest::newRow("XA") << jabberprotocol->JabberKOSXA << QStringLiteral("XA") << XMPP::Status::XA ; | ||||
100 | QTest::newRow("DND") << jabberprotocol->JabberKOSDND << QStringLiteral("DND") << XMPP::Status::DND ; | ||||
101 | QTest::newRow("Invisible") << jabberprotocol->JabberKOSInvisible << QStringLiteral("Invisible") << XMPP::Status::Invisible ; | ||||
102 | delete jabberprotocol; | ||||
103 | } | ||||
104 | | ||||
105 | void JabberProtocolTest::kosToStatusTest() | ||||
106 | { | ||||
107 | QFETCH(Kopete::OnlineStatus, KopeteOnlineStatus_input); | ||||
108 | QFETCH(QString, message); | ||||
109 | QFETCH(XMPP::Status::Type, xmppstatus_type_result); | ||||
110 | | ||||
111 | const QVariantList list; | ||||
112 | JabberProtocol* jabberprotocol = new JabberProtocol(nullptr, list); | ||||
113 | XMPP::Status xmppstatus = jabberprotocol->kosToStatus(KopeteOnlineStatus_input, message); | ||||
114 | QCOMPARE(xmppstatus.type(), xmppstatus_type_result); | ||||
115 | delete jabberprotocol; | ||||
116 | } | ||||
117 | | ||||
118 | QTEST_MAIN(JabberProtocolTest) | ||||
119 | #include "jabberprotocoltest.moc" |