/* * Copyright (C) 2008-2012 The QXmpp developers * * Authors: * Jeremy Lainé * Manjeet Dahiya * * Source: * http://code.google.com/p/qxmpp * * This file is a part of QXmpp library. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * */ #include #include #include #include #include #include "QXmppArchiveIq.h" #include "QXmppBindIq.h" #include "QXmppClient.h" #include "QXmppDiscoveryIq.h" #include "QXmppNonSASLAuth.h" #include "QXmppPasswordChecker.h" #include "QXmppPubSubIq.h" #include "QXmppSessionIq.h" #include "QXmppServer.h" #include "QXmppStreamFeatures.h" #include "QXmppUtils.h" #include "QXmppVersionIq.h" #include "QXmppGlobal.h" #include "QXmppEntityTimeIq.h" #include "codec.h" #include "dataform.h" #include "iq.h" #include "jingle.h" #include "message.h" #include "presence.h" #include "register.h" #include "roster.h" #include "rpc.h" #include "rsm.h" #include "rtp.h" #include "sasl.h" #include "stanza.h" #include "stun.h" #include "tests.h" #include "vcard.h" void TestUtils::testCrc32() { quint32 crc = QXmppUtils::generateCrc32(QByteArray()); QCOMPARE(crc, 0u); crc = QXmppUtils::generateCrc32(QByteArray("Hi There")); QCOMPARE(crc, 0xDB143BBEu); } void TestUtils::testHmac() { QByteArray hmac = QXmppUtils::generateHmacMd5(QByteArray(16, 0x0b), QByteArray("Hi There")); QCOMPARE(hmac, QByteArray::fromHex("9294727a3638bb1c13f48ef8158bfc9d")); hmac = QXmppUtils::generateHmacMd5(QByteArray("Jefe"), QByteArray("what do ya want for nothing?")); QCOMPARE(hmac, QByteArray::fromHex("750c783e6ab0b503eaa86e310a5db738")); hmac = QXmppUtils::generateHmacMd5(QByteArray(16, 0xaa), QByteArray(50, 0xdd)); QCOMPARE(hmac, QByteArray::fromHex("56be34521d144c88dbb8c733f0e8b3f6")); } void TestUtils::testJid() { QCOMPARE(QXmppUtils::jidToBareJid("foo@example.com/resource"), QLatin1String("foo@example.com")); QCOMPARE(QXmppUtils::jidToBareJid("foo@example.com"), QLatin1String("foo@example.com")); QCOMPARE(QXmppUtils::jidToBareJid("example.com"), QLatin1String("example.com")); QCOMPARE(QXmppUtils::jidToBareJid(QString()), QString()); QCOMPARE(QXmppUtils::jidToDomain("foo@example.com/resource"), QLatin1String("example.com")); QCOMPARE(QXmppUtils::jidToDomain("foo@example.com"), QLatin1String("example.com")); QCOMPARE(QXmppUtils::jidToDomain("example.com"), QLatin1String("example.com")); QCOMPARE(QXmppUtils::jidToDomain(QString()), QString()); QCOMPARE(QXmppUtils::jidToResource("foo@example.com/resource"), QLatin1String("resource")); QCOMPARE(QXmppUtils::jidToResource("foo@example.com"), QString()); QCOMPARE(QXmppUtils::jidToResource("example.com"), QString()); QCOMPARE(QXmppUtils::jidToResource(QString()), QString()); QCOMPARE(QXmppUtils::jidToUser("foo@example.com/resource"), QLatin1String("foo")); QCOMPARE(QXmppUtils::jidToUser("foo@example.com"), QLatin1String("foo")); QCOMPARE(QXmppUtils::jidToUser("example.com"), QString()); QCOMPARE(QXmppUtils::jidToUser(QString()), QString()); } // FIXME: how should we test MIME detection without expose getImageType? #if 0 QString getImageType(const QByteArray &contents); static void testMimeType(const QString &fileName, const QString fileType) { // load file from resources QFile file(":/" + fileName); QCOMPARE(file.open(QIODevice::ReadOnly), true); QCOMPARE(getImageType(file.readAll()), fileType); file.close(); } void TestUtils::testMime() { testMimeType("test.bmp", "image/bmp"); testMimeType("test.gif", "image/gif"); testMimeType("test.jpg", "image/jpeg"); testMimeType("test.mng", "video/x-mng"); testMimeType("test.png", "image/png"); testMimeType("test.svg", "image/svg+xml"); testMimeType("test.xpm", "image/x-xpm"); } #else void TestUtils::testMime() { } #endif void TestUtils::testLibVersion() { QCOMPARE(QXmppVersion(), QString("0.7.1")); } void TestUtils::testTimezoneOffset() { // parsing QCOMPARE(QXmppUtils::timezoneOffsetFromString("Z"), 0); QCOMPARE(QXmppUtils::timezoneOffsetFromString("+00:00"), 0); QCOMPARE(QXmppUtils::timezoneOffsetFromString("-00:00"), 0); QCOMPARE(QXmppUtils::timezoneOffsetFromString("+01:30"), 5400); QCOMPARE(QXmppUtils::timezoneOffsetFromString("-01:30"), -5400); // serialization QCOMPARE(QXmppUtils::timezoneOffsetToString(0), QLatin1String("Z")); QCOMPARE(QXmppUtils::timezoneOffsetToString(5400), QLatin1String("+01:30")); QCOMPARE(QXmppUtils::timezoneOffsetToString(-5400), QLatin1String("-01:30")); } void TestPackets::testArchiveList_data() { QTest::addColumn("xml"); QTest::addColumn("max"); QTest::newRow("no rsm") << QByteArray( "" "" "") << -1; QTest::newRow("with rsm") << QByteArray( "" "" "" "30" "" "" "") << 30; } void TestPackets::testArchiveList() { QFETCH(QByteArray, xml); QFETCH(int, max); QXmppArchiveListIq iq; parsePacket(iq, xml); QCOMPARE(iq.type(), QXmppIq::Get); QCOMPARE(iq.id(), QLatin1String("list_1")); QCOMPARE(iq.with(), QLatin1String("juliet@capulet.com")); QCOMPARE(iq.start(), QDateTime(QDate(1469, 7, 21), QTime(2, 0, 0), Qt::UTC)); QCOMPARE(iq.end(), QDateTime(QDate(1479, 7, 21), QTime(4, 0, 0), Qt::UTC)); QCOMPARE(iq.resultSetQuery().max(), max); serializePacket(iq, xml); } void TestPackets::testArchiveChat_data() { QTest::addColumn("xml"); QTest::addColumn("count"); QTest::newRow("no rsm") << QByteArray( "" "" "Art thou not Romeo, and a Montague?" "Neither, fair saint, if either thee dislike." "How cam'st thou hither, tell me, and wherefore?" "" "") << -1; QTest::newRow("with rsm") << QByteArray( "" "" "Art thou not Romeo, and a Montague?" "Neither, fair saint, if either thee dislike." "How cam'st thou hither, tell me, and wherefore?" "" "3" "" "" "") << 3; } void TestPackets::testArchiveChat() { QFETCH(QByteArray, xml); QFETCH(int, count); QXmppArchiveChatIq iq; parsePacket(iq, xml); QCOMPARE(iq.type(), QXmppIq::Result); QCOMPARE(iq.id(), QLatin1String("chat_1")); QCOMPARE(iq.chat().with(), QLatin1String("juliet@capulet.com")); QCOMPARE(iq.chat().messages().size(), 3); QCOMPARE(iq.chat().messages()[0].isReceived(), true); QCOMPARE(iq.chat().messages()[0].body(), QLatin1String("Art thou not Romeo, and a Montague?")); QCOMPARE(iq.chat().messages()[0].date(), QDateTime(QDate(1469, 7, 21), QTime(2, 56, 15), Qt::UTC)); QCOMPARE(iq.chat().messages()[1].isReceived(), false); QCOMPARE(iq.chat().messages()[1].date(), QDateTime(QDate(1469, 7, 21), QTime(2, 56, 26), Qt::UTC)); QCOMPARE(iq.chat().messages()[1].body(), QLatin1String("Neither, fair saint, if either thee dislike.")); QCOMPARE(iq.chat().messages()[2].isReceived(), true); QCOMPARE(iq.chat().messages()[2].date(), QDateTime(QDate(1469, 7, 21), QTime(2, 56, 33), Qt::UTC)); QCOMPARE(iq.chat().messages()[2].body(), QLatin1String("How cam'st thou hither, tell me, and wherefore?")); QCOMPARE(iq.resultSetReply().count(), count); serializePacket(iq, xml); } void TestPackets::testArchiveRemove() { const QByteArray xml( "" "" ""); QXmppArchiveRemoveIq iq; parsePacket(iq, xml); QCOMPARE(iq.type(), QXmppIq::Set); QCOMPARE(iq.id(), QLatin1String("remove_1")); QCOMPARE(iq.with(), QLatin1String("juliet@capulet.com")); QCOMPARE(iq.start(), QDateTime(QDate(1469, 7, 21), QTime(2, 0, 0), Qt::UTC)); QCOMPARE(iq.end(), QDateTime(QDate(1479, 7, 21), QTime(4, 0, 0), Qt::UTC)); serializePacket(iq, xml); } void TestPackets::testArchiveRetrieve_data() { QTest::addColumn("xml"); QTest::addColumn("max"); QTest::newRow("no rsm") << QByteArray( "" "" "") << -1; QTest::newRow("with rsm") << QByteArray( "" "" "" "30" "" "" "") << 30; } void TestPackets::testArchiveRetrieve() { QFETCH(QByteArray, xml); QFETCH(int, max); QXmppArchiveRetrieveIq iq; parsePacket(iq, xml); QCOMPARE(iq.type(), QXmppIq::Get); QCOMPARE(iq.id(), QLatin1String("retrieve_1")); QCOMPARE(iq.with(), QLatin1String("juliet@capulet.com")); QCOMPARE(iq.start(), QDateTime(QDate(1469, 7, 21), QTime(2, 0, 0), Qt::UTC)); QCOMPARE(iq.resultSetQuery().max(), max); serializePacket(iq, xml); } void TestPackets::testBindNoResource() { const QByteArray xml( "" "" ""); QXmppBindIq bind; parsePacket(bind, xml); QCOMPARE(bind.type(), QXmppIq::Set); QCOMPARE(bind.id(), QString("bind_1")); QCOMPARE(bind.jid(), QString()); QCOMPARE(bind.resource(), QString()); serializePacket(bind, xml); } void TestPackets::testBindResource() { const QByteArray xml( "" "" "someresource" "" ""); QXmppBindIq bind; parsePacket(bind, xml); QCOMPARE(bind.type(), QXmppIq::Set); QCOMPARE(bind.id(), QString("bind_2")); QCOMPARE(bind.jid(), QString()); QCOMPARE(bind.resource(), QString("someresource")); serializePacket(bind, xml); } void TestPackets::testBindResult() { const QByteArray xml( "" "" "somenode@example.com/someresource" "" ""); QXmppBindIq bind; parsePacket(bind, xml); QCOMPARE(bind.type(), QXmppIq::Result); QCOMPARE(bind.id(), QString("bind_2")); QCOMPARE(bind.jid(), QString("somenode@example.com/someresource")); QCOMPARE(bind.resource(), QString()); serializePacket(bind, xml); } void TestPackets::testDiscovery() { const QByteArray xml( "" "" "" "" "" "" "" "" ""); QXmppDiscoveryIq disco; parsePacket(disco, xml); QCOMPARE(disco.verificationString(), QByteArray::fromBase64("QgayPKawpkPSDYmwT/WM94uAlu0=")); serializePacket(disco, xml); } void TestPackets::testDiscoveryWithForm() { const QByteArray xml( "" "" "" "" "" "" "" "" "" "" "urn:xmpp:dataforms:softwareinfo" "" "" "ipv4" "ipv6" "" "" "Mac" "" "" "10.5.1" "" "" "Psi" "" "" "0.11" "" "" "" ""); QXmppDiscoveryIq disco; parsePacket(disco, xml); QCOMPARE(disco.verificationString(), QByteArray::fromBase64("q07IKJEyjvHSyhy//CH0CxmKi8w=")); serializePacket(disco, xml); } void TestPackets::testNonSaslAuth() { // Client Requests Authentication Fields from Server const QByteArray xml1( "" "" ""); QXmppNonSASLAuthIq iq1; parsePacket(iq1, xml1); serializePacket(iq1, xml1); // Client Provides Required Information (Plaintext) const QByteArray xml3( "" "" "bill" "Calli0pe" "globe" "" ""); QXmppNonSASLAuthIq iq3; parsePacket(iq3, xml3); QCOMPARE(iq3.username(), QLatin1String("bill")); QCOMPARE(iq3.digest(), QByteArray()); QCOMPARE(iq3.password(), QLatin1String("Calli0pe")); QCOMPARE(iq3.resource(), QLatin1String("globe")); serializePacket(iq3, xml3); // Client Provides Required Information (Plaintext) const QByteArray xml4( "" "" "bill" "48fc78be9ec8f86d8ce1c39c320c97c21d62334d" "globe" "" ""); QXmppNonSASLAuthIq iq4; parsePacket(iq4, xml4); QCOMPARE(iq4.username(), QLatin1String("bill")); QCOMPARE(iq4.digest(), QByteArray("\x48\xfc\x78\xbe\x9e\xc8\xf8\x6d\x8c\xe1\xc3\x9c\x32\x0c\x97\xc2\x1d\x62\x33\x4d")); QCOMPARE(iq4.password(), QString()); QCOMPARE(iq4.resource(), QLatin1String("globe")); serializePacket(iq4, xml4); } void TestPackets::testSession() { const QByteArray xml( "" "" ""); QXmppSessionIq session; parsePacket(session, xml); QCOMPARE(session.id(), QString("session_1")); QCOMPARE(session.to(), QString("example.com")); QCOMPARE(session.type(), QXmppIq::Set); serializePacket(session, xml); } void TestPackets::testStreamFeatures() { const QByteArray xml(""); QXmppStreamFeatures features; parsePacket(features, xml); QCOMPARE(features.bindMode(), QXmppStreamFeatures::Disabled); QCOMPARE(features.sessionMode(), QXmppStreamFeatures::Disabled); QCOMPARE(features.nonSaslAuthMode(), QXmppStreamFeatures::Disabled); QCOMPARE(features.tlsMode(), QXmppStreamFeatures::Disabled); QCOMPARE(features.authMechanisms(), QStringList()); QCOMPARE(features.compressionMethods(), QStringList()); serializePacket(features, xml); const QByteArray xml2("" "" "" "" "" "zlib" "PLAIN" ""); QXmppStreamFeatures features2; parsePacket(features2, xml2); QCOMPARE(features2.bindMode(), QXmppStreamFeatures::Enabled); QCOMPARE(features2.sessionMode(), QXmppStreamFeatures::Enabled); QCOMPARE(features2.nonSaslAuthMode(), QXmppStreamFeatures::Enabled); QCOMPARE(features2.tlsMode(), QXmppStreamFeatures::Enabled); QCOMPARE(features2.authMechanisms(), QStringList() << "PLAIN"); QCOMPARE(features2.compressionMethods(), QStringList() << "zlib"); serializePacket(features2, xml2); } void TestPackets::testVersionGet() { const QByteArray xmlGet( "" ""); QXmppVersionIq verIqGet; parsePacket(verIqGet, xmlGet); QCOMPARE(verIqGet.id(), QLatin1String("version_1")); QCOMPARE(verIqGet.to(), QLatin1String("juliet@capulet.com/balcony")); QCOMPARE(verIqGet.from(), QLatin1String("romeo@montague.net/orchard")); QCOMPARE(verIqGet.type(), QXmppIq::Get); serializePacket(verIqGet, xmlGet); } void TestPackets::testVersionResult() { const QByteArray xmlResult( "" "" "qxmpp" "Windows-XP" "0.2.0" ""); QXmppVersionIq verIqResult; parsePacket(verIqResult, xmlResult); QCOMPARE(verIqResult.id(), QLatin1String("version_1")); QCOMPARE(verIqResult.to(), QLatin1String("romeo@montague.net/orchard")); QCOMPARE(verIqResult.from(), QLatin1String("juliet@capulet.com/balcony")); QCOMPARE(verIqResult.type(), QXmppIq::Result); QCOMPARE(verIqResult.name(), QString("qxmpp")); QCOMPARE(verIqResult.version(), QString("0.2.0")); QCOMPARE(verIqResult.os(), QString("Windows-XP")); serializePacket(verIqResult, xmlResult); } void TestPackets::testEntityTimeGet() { const QByteArray xml("" ""); QXmppEntityTimeIq entityTime; parsePacket(entityTime, xml); QCOMPARE(entityTime.id(), QLatin1String("time_1")); QCOMPARE(entityTime.to(), QLatin1String("juliet@capulet.com/balcony")); QCOMPARE(entityTime.from(), QLatin1String("romeo@montague.net/orchard")); QCOMPARE(entityTime.type(), QXmppIq::Get); serializePacket(entityTime, xml); } void TestPackets::testEntityTimeResult() { const QByteArray xml( "" "" ""); QXmppEntityTimeIq entityTime; parsePacket(entityTime, xml); QCOMPARE(entityTime.id(), QLatin1String("time_1")); QCOMPARE(entityTime.from(), QLatin1String("juliet@capulet.com/balcony")); QCOMPARE(entityTime.to(), QLatin1String("romeo@montague.net/orchard")); QCOMPARE(entityTime.type(), QXmppIq::Result); QCOMPARE(entityTime.tzo(), -21600); QCOMPARE(entityTime.utc(), QDateTime(QDate(2006, 12, 19), QTime(17, 58, 35), Qt::UTC)); serializePacket(entityTime, xml); } void TestPubSub::testItems() { const QByteArray xml( "" "" "" "" ""); QXmppPubSubIq iq; parsePacket(iq, xml); QCOMPARE(iq.id(), QLatin1String("items1")); QCOMPARE(iq.to(), QLatin1String("pubsub.shakespeare.lit")); QCOMPARE(iq.from(), QLatin1String("francisco@denmark.lit/barracks")); QCOMPARE(iq.type(), QXmppIq::Get); QCOMPARE(iq.queryType(), QXmppPubSubIq::ItemsQuery); QCOMPARE(iq.queryJid(), QString()); QCOMPARE(iq.queryNode(), QLatin1String("storage:bookmarks")); serializePacket(iq, xml); } void TestPubSub::testItemsResponse() { const QByteArray xml( "" "" "" "" "" "" "JC" "" "" "" "" "" ""); QXmppPubSubIq iq; parsePacket(iq, xml); QCOMPARE(iq.id(), QLatin1String("items1")); QCOMPARE(iq.to(), QLatin1String("francisco@denmark.lit/barracks")); QCOMPARE(iq.from(), QLatin1String("pubsub.shakespeare.lit")); QCOMPARE(iq.type(), QXmppIq::Result); QCOMPARE(iq.queryType(), QXmppPubSubIq::ItemsQuery); QCOMPARE(iq.queryJid(), QString()); QCOMPARE(iq.queryNode(), QLatin1String("storage:bookmarks")); serializePacket(iq, xml); } void TestPubSub::testPublish() { const QByteArray xml( "" "" "" "" "" "" "JC" "" "" "" "" "" ""); QXmppPubSubIq iq; parsePacket(iq, xml); QCOMPARE(iq.id(), QLatin1String("items1")); QCOMPARE(iq.to(), QLatin1String("pubsub.shakespeare.lit")); QCOMPARE(iq.from(), QLatin1String("francisco@denmark.lit/barracks")); QCOMPARE(iq.type(), QXmppIq::Result); QCOMPARE(iq.queryType(), QXmppPubSubIq::PublishQuery); QCOMPARE(iq.queryJid(), QString()); QCOMPARE(iq.queryNode(), QLatin1String("storage:bookmarks")); serializePacket(iq, xml); } void TestPubSub::testSubscribe() { const QByteArray xml( "" "" "" "" ""); QXmppPubSubIq iq; parsePacket(iq, xml); QCOMPARE(iq.id(), QLatin1String("sub1")); QCOMPARE(iq.to(), QLatin1String("pubsub.shakespeare.lit")); QCOMPARE(iq.from(), QLatin1String("francisco@denmark.lit/barracks")); QCOMPARE(iq.type(), QXmppIq::Set); QCOMPARE(iq.queryType(), QXmppPubSubIq::SubscribeQuery); QCOMPARE(iq.queryJid(), QLatin1String("francisco@denmark.lit")); QCOMPARE(iq.queryNode(), QLatin1String("princely_musings")); serializePacket(iq, xml); } void TestPubSub::testSubscription() { const QByteArray xml( "" "" "" "" ""); QXmppPubSubIq iq; parsePacket(iq, xml); QCOMPARE(iq.id(), QLatin1String("sub1")); QCOMPARE(iq.to(), QLatin1String("francisco@denmark.lit/barracks")); QCOMPARE(iq.from(), QLatin1String("pubsub.shakespeare.lit")); QCOMPARE(iq.type(), QXmppIq::Result); QCOMPARE(iq.queryType(), QXmppPubSubIq::SubscriptionQuery); QCOMPARE(iq.queryJid(), QLatin1String("francisco@denmark.lit")); QCOMPARE(iq.queryNode(), QLatin1String("princely_musings")); QCOMPARE(iq.subscriptionId(), QLatin1String("ba49252aaa4f5d320c24d3766f0bdcade78c78d3")); serializePacket(iq, xml); } void TestPubSub::testSubscriptions() { const QByteArray xml( "" "" "" "" ""); QXmppPubSubIq iq; parsePacket(iq, xml); QCOMPARE(iq.id(), QLatin1String("subscriptions1")); QCOMPARE(iq.to(), QLatin1String("pubsub.shakespeare.lit")); QCOMPARE(iq.from(), QLatin1String("francisco@denmark.lit/barracks")); QCOMPARE(iq.type(), QXmppIq::Get); QCOMPARE(iq.queryType(), QXmppPubSubIq::SubscriptionsQuery); QCOMPARE(iq.queryJid(), QString()); QCOMPARE(iq.queryNode(), QString()); serializePacket(iq, xml); } class TestPasswordChecker : public QXmppPasswordChecker { public: TestPasswordChecker(const QString &username, const QString &password) : m_getPassword(true), m_username(username), m_password(password) { }; /// Retrieves the password for the given username. QXmppPasswordReply::Error getPassword(const QXmppPasswordRequest &request, QString &password) { if (request.username() == m_username) { password = m_password; return QXmppPasswordReply::NoError; } else { return QXmppPasswordReply::AuthorizationError; } }; /// Sets whether getPassword() is enabled. void setGetPassword(bool getPassword) { m_getPassword = getPassword; } /// Returns whether getPassword() is enabled. bool hasGetPassword() const { return m_getPassword; }; private: bool m_getPassword; QString m_username; QString m_password; }; void TestServer::testConnect_data() { QTest::addColumn("username"); QTest::addColumn("password"); QTest::addColumn("mechanism"); QTest::addColumn("connected"); QTest::newRow("plain-good") << "testuser" << "testpwd" << "PLAIN" << true; QTest::newRow("plain-bad-username") << "baduser" << "testpwd" << "PLAIN" << false; QTest::newRow("plain-bad-password") << "testuser" << "badpwd" << "PLAIN" << false; QTest::newRow("digest-good") << "testuser" << "testpwd" << "DIGEST-MD5" << true; QTest::newRow("digest-bad-username") << "baduser" << "testpwd" << "DIGEST-MD5" << false; QTest::newRow("digest-bad-password") << "testuser" << "badpwd" << "DIGEST-MD5" << false; } void TestServer::testConnect() { QFETCH(QString, username); QFETCH(QString, password); QFETCH(QString, mechanism); QFETCH(bool, connected); const QString testDomain("localhost"); const QHostAddress testHost(QHostAddress::LocalHost); const quint16 testPort = 12345; QXmppLogger logger; logger.setLoggingType(QXmppLogger::StdoutLogging); // prepare server TestPasswordChecker passwordChecker("testuser", "testpwd"); QXmppServer server; server.setDomain(testDomain); server.setLogger(&logger); server.setPasswordChecker(&passwordChecker); server.listenForClients(testHost, testPort); // prepare client QXmppClient client; client.setLogger(&logger); QEventLoop loop; connect(&client, SIGNAL(connected()), &loop, SLOT(quit())); connect(&client, SIGNAL(disconnected()), &loop, SLOT(quit())); QXmppConfiguration config; config.setDomain(testDomain); config.setHost(testHost.toString()); config.setPort(testPort); config.setUser(username); config.setPassword(password); config.setSaslAuthMechanism(mechanism); client.connectToServer(config); loop.exec(); QCOMPARE(client.isConnected(), connected); } int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); QXmppPresence pres; pres.availableStatusType(); // run tests int errors = 0; TestUtils testUtils; errors += QTest::qExec(&testUtils); TestPackets testPackets; errors += QTest::qExec(&testPackets); #ifdef QXMPP_AUTOTEST_INTERNAL TestCodec testCodec; errors += QTest::qExec(&testCodec); #endif tst_QXmppDataForm testDataForm; errors += QTest::qExec(&testDataForm); tst_QXmppIq testIq; errors += QTest::qExec(&testIq); TestJingle testJingle; errors += QTest::qExec(&testJingle); tst_QXmppMessage testMessage; errors += QTest::qExec(&testMessage); tst_QXmppPresence testPresence; errors += QTest::qExec(&testPresence); TestPubSub testPubSub; errors += QTest::qExec(&testPubSub); tst_QXmppRegisterIq testRegister; errors += QTest::qExec(&testRegister); tst_QXmppResultSet testRsm; errors += QTest::qExec(&testRsm); tst_QXmppRosterIq testRoster; errors += QTest::qExec(&testRoster); tst_QXmppRtpPacket testRtp; errors += QTest::qExec(&testRtp); #ifdef QXMPP_AUTOTEST_INTERNAL tst_QXmppSasl testSasl; errors += QTest::qExec(&testSasl); tst_QXmppSaslClient testSaslClient; errors += QTest::qExec(&testSaslClient); tst_QXmppSaslServer testSaslServer; errors += QTest::qExec(&testSaslServer); #endif TestServer testServer; errors += QTest::qExec(&testServer); tst_QXmppStanza testStanza; errors += QTest::qExec(&testStanza); TestStun testStun; errors += QTest::qExec(&testStun); tst_QXmppVCardIq testVCard; errors += QTest::qExec(&testVCard); TestXmlRpc testXmlRpc; errors += QTest::qExec(&testXmlRpc); if (errors) { qWarning() << "Total failed tests:" << errors; return EXIT_FAILURE; } return EXIT_SUCCESS; };