diff options
author | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2012-04-02 14:22:04 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-04-02 16:56:48 +0200 |
commit | 8f2a088028cf074a08e5252509c60e0f1021c43f (patch) | |
tree | d8af228b3cf3f9c998f7a52dec50ddcce84a7af1 | |
parent | b08f74f08939be310a79b5efcb5721e35c5deb21 (diff) |
Fix MSVC warnings in tests.
- Unused variables
- conversion truncations
- Overflow in expressions like '-1 + sizeof()'
Change-Id: Ibbd18497951e9e7e9dccaf596cb4e864b69ec02c
Reviewed-by: Jason McDonald <jason.mcdonald@nokia.com>
15 files changed, 70 insertions, 48 deletions
diff --git a/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp b/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp index 86e3433c12..81084dbaf4 100644 --- a/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp +++ b/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp @@ -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) diff --git a/tests/auto/corelib/codecs/utf8/tst_utf8.cpp b/tests/auto/corelib/codecs/utf8/tst_utf8.cpp index dd6774e101..b80ba8e665 100644 --- a/tests/auto/corelib/codecs/utf8/tst_utf8.cpp +++ b/tests/auto/corelib/codecs/utf8/tst_utf8.cpp @@ -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); } { diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp index b7fc366a39..250575bea0 100644 --- a/tests/auto/corelib/io/qdir/tst_qdir.cpp +++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp @@ -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 diff --git a/tests/auto/corelib/io/qprocess/testProcessEchoGui/main_win.cpp b/tests/auto/corelib/io/qprocess/testProcessEchoGui/main_win.cpp index a8a17b6951..3bae41e83e 100644 --- a/tests/auto/corelib/io/qprocess/testProcessEchoGui/main_win.cpp +++ b/tests/auto/corelib/io/qprocess/testProcessEchoGui/main_win.cpp @@ -42,10 +42,10 @@ #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 +} diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index d93e00eed8..09bd9fe445 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -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); } diff --git a/tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp b/tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp index bd9fa2a8db..8a60bb1876 100644 --- a/tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp +++ b/tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp @@ -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); } { diff --git a/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp b/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp index 861ad3835d..c4db74b6ec 100644 --- a/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp +++ b/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp @@ -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)); diff --git a/tests/auto/gui/painting/qwmatrix/tst_qwmatrix.cpp b/tests/auto/gui/painting/qwmatrix/tst_qwmatrix.cpp index f4cf586da1..26a68338a6 100644 --- a/tests/auto/gui/painting/qwmatrix/tst_qwmatrix.cpp +++ b/tests/auto/gui/painting/qwmatrix/tst_qwmatrix.cpp @@ -42,7 +42,7 @@ #include <QtTest/QtTest> #include <qmatrix.h> -#include <math.h> +#include <qmath.h> #include <qpolygon.h> Q_DECLARE_METATYPE(QRect) diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp index e8374b0cae..38208d27c8 100644 --- a/tests/auto/gui/qopengl/tst_qopengl.cpp +++ b/tests/auto/gui/qopengl/tst_qopengl.cpp @@ -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++; diff --git a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp index f63c593f91..cab3d56d32 100644 --- a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp +++ b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp @@ -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()); } diff --git a/tests/auto/other/networkselftest/tst_networkselftest.cpp b/tests/auto/other/networkselftest/tst_networkselftest.cpp index ebb8443748..3c0c4406fe 100644 --- a/tests/auto/other/networkselftest/tst_networkselftest.cpp +++ b/tests/auto/other/networkselftest/tst_networkselftest.cpp @@ -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() diff --git a/tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp b/tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp index 48d38a8146..404aa06399 100644 --- a/tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp +++ b/tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp @@ -199,7 +199,8 @@ QString tst_QPrinterInfo::getOutputFromCommand(const QStringList& command) return QString(array); } #else - return QString(); + Q_UNUSED(command) + return QString(); #endif } diff --git a/tests/auto/testlib/selftests/tst_selftests.cpp b/tests/auto/testlib/selftests/tst_selftests.cpp index 97458abfbf..26ccd826ca 100644 --- a/tests/auto/testlib/selftests/tst_selftests.cpp +++ b/tests/auto/testlib/selftests/tst_selftests.cpp @@ -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; diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index 19532a0e37..1838977749 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -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)); diff --git a/tests/shared/filesystem.h b/tests/shared/filesystem.h index c681dcfa05..acc8500ba0 100644 --- a/tests/shared/filesystem.h +++ b/tests/shared/filesystem.h @@ -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; |