Use QStringLiteral where appropriate
authorKurt Pattyn <pattyn.kurt@gmail.com>
Sat, 18 Jan 2014 21:02:11 +0000 (22:02 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 20 Jan 2014 17:26:48 +0000 (18:26 +0100)
Change-Id: I608b555428aceafd7761a882cd4bd1fdb50d19b3
Reviewed-by: Richard J. Moore <rich@kde.org>
12 files changed:
examples/echoclient/echoclient.cpp
examples/echoclient/main.cpp
examples/simplechat/chatserver.cpp
examples/sslechoclient/main.cpp
examples/sslechoclient/sslechoclient.cpp
examples/sslechoserver/sslechoserver.cpp
src/websockets/doc/snippets/src_websockets_ssl_qwebsocket.cpp
tests/auto/dataprocessor/tst_dataprocessor.cpp
tests/auto/handshakerequest/tst_handshakerequest.cpp
tests/auto/websocketframe/tst_websocketframe.cpp
tests/manual/compliance/tst_compliance.cpp
tests/manual/websockets/tst_websockets.cpp

index 8ef8aff..0c9bef8 100644 (file)
@@ -61,7 +61,7 @@ void EchoClient::onConnected()
     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]
index e6a3a5d..b197b39 100644 (file)
@@ -44,7 +44,7 @@
 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);
index 9244b81..f7ad006 100644 (file)
@@ -51,7 +51,8 @@ ChatServer::ChatServer(quint16 port, QObject *parent) :
     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))
     {
index beffe45..5345087 100644 (file)
@@ -44,7 +44,7 @@
 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);
 
index 411dcce..9807719 100644 (file)
@@ -59,7 +59,7 @@ void SslEchoClient::onConnected()
     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]
index aafc9f4..c6bca2f 100644 (file)
@@ -54,7 +54,8 @@ SslEchoServer::SslEchoServer(quint16 port, QObject *parent) :
     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"));
index 0661d1c..b86164b 100644 (file)
@@ -32,5 +32,5 @@ expectedSslErrors.append(error);
 
 QWebSocket socket;
 socket.ignoreSslErrors(expectedSslErrors);
-socket.open("wss://myserver.at.home");
+socket.open(QUrl(QStringLiteral("wss://myserver.at.home")));
 //! [6]
index c4a9ed3..dc3d4fb 100644 (file)
@@ -1725,7 +1725,7 @@ void tst_DataProcessor::invalidField(const char *dataTag, quint8 invalidFieldVal
                            << 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)
index db5ec3c..45fd5d4 100644 (file)
@@ -162,7 +162,7 @@ void tst_HandshakeRequest::tst_invalidStream_data()
     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)
index c818f95..f381741 100644 (file)
@@ -204,7 +204,7 @@ void tst_WebSocketFrame::tst_copyConstructorAndAssignment()
     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);
index a5216b2..5c2115c 100644 (file)
@@ -113,10 +113,10 @@ void tst_ComplianceTest::runTestCase(int nbr, int total)
 
     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);
@@ -142,7 +142,7 @@ void tst_ComplianceTest::autobahnTest()
         numberOfTestCases = message.toInt();
     });
 
-    url.setPath("/getCaseCount");
+    url.setPath(QStringLiteral("/getCaseCount"));
     pWebSocket->open(url);
     spy.wait(60000);
     QVERIFY(numberOfTestCases > 0);
@@ -150,9 +150,9 @@ void tst_ComplianceTest::autobahnTest()
     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);
index 57cb940..e0fbc09 100644 (file)
@@ -97,7 +97,7 @@ private:
 
 tst_WebSocketsTest::tst_WebSocketsTest() :
     m_pWebSocket(0),
-    m_url("ws://localhost:9000")
+    m_url(QStringLiteral("ws://localhost:9000"))
 {
 }
 
@@ -130,24 +130,16 @@ void tst_WebSocketsTest::cleanup()
 
 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()
@@ -156,7 +148,7 @@ 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);
@@ -166,7 +158,7 @@ void tst_WebSocketsTest::testBinaryMessage()
 
 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.");
 }
@@ -198,7 +190,7 @@ void tst_WebSocketsTest::testPeerAddress()
 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);