Fix MSVC warnings in tests.
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>
Mon, 2 Apr 2012 12:22:04 +0000 (14:22 +0200)
committerQt by Nokia <qt-info@nokia.com>
Mon, 2 Apr 2012 14:56:48 +0000 (16:56 +0200)
- Unused variables
- conversion truncations
- Overflow in expressions like '-1 + sizeof()'

Change-Id: Ibbd18497951e9e7e9dccaf596cb4e864b69ec02c
Reviewed-by: Jason McDonald <jason.mcdonald@nokia.com>
15 files changed:
tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp
tests/auto/corelib/codecs/utf8/tst_utf8.cpp
tests/auto/corelib/io/qdir/tst_qdir.cpp
tests/auto/corelib/io/qprocess/testProcessEchoGui/main_win.cpp
tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp
tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp
tests/auto/gui/painting/qwmatrix/tst_qwmatrix.cpp
tests/auto/gui/qopengl/tst_qopengl.cpp
tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
tests/auto/other/networkselftest/tst_networkselftest.cpp
tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp
tests/auto/testlib/selftests/tst_selftests.cpp
tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
tests/shared/filesystem.h

index 86e3433..81084db 100644 (file)
@@ -381,7 +381,7 @@ void tst_QtConcurrentRun::exceptions()
     bool caught = false;
     try  {
         QtConcurrent::run(throwFunction).waitForFinished();
-    } catch (Exception &e) {
+    } catch (Exception &) {
         caught = true;
     }
     if (!caught)
@@ -390,7 +390,7 @@ void tst_QtConcurrentRun::exceptions()
     caught = false;
     try  {
         QtConcurrent::run(throwFunctionReturn).waitForFinished();
-    } catch (Exception &e) {
+    } catch (Exception &) {
         caught = true;
     }
     if (!caught)
index dd6774e..b80ba8e 100644 (file)
@@ -185,7 +185,7 @@ void tst_Utf8::charByChar()
         }
 
         if (encoded.startsWith(utf8bom))
