diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-09-27 21:03:39 +0200 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-09-27 21:03:39 +0200 |
| commit | f4dbb00a035eb4df8a12f5edaf53bb99a2bd435a (patch) | |
| tree | c3dcc1dabe8a4c55a9fc3fef627307629d548920 | |
| parent | 58b54e9279a0fef211003c94735ca9024bde72ee (diff) | |
| download | qxmpp-f4dbb00a035eb4df8a12f5edaf53bb99a2bd435a.tar.gz | |
move server tests
| -rw-r--r-- | tests/all/tests.cpp | 110 | ||||
| -rw-r--r-- | tests/all/tests.h | 8 | ||||
| -rw-r--r-- | tests/qxmppserver/qxmppserver.pro | 3 | ||||
| -rw-r--r-- | tests/qxmppserver/tst_qxmppserver.cpp | 138 | ||||
| -rw-r--r-- | tests/tests.pro | 1 |
5 files changed, 142 insertions, 118 deletions
diff --git a/tests/all/tests.cpp b/tests/all/tests.cpp index f191dfde..322085e5 100644 --- a/tests/all/tests.cpp +++ b/tests/all/tests.cpp @@ -25,19 +25,14 @@ #include <cstdlib> #include <QCoreApplication> -#include <QDomDocument> -#include <QEventLoop> #include <QtTest> #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" @@ -666,112 +661,10 @@ void TestPubSub::testSubscriptions() 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<QString>("username"); - QTest::addColumn<QString>("password"); - QTest::addColumn<QString>("mechanism"); - QTest::addColumn<bool>("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; @@ -781,9 +674,6 @@ int main(int argc, char *argv[]) TestPubSub testPubSub; errors += QTest::qExec(&testPubSub); - TestServer testServer; - errors += QTest::qExec(&testServer); - if (errors) { qWarning() << "Total failed tests:" << errors; diff --git a/tests/all/tests.h b/tests/all/tests.h index fe928346..3bc8ad1e 100644 --- a/tests/all/tests.h +++ b/tests/all/tests.h @@ -63,11 +63,3 @@ private slots: void testSubscriptions(); }; -class TestServer : public QObject -{ - Q_OBJECT - -private slots: - void testConnect_data(); - void testConnect(); -}; diff --git a/tests/qxmppserver/qxmppserver.pro b/tests/qxmppserver/qxmppserver.pro new file mode 100644 index 00000000..1ddd94a6 --- /dev/null +++ b/tests/qxmppserver/qxmppserver.pro @@ -0,0 +1,3 @@ +include(../tests.pri) +TARGET = tst_qxmppserver +SOURCES += tst_qxmppserver.cpp diff --git a/tests/qxmppserver/tst_qxmppserver.cpp b/tests/qxmppserver/tst_qxmppserver.cpp new file mode 100644 index 00000000..9c60d089 --- /dev/null +++ b/tests/qxmppserver/tst_qxmppserver.cpp @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2008-2012 The QXmpp developers + * + * Author: + * Jeremy Lainé + * + * 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 "QXmppClient.h" +#include "QXmppPasswordChecker.h" +#include "QXmppServer.h" +#include "util.h" + +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; +}; + +class TestServer : public QObject +{ + Q_OBJECT + +private slots: + void testConnect_data(); + void testConnect(); +}; + +void TestServer::testConnect_data() +{ + QTest::addColumn<QString>("username"); + QTest::addColumn<QString>("password"); + QTest::addColumn<QString>("mechanism"); + QTest::addColumn<bool>("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); +} + +QTEST_MAIN(TestServer) +#include "tst_qxmppserver.moc" diff --git a/tests/tests.pro b/tests/tests.pro index 7bfeba14..d356fbcf 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -11,6 +11,7 @@ SUBDIRS = \ qxmpprosteriq \ qxmpprpciq \ qxmpprtppacket \ + qxmppserver \ qxmppstanza \ qxmppstunmessage \ qxmpputils \ |
