qDebug() << "Websocket connected";
connect(&m_webSocket, &QWebSocket::textMessageReceived,
this, &EchoClient::onTextMessageReceived);
- qint64 bytesWritten = m_webSocket.write("Hello, world!");
+ qint64 bytesWritten = m_webSocket.write(QStringLiteral("Hello, world!"));
Q_UNUSED(bytesWritten);
}
//! [onConnected]
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
- EchoClient client(QUrl("ws://localhost:1234"));
+ EchoClient client(QUrl(QStringLiteral("ws://localhost:1234")));
QObject::connect(&client, &EchoClient::closed, &a, &QCoreApplication::quit);
Q_UNUSED(client);
m_pWebSocketServer(Q_NULLPTR),
m_clients()
{
- m_pWebSocketServer = new QWebSocketServer("Chat Server", QWebSocketServer::SecureModeNonSecure,
+ m_pWebSocketServer = new QWebSocketServer(QStringLiteral("Chat Server"),
+ QWebSocketServer::SecureModeNonSecure,
this);
if (m_pWebSocketServer->listen(QHostAddress::Any, port))
{
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
- SslEchoClient client(QUrl("wss://localhost:1234"));
+ SslEchoClient client(QUrl(QStringLiteral("wss://localhost:1234")));
Q_UNUSED(client);
qDebug() << "Websocket connected";
connect(&m_webSocket, &QWebSocket::textMessageReceived,
this, &SslEchoClient::onTextMessageReceived);
- qint64 bytesWritten = m_webSocket.write("Hello, world!");
+ qint64 bytesWritten = m_webSocket.write(QStringLiteral("Hello, world!"));
Q_UNUSED(bytesWritten);
}
//! [onConnected]
m_pWebSocketServer(Q_NULLPTR),
m_clients()
{
- m_pWebSocketServer = new QWebSocketServer("SSL Echo Server", QWebSocketServer::SecureModeSecure,
+ m_pWebSocketServer = new QWebSocketServer(QStringLiteral("SSL Echo Server"),
+ QWebSocketServer::SecureModeSecure,
this);
QSslConfiguration sslConfiguration;
QFile certFile(QStringLiteral("./localhost.cert"));
QWebSocket socket;
socket.ignoreSslErrors(expectedSslErrors);
-socket.open("wss://myserver.at.home");
+socket.open(QUrl(QStringLiteral("wss://myserver.at.home")));
//! [6]
<< QByteArray()
<< false
<< QWebSocketProtocol::CloseCodeProtocolError;
- QTest::newRow(QString::fromLatin1(dataTag).append(" with continuation frame")
+ QTest::newRow(QString::fromLatin1(dataTag).append(QStringLiteral(" with continuation frame"))
.toLatin1().constData())
<< quint8(FIN | invalidFieldValue)
<< quint8(0x00)
QTest::newRow("Invalid http version in header") << QStringLiteral("V R HTTP/invalid");
QTest::newRow("Empty header field") << QStringLiteral("GET . HTTP/1.1\r\nHEADER: ");
QTest::newRow("All zeros") << QString::fromUtf8(QByteArray(10, char(0)));
- QTest::newRow("Invalid hostname") << "GET . HTTP/1.1\r\nHost: \xFF\xFF";
+ QTest::newRow("Invalid hostname") << QStringLiteral("GET . HTTP/1.1\r\nHost: \xFF\xFF");
//doing extensive QStringLiteral concatenations here, because
//MSVC 2010 complains when using concatenation literal strings about
//concatenation of wide and narrow strings (error C2308)
frameHelper.setFinalFrame(true);
frameHelper.setMask(1234u);
frameHelper.setOpCode(QWebSocketProtocol::OpCodeBinary);
- frameHelper.setPayload(QByteArray("12345"));
+ frameHelper.setPayload(QByteArrayLiteral("12345"));
QByteArray payload = frameHelper.wireRepresentation();
QBuffer buffer(&payload);
qDebug() << "Executing test" << (nbr + 1) << "/" << total;
QUrl url = m_url;
- url.setPath("/runCase?");
+ url.setPath(QStringLiteral("/runCase?"));
QUrlQuery query;
- query.addQueryItem("case", QString::number(nbr + 1));
- query.addQueryItem("agent", "QtWebSockets/1.0");
+ query.addQueryItem(QStringLiteral("case"), QString::number(nbr + 1));
+ query.addQueryItem(QStringLiteral("agent"), QStringLiteral("QtWebSockets/1.0"));
url.setQuery(query);
pWebSocket->open(url);
spy.wait(60000);
numberOfTestCases = message.toInt();
});
- url.setPath("/getCaseCount");
+ url.setPath(QStringLiteral("/getCaseCount"));
pWebSocket->open(url);
spy.wait(60000);
QVERIFY(numberOfTestCases > 0);
QObject::disconnect(pWebSocket, &QWebSocket::textMessageReceived, 0, 0);
runTestCases(0, numberOfTestCases);
- url.setPath("/updateReports?");
+ url.setPath(QStringLiteral("/updateReports?"));
QUrlQuery query;
- query.addQueryItem("agent", "QtWebSockets");
+ query.addQueryItem(QStringLiteral("agent"), QStringLiteral("QtWebSockets"));
url.setQuery(query);
pWebSocket->open(url);
spy.wait(60000);
tst_WebSocketsTest::tst_WebSocketsTest() :
m_pWebSocket(0),
- m_url("ws://localhost:9000")
+ m_url(QStringLiteral("ws://localhost:9000"))
{
}
void tst_WebSocketsTest::testTextMessage()
{
- const char *message = "Hello world!";
+ const QString message = QStringLiteral("Hello world!");
QSignalSpy spy(m_pWebSocket, SIGNAL(textMessageReceived(QString)));
- QCOMPARE(m_pWebSocket->write(message), (qint64)strlen(message));
+ QCOMPARE(m_pWebSocket->write(message), qint64(message.size()));
QTRY_VERIFY_WITH_TIMEOUT(spy.count() != 0, 1000);
QCOMPARE(spy.count(), 1);
QCOMPARE(spy.at(0).count(), 1);
- QCOMPARE(spy.takeFirst().at(0).toString(), QString(message));
-
- spy.clear();
- QString qMessage(message);
- QCOMPARE(m_pWebSocket->write(qMessage), (qint64)qMessage.length());
- QTRY_VERIFY_WITH_TIMEOUT(spy.count() != 0, 1000);
- QCOMPARE(spy.count(), 1);
- QCOMPARE(spy.at(0).count(), 1);
- QCOMPARE(spy.takeFirst().at(0).toString(), qMessage);
+ QCOMPARE(spy.takeFirst().at(0).toString(), message);
}
void tst_WebSocketsTest::testBinaryMessage()
QByteArray data("Hello world!");
- QCOMPARE(m_pWebSocket->write(data), (qint64)data.size());
+ QCOMPARE(m_pWebSocket->write(data), qint64(data.size()));
QTRY_VERIFY_WITH_TIMEOUT(spy.count() != 0, 1000);
QCOMPARE(spy.count(), 1);
void tst_WebSocketsTest::testLocalAddress()
{
- QCOMPARE(m_pWebSocket->localAddress().toString(), QString("127.0.0.1"));
+ QCOMPARE(m_pWebSocket->localAddress().toString(), QStringLiteral("127.0.0.1"));
quint16 localPort = m_pWebSocket->localPort();
QVERIFY2(localPort > 0, "Local port is invalid.");
}
void tst_WebSocketsTest::testProxy()
{
QNetworkProxy oldProxy = m_pWebSocket->proxy();
- QNetworkProxy proxy(QNetworkProxy::HttpProxy, QString("proxy.network.com"), 80);
+ QNetworkProxy proxy(QNetworkProxy::HttpProxy, QStringLiteral("proxy.network.com"), 80);
m_pWebSocket->setProxy(proxy);
QCOMPARE(proxy, m_pWebSocket->proxy());
m_pWebSocket->setProxy(oldProxy);