-            encoded = encoded.mid(strlen(utf8bom));
+            encoded = encoded.mid(int(strlen(utf8bom)));
         QCOMPARE(encoded, utf8);
     }
     {
index b7fc366..250575b 100644 (file)
@@ -53,7 +53,7 @@
 #include "../../../network-settings.h"
 #endif
 
-#if defined(Q_OS_WIN)
+#if defined(Q_OS_WIN) && !defined(_WIN32_WINNT)
 #define _WIN32_WINNT  0x500
 #endif
 
index a8a17b6..3bae41e 100644 (file)
 
 #include <windows.h>
 
-int APIENTRY WinMain(HINSTANCE hInstance,
-                     HINSTANCE hPrevInstance,
-                     LPSTR     lpCmdLine,
-                     int       nCmdShow)
+int APIENTRY WinMain(HINSTANCE /* hInstance */,
+                     HINSTANCE /* hPrevInstance */,
+                     LPSTR     /* lpCmdLine */,
+                     int       /* nCmdShow */)
 {
 
     HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
@@ -64,4 +64,4 @@ int APIENTRY WinMain(HINSTANCE hInstance,
         WriteFile(hStderr, &c, 1, &wrote, 0);
     }
     return 0;
-}
\ No newline at end of file
+}
index d93e00e..09bd9fe 100644 (file)
@@ -429,7 +429,7 @@ template<> struct TestValueFactory<QMetaType::UChar> {
     static uchar *create() { return new uchar('u'); }
 };
 template<> struct TestValueFactory<QMetaType::Float> {
-    static float *create() { return new float(3.14); }
+    static float *create() { return new float(3.14f); }
 };
 template<> struct TestValueFactory<QMetaType::QObjectStar> {
     static QObject * *create() { return new QObject *(0); }
index bd9fa2a..8a60bb1 100644 (file)
@@ -984,7 +984,7 @@ void tst_QXmlStream::writeAttributesWithSpace() const
     QXmlStreamWriter writer(&buffer);
     writer.writeStartDocument();
     writer.writeEmptyElement("A");
-    writer.writeAttribute("attribute", QString("value")+QChar::Nbsp);
+    writer.writeAttribute("attribute", QStringLiteral("value") + QChar(QChar::Nbsp));
     writer.writeEndDocument();
     QString s = QString("<?xml version=\"1.0\" encoding=\"UTF-8\"?><A attribute=\"value%1\"/>\n").arg(QChar(QChar::Nbsp));
     QCOMPARE(buffer.buffer().data(), s.toUtf8().data());
@@ -1512,35 +1512,38 @@ void tst_QXmlStream::hasError() const
         // Failure caused by write(QString)
         FakeBuffer fb;
         QVERIFY(fb.open(QBuffer::ReadWrite));
-        fb.setCapacity(strlen("<?xml version=\""));
+        const QByteArray expected = QByteArrayLiteral("<?xml version=\"");
+        fb.setCapacity(expected.size());
         QXmlStreamWriter writer(&fb);
         writer.writeStartDocument();
         QVERIFY(writer.hasError());
-        QCOMPARE(fb.data(), QByteArray("<?xml version=\""));
+        QCOMPARE(fb.data(), expected);
     }
 
     {
         // Failure caused by write(char *)
         FakeBuffer fb;
         QVERIFY(fb.open(QBuffer::ReadWrite));
-        fb.setCapacity(strlen("<?xml version=\"1.0"));
+        const QByteArray expected = QByteArrayLiteral("<?xml version=\"1.0");
+        fb.setCapacity(expected.size());
         QXmlStreamWriter writer(&fb);
         writer.writeStartDocument();
         QVERIFY(writer.hasError());
-        QCOMPARE(fb.data(), QByteArray("<?xml version=\"1.0"));
+        QCOMPARE(fb.data(), expected);
     }
 
     {
         // Failure caused by write(QStringRef)
         FakeBuffer fb;
         QVERIFY(fb.open(QBuffer::ReadWrite));
-        fb.setCapacity(strlen("<?xml version=\"1.0\" encoding=\"UTF-8\"?><test xmlns:"));
+        const QByteArray expected = QByteArrayLiteral("<?xml version=\"1.0\" encoding=\"UTF-8\"?><test xmlns:");
+        fb.setCapacity(expected.size());
         QXmlStreamWriter writer(&fb);
         writer.writeStartDocument();
         writer.writeStartElement("test");
         writer.writeNamespace("http://foo.bar", "foo");
         QVERIFY(writer.hasError());
-        QCOMPARE(fb.data(), QByteArray("<?xml version=\"1.0\" encoding=\"UTF-8\"?><test xmlns:"));
+        QCOMPARE(fb.data(), expected);
     }
 
     {
index 861ad38..c4db74b 100644 (file)
@@ -422,7 +422,9 @@ void tst_QKeySequence::mnemonic()
     QFETCH(QString, key);
     QFETCH(bool, warning);
 
-#ifndef QT_NO_DEBUG
+#ifdef QT_NO_DEBUG
+    Q_UNUSED(warning)
+#else
     if (warning) {
         QString str = QString::fromLatin1("QKeySequence::mnemonic: \"%1\" contains multiple occurrences of '&'").arg(string);
         QTest::ignoreMessage(QtWarningMsg, qPrintable(str));
index f4cf586..26a6833 100644 (file)
@@ -42,7 +42,7 @@
 
 #include <QtTest/QtTest>
 #include <qmatrix.h>
-#include <math.h>
+#include <qmath.h>
 #include <qpolygon.h>
 
 Q_DECLARE_METATYPE(QRect)
index e8374b0..38208d2 100644 (file)
@@ -118,6 +118,7 @@ struct SharedResource : public QOpenGLSharedResource
     void freeResource(QOpenGLContext *context)
     {
         Q_ASSERT(context == QOpenGLContext::currentContext());
+        Q_UNUSED(context)
         resource = 0;
         if (tracker)
             tracker->freeResourceCalls++;
index f63c593..cab3d56 100644 (file)
@@ -309,9 +309,10 @@ void tst_QUdpSocket::broadcasting()
                 QByteArray arr; arr.resize(serverSocket.pendingDatagramSize() + 1);
                 QHostAddress host;
                 quint16 port;
+                const int messageLength = int(strlen(message[i]));
                 QCOMPARE((int) serverSocket.readDatagram(arr.data(), arr.size() - 1, &host, &port),
-                    (int) strlen(message[i]));
-                arr.resize(strlen(message[i]));
+                         messageLength);
+                arr.resize(messageLength);
                 QCOMPARE(arr, QByteArray(message[i]));
             } while (serverSocket.hasPendingDatagrams());
         }
index ebb8443..3c0c440 100644 (file)
@@ -863,7 +863,7 @@ static const char connect2[] = "\5\1\0\3\11localhost\0\25"; // Connect hostname
 static const char connect2a[] = "\5\1\0\3"; // just "Connect to hostname"
 static const char connected[] = "\5\0\0";
 
