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>
This commit is contained in:
Friedemann Kleint 2012-04-02 14:22:04 +02:00 committed by Qt by Nokia
parent b08f74f089
commit 8f2a088028
15 changed files with 70 additions and 48 deletions

View 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)

View 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);
}
{

View 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

View File

@ -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;
}
}

View 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); }

View 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);
}
{

View 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));

View File

@ -42,7 +42,7 @@
#include <QtTest/QtTest>
#include <qmatrix.h>
#include <math.h>
#include <qmath.h>
#include <qpolygon.h>
Q_DECLARE_METATYPE(QRect)

View 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++;

View 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());
}

View 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()

View File

@ -199,7 +199,8 @@ QString tst_QPrinterInfo::getOutputFromCommand(const QStringList& command)
return QString(array);
}
#else
return QString();
Q_UNUSED(command)
return QString();
#endif
}

View 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;

View 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));

View 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;