summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesus Fernandez <jesus.fernandez@qt.io>2018-08-14 16:17:12 +0200
committerJesus Fernandez <Jesus.Fernandez@qt.io>2018-08-16 11:51:44 +0000
commit39a0e9bb5a3e87522bfe4a3107560fd6ef7632b4 (patch)
tree00e15e813921e4de4d9a131cc59481b57aa8485f
parent49c06eadaada1e040d78d353ad42ad19ad86d3d3 (diff)
downloadqtwebsockets-39a0e9bb5a3e87522bfe4a3107560fd6ef7632b4.tar.gz
Refactor manual test
Rewrite a manual test to be data-driven, rather than clumsily recursive. Modernise and tidy the code in the process. Change-Id: I11919adf1bceaec831b8573bd1194fb2ab15297d Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
-rw-r--r--tests/manual/compliance/tst_compliance.cpp136
1 files changed, 47 insertions, 89 deletions
diff --git a/tests/manual/compliance/tst_compliance.cpp b/tests/manual/compliance/tst_compliance.cpp
index ffb4b06..8ef3c14 100644
--- a/tests/manual/compliance/tst_compliance.cpp
+++ b/tests/manual/compliance/tst_compliance.cpp
@@ -37,116 +37,74 @@ class tst_ComplianceTest : public QObject
{
Q_OBJECT
-public:
- tst_ComplianceTest();
-
private Q_SLOTS:
- void initTestCase();
void cleanupTestCase();
- void init();
- void cleanup();
- /**
- * @brief Runs the autobahn tests against our implementation
- */
- void autobahnTest();
-
-private:
- QUrl m_url;
- void runTestCases(int startNbr, int stopNbr = -1);
- void runTestCase(int nbr, int total);
+ void autobahnTest_data();
+ void autobahnTest();
};
-tst_ComplianceTest::tst_ComplianceTest() :
- m_url("ws://localhost:9001")
-{
-}
-
-void tst_ComplianceTest::initTestCase()
-{
-}
+static const QUrl baseUrl { "ws://localhost:9001" };
+static const auto agent = QStringLiteral("QtWebSockets/" QT_VERSION_STR);
void tst_ComplianceTest::cleanupTestCase()
{
-}
-
-void tst_ComplianceTest::init()
-{
-}
-
-void tst_ComplianceTest::cleanup()
-{
-}
-
-void tst_ComplianceTest::runTestCase(int nbr, int total)
-{
- if (nbr == total)
- {
- return;
- }
-
- QWebSocket *pWebSocket = new QWebSocket;
- QSignalSpy spy(pWebSocket, SIGNAL(disconnected()));
-
- //next for every case, connect to url
- //ws://ipaddress:port/runCase?case=<number>&agent=<agentname>
- //where agent name will be QWebSocket
- QObject::connect(pWebSocket, &QWebSocket::textMessageReceived, [=](QString message) {
- pWebSocket->sendTextMessage(message);
- });
- QObject::connect(pWebSocket, &QWebSocket::binaryMessageReceived, [=](QByteArray message) {
- pWebSocket->sendBinaryMessage(message);
- });
-
- qDebug() << "Executing test" << (nbr + 1) << "/" << total;
- QUrl url = m_url;
- url.setPath(QStringLiteral("/runCase"));
+ QWebSocket webSocket;
+ QSignalSpy spy(&webSocket, &QWebSocket::disconnected);
+ auto url = baseUrl;
+ url.setPath(QStringLiteral("/updateReports"));
QUrlQuery query;
- query.addQueryItem(QStringLiteral("case"), QString::number(nbr + 1));
- query.addQueryItem(QStringLiteral("agent"), QStringLiteral("QtWebSockets/1.0"));
+ query.addQueryItem(QStringLiteral("agent"), agent);
url.setQuery(query);
- pWebSocket->open(url);
- spy.wait(60000);
- pWebSocket->close();
- delete pWebSocket;
- pWebSocket = nullptr;
- runTestCase(nbr + 1, total);
-}
-
-void tst_ComplianceTest::runTestCases(int startNbr, int stopNbr)
-{
- runTestCase(startNbr, stopNbr);
+ webSocket.open(url);
+ QVERIFY(spy.wait());
}
-void tst_ComplianceTest::autobahnTest()
+void tst_ComplianceTest::autobahnTest_data()
{
- //connect to autobahn server at url ws://ipaddress:port/getCaseCount
- QWebSocket *pWebSocket = new QWebSocket;
- QUrl url = m_url;
- int numberOfTestCases = 0;
- QSignalSpy spy(pWebSocket, SIGNAL(disconnected()));
- QObject::connect(pWebSocket, &QWebSocket::textMessageReceived, [&](QString message) {
- numberOfTestCases = message.toInt();
+ QTest::addColumn<int>("testCase");
+
+ // Ask /getCaseCount how many tests we have
+ QWebSocket webSocket;
+ QSignalSpy spy(&webSocket, &QWebSocket::disconnected);
+
+ connect(&webSocket, &QWebSocket::textMessageReceived, [](QString message) {
+ bool ok;
+ const auto numberOfTestCases = message.toInt(&ok);
+ if (!ok)
+ QSKIP("Unable to parse /getCaseCount result");
+ for (auto i = 1; i <= numberOfTestCases; ++i)
+ QTest::addRow("%d", i) << i;
});
+ auto url = baseUrl;
url.setPath(QStringLiteral("/getCaseCount"));
- pWebSocket->open(url);
- spy.wait(60000);
- QVERIFY(numberOfTestCases > 0);
-
- QObject::disconnect(pWebSocket, &QWebSocket::textMessageReceived, nullptr, nullptr);
- runTestCases(0, numberOfTestCases);
+ webSocket.open(url);
+ if (!spy.wait())
+ QSKIP("AutoBahn test server didn't deliver case-count");
+}
- url.setPath(QStringLiteral("/updateReports"));
+void tst_ComplianceTest::autobahnTest()
+{
+ QFETCH(int, testCase);
+ QWebSocket webSocket;
+ QSignalSpy spy(&webSocket, &QWebSocket::disconnected);
+ connect(&webSocket, &QWebSocket::textMessageReceived,
+ &webSocket, &QWebSocket::sendTextMessage);
+ connect(&webSocket, &QWebSocket::binaryMessageReceived,
+ &webSocket, &QWebSocket::sendBinaryMessage);
+
+ // Ask /runCase?case=<number>&agent=<agent> to run the test-case.
+ auto url = baseUrl;
+ url.setPath(QStringLiteral("/runCase"));
QUrlQuery query;
- query.addQueryItem(QStringLiteral("agent"), QStringLiteral("QtWebSockets"));
+ query.addQueryItem(QStringLiteral("case"), QString::number(testCase));
+ query.addQueryItem(QStringLiteral("agent"), agent);
url.setQuery(query);
- pWebSocket->open(url);
- spy.wait(60000);
- delete pWebSocket;
+ webSocket.open(url);
+ QVERIFY(spy.wait());
}
QTEST_MAIN(tst_ComplianceTest)
#include "tst_compliance.moc"
-