-#define QBA(x) (QByteArray::fromRawData(x, -1 + sizeof(x)))
+#define QBA(x) (QByteArray::fromRawData(x, int(sizeof(x)) - 1))
 
 void tst_NetworkSelfTest::socks5Proxy()
 {
@@ -873,42 +873,48 @@ void tst_NetworkSelfTest::socks5Proxy()
     } ip4Address;
     ip4Address.data = qToBigEndian(serverIpAddress().toIPv4Address());
 
+    const QByteArray handshakeNoAuthData = QByteArray(handshakeNoAuth, int(sizeof handshakeNoAuth) - 1);
+    const QByteArray handshakeOkNoAuthData = QByteArray(handshakeOkNoAuth, int(sizeof handshakeOkNoAuth) - 1);
+    const QByteArray connect1Data = QByteArray(connect1, int(sizeof connect1) - 1);
+    const QByteArray connectedData = QByteArray(connected, int(sizeof connected) - 1);
+    const QByteArray connect2Data = QByteArray(connect2, int(sizeof connect2) - 1);
+
     netChat(1080, QList<Chat>()
             // IP address connection
-            << Chat::send(QByteArray(handshakeNoAuth, -1 + sizeof handshakeNoAuth))
-            << Chat::expect(QByteArray(handshakeOkNoAuth, -1 + sizeof handshakeOkNoAuth))
-            << Chat::send(QByteArray(connect1, -1 + sizeof connect1))
-            << Chat::expect(QByteArray(connected, -1 + sizeof connected))
+            << Chat::send(handshakeNoAuthData)
+            << Chat::expect(handshakeOkNoAuthData)
+            << Chat::send(connect1Data)
+            << Chat::expect(connectedData)
             << Chat::expect("\1") // IPv4 address following
             << Chat::skipBytes(6) // the server's local address and port
             << ftpChat()
 
             // connect by IP
             << Chat::Reconnect
-            << Chat::send(QByteArray(handshakeNoAuth, -1 + sizeof handshakeNoAuth))
-            << Chat::expect(QByteArray(handshakeOkNoAuth, -1 + sizeof handshakeOkNoAuth))
+            << Chat::send(handshakeNoAuthData)
+            << Chat::expect(handshakeOkNoAuthData)
             << Chat::send(QBA(connect1a) + QByteArray::fromRawData(ip4Address.buf, 4) + QBA(connect1b))
-            << Chat::expect(QByteArray(connected, -1 + sizeof connected))
+            << Chat::expect(connectedData)
             << Chat::expect("\1") // IPv4 address following
             << Chat::skipBytes(6) // the server's local address and port
             << ftpChat()
 
             // connect to "localhost" by hostname
             << Chat::Reconnect
-            << Chat::send(QByteArray(handshakeNoAuth, -1 + sizeof handshakeNoAuth))
-            << Chat::expect(QByteArray(handshakeOkNoAuth, -1 + sizeof handshakeOkNoAuth))
-            << Chat::send(QByteArray(connect2, -1 + sizeof connect2))
-            << Chat::expect(QByteArray(connected, -1 + sizeof connected))
+            << Chat::send(handshakeNoAuthData)
+            << Chat::expect(handshakeOkNoAuthData)
+            << Chat::send(connect2Data)
+            << Chat::expect(connectedData)
             << Chat::expect("\1") // IPv4 address following
             << Chat::skipBytes(6) // the server's local address and port
             << ftpChat()
 
             // connect to server by its official name
             << Chat::Reconnect
-            << Chat::send(QByteArray(handshakeNoAuth, -1 + sizeof handshakeNoAuth))
-            << Chat::expect(QByteArray(handshakeOkNoAuth, -1 + sizeof handshakeOkNoAuth))
+            << Chat::send(handshakeNoAuthData)
+            << Chat::expect(handshakeOkNoAuthData)
             << Chat::send(QBA(connect2a) + char(QtNetworkSettings::serverName().size()) + QtNetworkSettings::serverName().toLatin1() + QBA(connect1b))
-            << Chat::expect(QByteArray(connected, -1 + sizeof connected))
+            << Chat::expect(connectedData)
             << Chat::expect("\1") // IPv4 address following
             << Chat::skipBytes(6) // the server's local address and port
             << ftpChat()
@@ -917,18 +923,25 @@ void tst_NetworkSelfTest::socks5Proxy()
 
 void tst_NetworkSelfTest::socks5ProxyAuth()
 {
+    const QByteArray handshakeNoAuthData = QByteArray(handshakeNoAuth, int(sizeof handshakeNoAuth) - 1);
+    const QByteArray connect1Data = QByteArray(connect1, int(sizeof connect1) - 1);
+    const QByteArray connectedData = QByteArray(connected, int(sizeof connected) - 1);
+    const QByteArray handshakeAuthNotOkData = QByteArray(handshakeAuthNotOk, int(sizeof(handshakeAuthNotOk)) - 1);
+    const QByteArray handshakeAuthPasswordData = QByteArray(handshakeAuthPassword, int(sizeof(handshakeAuthPassword)) - 1);
+    const QByteArray handshakeOkPasswdAuthData = QByteArray(handshakeOkPasswdAuth, int(sizeof(handshakeOkPasswdAuth)) - 1);
+
     netChat(1081, QList<Chat>()
             // unauthenticated connect -- will get error
-            << Chat::send(QByteArray(handshakeNoAuth, -1 + sizeof handshakeNoAuth))
-            << Chat::expect(QByteArray(handshakeAuthNotOk, -1 + sizeof handshakeAuthNotOk))
+            << Chat::send(handshakeNoAuthData)
+            << Chat::expect(handshakeAuthNotOkData)
             << Chat::RemoteDisconnect
 
             // now try to connect with authentication
             << Chat::Reconnect
-            << Chat::send(QByteArray(handshakeAuthPassword, -1 + sizeof handshakeAuthPassword))
-            << Chat::expect(QByteArray(handshakeOkPasswdAuth, -1 + sizeof handshakeOkPasswdAuth))
-            << Chat::send(QByteArray(connect1, -1 + sizeof connect1))
-            << Chat::expect(QByteArray(connected, -1 + sizeof connected))
+            << Chat::send(handshakeAuthPasswordData)
+            << Chat::expect(handshakeOkPasswdAuthData)
+            << Chat::send(connect1Data)
+            << Chat::expect(connectedData)
             << Chat::expect("\1") // IPv4 address following
             << Chat::skipBytes(6) // the server's local address and port
             << ftpChat()
index 48d38a8..404aa06 100644 (file)
@@ -199,7 +199,8 @@ QString tst_QPrinterInfo::getOutputFromCommand(const QStringList& command)
         return QString(array);
     }
 #else
-       return QString();
+    Q_UNUSED(command)
+    return QString();
 #endif
 }
 
index 97458ab..26ccd82 100644 (file)
@@ -135,7 +135,7 @@ static QList<QByteArray> splitLines(QByteArray ba)
             if (index == -1) {
                 continue;
             }
-            int end = line.indexOf('"', index + strlen(markers[j][0]));
+            const int end = line.indexOf('"', index + int(strlen(markers[j][0])));
             if (end == -1) {
                 continue;
             }
@@ -686,11 +686,12 @@ QString extractXmlAttribute(const QString &line, const char *attribute)
     int index = line.indexOf(attribute);
     if (index == -1)
         return QString();
-    int end = line.indexOf('"', index + strlen(attribute));
+    const int attributeLength = int(strlen(attribute));
+    const int end = line.indexOf('"', index + attributeLength);
     if (end == -1)
         return QString();
 
-    QString result = line.mid(index + strlen(attribute), end - index - strlen(attribute));
+    const QString result = line.mid(index + attributeLength, end - index - attributeLength);
     if (result.isEmpty())
         return ""; // ensure empty but not null
     return result;
index 19532a0..1838977 100644 (file)
@@ -3712,7 +3712,7 @@ void tst_QGraphicsView::render()
     view.show();
     QTest::qWaitForWindowShown(&view);
     QApplication::processEvents();
-    QTRY_VERIFY(view.painted > 0);
+    QTRY_VERIFY(view.painted);
 
     RenderTester *r1 = new RenderTester(QRectF(0, 0, 50, 50));
     RenderTester *r2 = new RenderTester(QRectF(50, 50, 50, 50));
index c681dcf..acc8500 100644 (file)
@@ -149,7 +149,7 @@ struct FileSystem
 
         memset( reparseInfo, 0, sizeof( *reparseInfo ));
         reparseInfo->ReparseTag = IO_REPARSE_TAG_MOUNT_POINT;
-        reparseInfo->ReparseTargetLength = target.size() * sizeof(wchar_t);
+        reparseInfo->ReparseTargetLength = DWORD(target.size() * sizeof(wchar_t));
         reparseInfo->ReparseTargetMaximumLength = reparseInfo->ReparseTargetLength + sizeof(wchar_t);
         target.toWCharArray(reparseInfo->ReparseTarget);
         reparseInfo->ReparseDataLength = reparseInfo->ReparseTargetLength + 12;