1 /****************************************************************************
3 ** Copyright (C) 2014 Kurt Pattyn <pattyn.kurt@gmail.com>.
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtWebSockets module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL21$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
26 ** In addition, as a special exception, Digia gives you certain additional
27 ** rights. These rights are described in the Digia Qt LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
32 ****************************************************************************/
33 #include <QtTest/QtTest>
34 #include <QtTest/qtestcase.h>
39 #include <QtWebSockets/QWebSocket>
41 class tst_ComplianceTest : public QObject
50 void cleanupTestCase();
54 * @brief Runs the autobahn tests against our implementation
61 void runTestCases(int startNbr, int stopNbr = -1);
62 void runTestCase(int nbr, int total);
65 tst_ComplianceTest::tst_ComplianceTest() :
66 m_url("ws://localhost:9001")
70 void tst_ComplianceTest::initTestCase()
74 void tst_ComplianceTest::cleanupTestCase()
78 void tst_ComplianceTest::init()
82 void tst_ComplianceTest::cleanup()
86 void tst_ComplianceTest::runTestCase(int nbr, int total)
93 QWebSocket *pWebSocket = new QWebSocket;
94 QSignalSpy spy(pWebSocket, SIGNAL(disconnected()));
96 //next for every case, connect to url
97 //ws://ipaddress:port/runCase?case=<number>&agent=<agentname>
98 //where agent name will be QWebSocket
99 QObject::connect(pWebSocket, &QWebSocket::textMessageReceived, [=](QString message) {
100 pWebSocket->sendTextMessage(message);
102 QObject::connect(pWebSocket, &QWebSocket::binaryMessageReceived, [=](QByteArray message) {
103 pWebSocket->sendBinaryMessage(message);
106 qDebug() << "Executing test" << (nbr + 1) << "/" << total;
108 url.setPath(QStringLiteral("/runCase?"));
110 query.addQueryItem(QStringLiteral("case"), QString::number(nbr + 1));
111 query.addQueryItem(QStringLiteral("agent"), QStringLiteral("QtWebSockets/1.0"));
113 pWebSocket->open(url);
117 pWebSocket = Q_NULLPTR;
118 runTestCase(nbr + 1, total);
121 void tst_ComplianceTest::runTestCases(int startNbr, int stopNbr)
123 runTestCase(startNbr, stopNbr);
126 void tst_ComplianceTest::autobahnTest()
128 //connect to autobahn server at url ws://ipaddress:port/getCaseCount
129 QWebSocket *pWebSocket = new QWebSocket;
131 int numberOfTestCases = 0;
132 QSignalSpy spy(pWebSocket, SIGNAL(disconnected()));
133 QObject::connect(pWebSocket, &QWebSocket::textMessageReceived, [&](QString message) {
134 numberOfTestCases = message.toInt();
137 url.setPath(QStringLiteral("/getCaseCount"));
138 pWebSocket->open(url);
140 QVERIFY(numberOfTestCases > 0);
142 QObject::disconnect(pWebSocket, &QWebSocket::textMessageReceived, 0, 0);
143 runTestCases(0, numberOfTestCases);
145 url.setPath(QStringLiteral("/updateReports?"));
147 query.addQueryItem(QStringLiteral("agent"), QStringLiteral("QtWebSockets"));
149 pWebSocket->open(url);
154 QTEST_MAIN(tst_ComplianceTest)
156 #include "tst_compliance.moc"