aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2015-07-27 10:17:23 +0200
committerJeremy Lainé <jeremy.laine@m4x.org>2015-07-27 10:17:23 +0200
commit327e5060cbcb85ed26931136bb62731bb15dc5ab (patch)
tree4b23bd84358c2ea7b5a2832bd97b9f80210f4318 /tests
parent350b0db6c8a51ee500d3ba2d40dd421f5cf86494 (diff)
downloadqxmpp-327e5060cbcb85ed26931136bb62731bb15dc5ab.tar.gz
add some tests for QXmppSocksServer
Diffstat (limited to 'tests')
-rw-r--r--tests/qxmppsocks/qxmppsocks.pro3
-rw-r--r--tests/qxmppsocks/tst_qxmppsocks.cpp122
-rw-r--r--tests/tests.pro1
3 files changed, 126 insertions, 0 deletions
diff --git a/tests/qxmppsocks/qxmppsocks.pro b/tests/qxmppsocks/qxmppsocks.pro
new file mode 100644
index 00000000..fed3fa2e
--- /dev/null
+++ b/tests/qxmppsocks/qxmppsocks.pro
@@ -0,0 +1,3 @@
+include(../tests.pri)
+TARGET = tst_qxmppsocks
+SOURCES += tst_qxmppsocks.cpp
diff --git a/tests/qxmppsocks/tst_qxmppsocks.cpp b/tests/qxmppsocks/tst_qxmppsocks.cpp
new file mode 100644
index 00000000..2a24c524
--- /dev/null
+++ b/tests/qxmppsocks/tst_qxmppsocks.cpp
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2008-2014 The QXmpp developers
+ *
+ * Author:
+ * Jeremy Lainé
+ *
+ * Source:
+ * https://github.com/qxmpp-project/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 <QTcpSocket>
+#include "QXmppSocks.h"
+#include "util.h"
+
+class tst_QXmppSocks : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void init();
+ void newConnectionSlot(QTcpSocket *socket, QString hostName, quint16 port);
+
+ void testClientAndServer();
+ void testServer();
+
+private:
+ QTcpSocket *m_connectionSocket;
+ QString m_connectionHostName;
+ quint16 m_connectionPort;
+};
+
+void tst_QXmppSocks::init()
+{
+ m_connectionSocket = 0;
+ m_connectionHostName = QString();
+ m_connectionPort = 0;
+}
+
+void tst_QXmppSocks::newConnectionSlot(QTcpSocket *socket, QString hostName, quint16 port)
+{
+ m_connectionSocket = socket;
+ m_connectionHostName = hostName;
+ m_connectionPort = port;
+}
+
+void tst_QXmppSocks::testClientAndServer()
+{
+ QXmppSocksServer server;
+ QVERIFY(server.listen(1080));
+ QVERIFY(server.serverPort() != 0);
+ connect(&server, SIGNAL(newConnection(QTcpSocket*,QString,quint16)),
+ this, SLOT(newConnectionSlot(QTcpSocket*,QString,quint16)));
+
+ QXmppSocksClient client("127.0.0.1", server.serverPort());
+
+ QEventLoop loop;
+ connect(&client, SIGNAL(ready()), &loop, SLOT(quit()));
+
+ client.connectToHost("www.google.com", 80);
+ loop.exec();
+
+ // check server
+ QVERIFY(m_connectionSocket);
+ QCOMPARE(m_connectionSocket->state(), QAbstractSocket::ConnectedState);
+ QCOMPARE(m_connectionHostName, QLatin1String("www.google.com"));
+ QCOMPARE(m_connectionPort, quint16(80));
+
+ // disconnect
+ client.disconnectFromHost();
+}
+
+
+void tst_QXmppSocks::testServer()
+{
+ QXmppSocksServer server;
+ QVERIFY(server.listen());
+ QVERIFY(server.serverPort() != 0);
+ connect(&server, SIGNAL(newConnection(QTcpSocket*,QString,quint16)),
+ this, SLOT(newConnectionSlot(QTcpSocket*,QString,quint16)));
+
+ QTcpSocket client;
+ client.connectToHost(QHostAddress::LocalHost, server.serverPort());
+ QVERIFY2(client.waitForConnected(), qPrintable(client.errorString()));
+
+ QEventLoop loop;
+ connect(&client, SIGNAL(readyRead()), &loop, SLOT(quit()));
+
+ // SOCKS5, no authentication
+ client.write(QByteArray::fromHex("050100"));
+ loop.exec();
+ QCOMPARE(client.readAll(), QByteArray::fromHex("0500"));
+
+ // request connect to www.google.com port 80
+ client.write(QByteArray::fromHex("050100030e7777772e676f6f676c652e636f6d0050"));
+ loop.exec();
+ QCOMPARE(client.readAll(), QByteArray::fromHex("050000030e7777772e676f6f676c652e636f6d0050"));
+
+ // check server
+ QVERIFY(m_connectionSocket);
+ QCOMPARE(m_connectionSocket->state(), QAbstractSocket::ConnectedState);
+ QCOMPARE(m_connectionHostName, QLatin1String("www.google.com"));
+ QCOMPARE(m_connectionPort, quint16(80));
+
+ // disconnect
+ client.disconnectFromHost();
+}
+
+QTEST_MAIN(tst_QXmppSocks)
+#include "tst_qxmppsocks.moc"
diff --git a/tests/tests.pro b/tests/tests.pro
index e6cc6e21..381df555 100644
--- a/tests/tests.pro
+++ b/tests/tests.pro
@@ -18,6 +18,7 @@ SUBDIRS = \
qxmpprtppacket \
qxmppserver \
qxmppsessioniq \
+ qxmppsocks \
qxmppstanza \
qxmppstreamfeatures \
qxmppstunmessage \