summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/websockets/qwebsockethandshakerequest.cpp1
-rw-r--r--src/websockets/qwebsocketprotocol.h2
-rw-r--r--src/websockets/qwebsocketprotocol_p.h1
-rw-r--r--tests/auto/websocketprotocol/tst_websocketprotocol.cpp77
4 files changed, 78 insertions, 3 deletions
diff --git a/src/websockets/qwebsockethandshakerequest.cpp b/src/websockets/qwebsockethandshakerequest.cpp
index c47dfd0..5d6e827 100644
--- a/src/websockets/qwebsockethandshakerequest.cpp
+++ b/src/websockets/qwebsockethandshakerequest.cpp
@@ -41,6 +41,7 @@
#include "qwebsockethandshakerequest_p.h"
#include "qwebsocketprotocol.h"
+#include "qwebsocketprotocol_p.h"
#include <QtCore/QString>
#include <QtCore/QMap>
diff --git a/src/websockets/qwebsocketprotocol.h b/src/websockets/qwebsocketprotocol.h
index 1affc76..a7cb1ff 100644
--- a/src/websockets/qwebsocketprotocol.h
+++ b/src/websockets/qwebsocketprotocol.h
@@ -65,8 +65,6 @@ enum Version
VersionLatest = Version13
};
-Version versionFromString(const QString &versionString);
-
enum CloseCode
{
CloseCodeNormal = 1000,
diff --git a/src/websockets/qwebsocketprotocol_p.h b/src/websockets/qwebsocketprotocol_p.h
index 4ce51b5..8850c4d 100644
--- a/src/websockets/qwebsocketprotocol_p.h
+++ b/src/websockets/qwebsocketprotocol_p.h
@@ -87,6 +87,7 @@ inline bool isCloseCodeValid(int closeCode)
}
inline Version currentVersion() { return VersionLatest; }
+Version versionFromString(const QString &versionString);
void Q_AUTOTEST_EXPORT mask(QByteArray *payload, quint32 maskingKey);
void Q_AUTOTEST_EXPORT mask(char *payload, quint64 size, quint32 maskingKey);
diff --git a/tests/auto/websocketprotocol/tst_websocketprotocol.cpp b/tests/auto/websocketprotocol/tst_websocketprotocol.cpp
index eea434b..b8948d5 100644
--- a/tests/auto/websocketprotocol/tst_websocketprotocol.cpp
+++ b/tests/auto/websocketprotocol/tst_websocketprotocol.cpp
@@ -44,7 +44,7 @@
#include <QDebug>
-#include "qwebsocketprotocol.h"
+#include "QtWebSockets/qwebsocketprotocol.h"
#include "private/qwebsocketprotocol_p.h"
QT_USE_NAMESPACE
@@ -73,6 +73,9 @@ private Q_SLOTS:
void tst_closeCodes_data();
void tst_closeCodes();
+
+ void tst_versionFromString_data();
+ void tst_versionFromString();
};
tst_WebSocketProtocol::tst_WebSocketProtocol()
@@ -215,6 +218,78 @@ void tst_WebSocketProtocol::tst_closeCodes()
QCOMPARE(result, isValid);
}
+void tst_WebSocketProtocol::tst_versionFromString_data()
+{
+ QTest::addColumn<QWebSocketProtocol::Version>("version");
+ QTest::addColumn<QString>("versionString");
+
+ //happy flow; good data
+ QTest::newRow("Version 0")
+ << QWebSocketProtocol::Version0
+ << QStringLiteral("0");
+ QTest::newRow("Version 4")
+ << QWebSocketProtocol::Version4
+ << QStringLiteral("4");
+ QTest::newRow("Version 5")
+ << QWebSocketProtocol::Version5
+ << QStringLiteral("5");
+ QTest::newRow("Version 6")
+ << QWebSocketProtocol::Version6
+ << QStringLiteral("6");
+ QTest::newRow("Version 7")
+ << QWebSocketProtocol::Version7
+ << QStringLiteral("7");
+ QTest::newRow("Version 8")
+ << QWebSocketProtocol::Version8
+ << QStringLiteral("8");
+ QTest::newRow("Version 13")
+ << QWebSocketProtocol::Version13
+ << QStringLiteral("13");
+
+ //rainy flow; invalid data
+ QTest::newRow("Version -1")
+ << QWebSocketProtocol::VersionUnknown
+ << QStringLiteral("-1");
+ QTest::newRow("Version 1")
+ << QWebSocketProtocol::VersionUnknown
+ << QStringLiteral("1");
+ QTest::newRow("Version 2")
+ << QWebSocketProtocol::VersionUnknown
+ << QStringLiteral("2");
+ QTest::newRow("Version 3")
+ << QWebSocketProtocol::VersionUnknown
+ << QStringLiteral("3");
+ QTest::newRow("Version 9")
+ << QWebSocketProtocol::VersionUnknown
+ << QStringLiteral("9");
+ QTest::newRow("Version 10")
+ << QWebSocketProtocol::VersionUnknown
+ << QStringLiteral("10");
+ QTest::newRow("Version 11")
+ << QWebSocketProtocol::VersionUnknown
+ << QStringLiteral("11");
+ QTest::newRow("Version 12")
+ << QWebSocketProtocol::VersionUnknown
+ << QStringLiteral("12");
+ QTest::newRow("Version abcd")
+ << QWebSocketProtocol::VersionUnknown
+ << QStringLiteral("abcd");
+ QTest::newRow("Version 1.6")
+ << QWebSocketProtocol::VersionUnknown
+ << QStringLiteral("1.6");
+ QTest::newRow("Version empty")
+ << QWebSocketProtocol::VersionUnknown
+ << QString();
+}
+
+void tst_WebSocketProtocol::tst_versionFromString()
+{
+ QFETCH(QWebSocketProtocol::Version, version);
+ QFETCH(QString, versionString);
+
+ QCOMPARE(QWebSocketProtocol::versionFromString(versionString), version);
+}
+
QTEST_MAIN(tst_WebSocketProtocol)
#include "tst_websocketprotocol.moc"