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:LGPL$
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 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
41 #include <QtTest/QtTest>
42 #include <QtTest/qtestcase.h>
47 #include <QtWebSockets/QWebSocket>
49 class tst_ComplianceTest : public QObject
58 void cleanupTestCase();
62 * @brief Runs the autobahn tests against our implementation
69 void runTestCases(int startNbr, int stopNbr = -1);
70 void runTestCase(int nbr, int total);
73 tst_ComplianceTest::tst_ComplianceTest() :
74 m_url("ws://localhost:9001")
78 void tst_ComplianceTest::initTestCase()
82 void tst_ComplianceTest::cleanupTestCase()
86 void tst_ComplianceTest::init()
90 void tst_ComplianceTest::cleanup()
94 void tst_ComplianceTest::runTestCase(int nbr, int total)
101 QWebSocket *pWebSocket = new QWebSocket;
102 QSignalSpy spy(pWebSocket, SIGNAL(disconnected()));
104 //next for every case, connect to url
105 //ws://ipaddress:port/runCase?case=<number>&agent=<agentname>
106 //where agent name will be QWebSocket
107 QObject::connect(pWebSocket, &QWebSocket::textMessageReceived, [=](QString message) {
108 pWebSocket->sendTextMessage(message);
110 QObject::connect(pWebSocket, &QWebSocket::binaryMessageReceived, [=](QByteArray message) {
111 pWebSocket->sendBinaryMessage(message);
114 qDebug() << "Executing test" << (nbr + 1) << "/" << total;
116 url.setPath(QStringLiteral("/runCase?"));
118 query.addQueryItem(QStringLiteral("case"), QString::number(nbr + 1));
119 query.addQueryItem(QStringLiteral("agent"), QStringLiteral("QtWebSockets/1.0"));
121 pWebSocket->open(url);
125 pWebSocket = Q_NULLPTR;
126 runTestCase(nbr + 1, total);
129 void tst_ComplianceTest::runTestCases(int startNbr, int stopNbr)
131 runTestCase(startNbr, stopNbr);
134 void tst_ComplianceTest::autobahnTest()
136 //connect to autobahn server at url ws://ipaddress:port/getCaseCount
137 QWebSocket *pWebSocket = new QWebSocket;
139 int numberOfTestCases = 0;
140 QSignalSpy spy(pWebSocket, SIGNAL(disconnected()));
141 QObject::connect(pWebSocket, &QWebSocket::textMessageReceived, [&](QString message) {
142 numberOfTestCases = message.toInt();
145 url.setPath(QStringLiteral("/getCaseCount"));
146 pWebSocket->open(url);
148 QVERIFY(numberOfTestCases > 0);
150 QObject::disconnect(pWebSocket, &QWebSocket::textMessageReceived, 0, 0);
151 runTestCases(0, numberOfTestCases);
153 url.setPath(QStringLiteral("/updateReports?"));
155 query.addQueryItem(QStringLiteral("agent"), QStringLiteral("QtWebSockets"));
157 pWebSocket->open(url);
162 QTEST_MAIN(tst_ComplianceTest)
164 #include "tst_compliance.moc"