summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKurt Pattyn <pattyn.kurt@gmail.com>2013-10-12 21:02:02 +0200
committerKurt Pattyn <pattyn.kurt@gmail.com>2013-10-13 12:25:44 +0200
commitd3d89a966401bad131bbab6b2c8a33655ac9514e (patch)
tree8ce14ce1aca92349d806f981958057f4f6f3e4cb /tests
parent7d27956893423e0447aedaa0038bf38e5725ddfd (diff)
downloadqtwebsockets-d3d89a966401bad131bbab6b2c8a33655ac9514e.tar.gz
Added unittests for QWebSocketProtocol
Added copyright headers Change-Id: Idef8307ef80db9e5805b880514bd3a9c18ddf125 Reviewed-by: Kurt Pattyn <pattyn.kurt@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/auto.pro3
-rw-r--r--tests/auto/dataprocessor/tst_dataprocessor.cpp40
-rw-r--r--tests/auto/websocketprotocol/tst_websocketprotocol.cpp204
-rw-r--r--tests/auto/websocketprotocol/websocketprotocol.pro15
4 files changed, 261 insertions, 1 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index a203896..c4d88b6 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -3,4 +3,5 @@ TEMPLATE = subdirs
SUBDIRS += \
contains(QT_CONFIG, private_tests): SUBDIRS += \
- dataprocessor
+ dataprocessor \
+ websocketprotocol
diff --git a/tests/auto/dataprocessor/tst_dataprocessor.cpp b/tests/auto/dataprocessor/tst_dataprocessor.cpp
index 4fd14fe..297bd42 100644
--- a/tests/auto/dataprocessor/tst_dataprocessor.cpp
+++ b/tests/auto/dataprocessor/tst_dataprocessor.cpp
@@ -1,3 +1,43 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
#include <QtTest/QtTest>
#include <QtTest/qtestcase.h>
#include <QSignalSpy>
diff --git a/tests/auto/websocketprotocol/tst_websocketprotocol.cpp b/tests/auto/websocketprotocol/tst_websocketprotocol.cpp
new file mode 100644
index 0000000..fdf6516
--- /dev/null
+++ b/tests/auto/websocketprotocol/tst_websocketprotocol.cpp
@@ -0,0 +1,204 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QtTest/QtTest>
+#include <QtTest/qtestcase.h>
+#include <QDebug>
+
+#include "qwebsocketprotocol.h"
+
+Q_DECLARE_METATYPE(QWebSocketProtocol::CloseCode)
+Q_DECLARE_METATYPE(QWebSocketProtocol::OpCode)
+
+QT_USE_NAMESPACE
+
+class tst_WebSocketProtocol : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_WebSocketProtocol();
+
+private Q_SLOTS:
+ void initTestCase();
+ void cleanupTestCase();
+ void init();
+ void cleanup();
+
+ void tst_validMasks_data();
+ void tst_validMasks();
+
+ void tst_opCodes_data();
+ void tst_opCodes();
+
+ void tst_closeCodes_data();
+ void tst_closeCodes();
+};
+
+tst_WebSocketProtocol::tst_WebSocketProtocol()
+{}
+
+void tst_WebSocketProtocol::initTestCase()
+{
+}
+
+void tst_WebSocketProtocol::cleanupTestCase()
+{}
+
+void tst_WebSocketProtocol::init()
+{
+ qRegisterMetaType<QWebSocketProtocol::OpCode>("QWebSocketProtocol::OpCode");
+ qRegisterMetaType<QWebSocketProtocol::CloseCode>("QWebSocketProtocol::CloseCode");
+}
+
+void tst_WebSocketProtocol::cleanup()
+{
+}
+
+void tst_WebSocketProtocol::tst_validMasks_data()
+{
+ QTest::addColumn<quint32>("mask");
+ QTest::addColumn<QString>("inputdata");
+ QTest::addColumn<QByteArray>("result");
+
+ QTest::newRow("Empty payload") << 0x12345678u << QString("") << QByteArray("");
+ QTest::newRow("ASCII payload of 8 characters") << 0x12345678u << QString("abcdefgh") << QByteArray("\x19\x34\x57\x76\x1D\x30\x53\x7A");
+ QTest::newRow("ASCII payload of 9 characters") << 0x12345678u << QString("abcdefghi") << QByteArray("\x19\x34\x57\x76\x1D\x30\x53\x7A\x11");
+ QTest::newRow("UTF-8 payload") << 0x12345678u << QString("∫∂ƒ©øØ") << QByteArray("\x47\x69\x0B\xBB\x80\x8E");
+}
+
+void tst_WebSocketProtocol::tst_validMasks()
+{
+ QFETCH(quint32, mask);
+ QFETCH(QString, inputdata);
+ QFETCH(QByteArray, result);
+
+ char *data = inputdata.toLatin1().data();
+
+ QWebSocketProtocol::mask(data, inputdata.size(), mask);
+ QCOMPARE(QByteArray::fromRawData(data, inputdata.size()), result);
+}
+
+void tst_WebSocketProtocol::tst_opCodes_data()
+{
+ QTest::addColumn<QWebSocketProtocol::OpCode>("opCode");
+ QTest::addColumn<bool>("isReserved");
+
+ QTest::newRow("OC_BINARY") << QWebSocketProtocol::OC_BINARY << false;
+ QTest::newRow("OC_CLOSE") << QWebSocketProtocol::OC_CLOSE << false;
+ QTest::newRow("OC_CONTINUE") << QWebSocketProtocol::OC_CONTINUE << false;
+ QTest::newRow("OC_PING") << QWebSocketProtocol::OC_PING << false;
+ QTest::newRow("OC_PONG") << QWebSocketProtocol::OC_PONG << false;
+ QTest::newRow("OC_RESERVED3") << QWebSocketProtocol::OC_RESERVED_3 << true;
+ QTest::newRow("OC_RESERVED4") << QWebSocketProtocol::OC_RESERVED_4 << true;
+ QTest::newRow("OC_RESERVED5") << QWebSocketProtocol::OC_RESERVED_5 << true;
+ QTest::newRow("OC_RESERVED6") << QWebSocketProtocol::OC_RESERVED_6 << true;
+ QTest::newRow("OC_RESERVED7") << QWebSocketProtocol::OC_RESERVED_7 << true;
+ QTest::newRow("OC_RESERVEDB") << QWebSocketProtocol::OC_RESERVED_B << true;
+ QTest::newRow("OC_RESERVEDC") << QWebSocketProtocol::OC_RESERVED_C << true;
+ QTest::newRow("OC_RESERVEDD") << QWebSocketProtocol::OC_RESERVED_D << true;
+ QTest::newRow("OC_RESERVEDE") << QWebSocketProtocol::OC_RESERVED_E << true;
+ QTest::newRow("OC_RESERVEDF") << QWebSocketProtocol::OC_RESERVED_F << true;
+ QTest::newRow("OC_TEXT") << QWebSocketProtocol::OC_TEXT << false;
+}
+
+void tst_WebSocketProtocol::tst_opCodes()
+{
+ QFETCH(QWebSocketProtocol::OpCode, opCode);
+ QFETCH(bool, isReserved);
+
+ bool result = QWebSocketProtocol::isOpCodeReserved(opCode);
+
+ QCOMPARE(result, isReserved);
+}
+
+void tst_WebSocketProtocol::tst_closeCodes_data()
+{
+ QTest::addColumn<int>("closeCode");
+ QTest::addColumn<bool>("isValid");
+
+ for (int i = 0; i < 1000; ++i)
+ {
+ QTest::newRow(QString("Close code %1").arg(i).toLatin1().constData()) << i << false;
+ }
+
+ for (int i = 1000; i < 1004; ++i)
+ {
+ QTest::newRow(QString("Close code %1").arg(i).toLatin1().constData()) << i << true;
+ }
+
+ QTest::newRow("Close code 1004") << 1004 << false;
+ QTest::newRow("Close code 1005") << 1005 << false;
+ QTest::newRow("Close code 1006") << 1006 << false;
+
+ for (int i = 1007; i < 1012; ++i)
+ {
+ QTest::newRow(QString("Close code %1").arg(i).toLatin1().constData()) << i << true;
+ }
+
+ for (int i = 1013; i < 3000; ++i)
+ {
+ QTest::newRow(QString("Close code %1").arg(i).toLatin1().constData()) << i << false;
+ }
+
+ for (int i = 3000; i < 5000; ++i)
+ {
+ QTest::newRow(QString("Close code %1").arg(i).toLatin1().constData()) << i << true;
+ }
+
+ QTest::newRow("Close code 5000") << 1004 << false;
+ QTest::newRow("Close code 6000") << 1004 << false;
+ QTest::newRow("Close code 7000") << 1004 << false;
+}
+
+void tst_WebSocketProtocol::tst_closeCodes()
+{
+ QFETCH(int, closeCode);
+ QFETCH(bool, isValid);
+
+ bool result = QWebSocketProtocol::isCloseCodeValid(closeCode);
+
+ QCOMPARE(result, isValid);
+}
+
+QTEST_MAIN(tst_WebSocketProtocol)
+
+#include "tst_websocketprotocol.moc"
+
diff --git a/tests/auto/websocketprotocol/websocketprotocol.pro b/tests/auto/websocketprotocol/websocketprotocol.pro
new file mode 100644
index 0000000..bb0ab3b
--- /dev/null
+++ b/tests/auto/websocketprotocol/websocketprotocol.pro
@@ -0,0 +1,15 @@
+CONFIG += console
+CONFIG += c++11
+CONFIG += testcase
+CONFIG -= app_bundle
+
+TEMPLATE = app
+
+TARGET = tst_websocketprotocol
+
+QT = core testlib websockets websockets-private
+
+SOURCES += tst_websocketprotocol.cpp
+
+requires(contains(QT_CONFIG, private_tests))
+DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0