Fix tst_networkselftest build for WEC7.

WEC7 does not have time() function. Let's use Qt APIs to query time and
initialize random number generator, Qt APIs have already been adapted
to work on all supported platforms.

In addition use QByteArray instead of QString to avoid unnecessary type
conversions later on with toLatin1().

Change-Id: I1ae3729397b0f4a1bd138022a4e122021e10f1e9
Reviewed-by: Björn Breitmeyer <bjoern.breitmeyer@kdab.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Andreas Holzammer <andreas.holzammer@kdab.com>
This commit is contained in:
Janne Anttila 2013-04-17 15:05:41 +03:00 committed by The Qt Project
parent 0775f88c66
commit 2d73648c71

View File

@ -41,8 +41,7 @@
#include <QtTest/QtTest>
#include <QtNetwork/QtNetwork>
#include <time.h>
#include <QtCore/QDateTime>
#ifndef QT_NO_BEARERMANAGEMENT
#include <QtNetwork/qnetworkconfigmanager.h>
@ -531,13 +530,9 @@ void tst_NetworkSelfTest::imapServer()
void tst_NetworkSelfTest::httpServer()
{
QString uniqueExtension;
qsrand(time(0));
#ifndef Q_OS_WINCE
uniqueExtension = QString("%1%2%3").arg((qulonglong)this).arg(qrand()).arg((qulonglong)time(0));
#else
uniqueExtension = QString("%1%2").arg((qulonglong)this).arg(qrand());
#endif
QByteArray uniqueExtension = QByteArray::number((qulonglong)this) +
QByteArray::number((qulonglong)qrand()) +
QByteArray::number((qulonglong)QDateTime::currentDateTime().toTime_t());
netChat(80, QList<Chat>()
// HTTP/0.9 chat:
@ -603,7 +598,7 @@ void tst_NetworkSelfTest::httpServer()
// HTTP/1.0 PUT
<< Chat::Reconnect
<< Chat::send("PUT /dav/networkselftest-" + uniqueExtension.toLatin1() + ".txt HTTP/1.0\r\n"
<< Chat::send("PUT /dav/networkselftest-" + uniqueExtension + ".txt HTTP/1.0\r\n"
"Content-Length: 5\r\n"
"Host: " + QtNetworkSettings::serverName().toLatin1() + "\r\n"
"Connection: close\r\n"
@ -616,7 +611,7 @@ void tst_NetworkSelfTest::httpServer()
// check that the file did get uploaded
<< Chat::Reconnect
<< Chat::send("HEAD /dav/networkselftest-" + uniqueExtension.toLatin1() + ".txt HTTP/1.0\r\n"
<< Chat::send("HEAD /dav/networkselftest-" + uniqueExtension + ".txt HTTP/1.0\r\n"
"Host: " + QtNetworkSettings::serverName().toLatin1() + "\r\n"
"Connection: close\r\n"
"\r\n")
@ -628,7 +623,7 @@ void tst_NetworkSelfTest::httpServer()
// HTTP/1.0 DELETE
<< Chat::Reconnect
<< Chat::send("DELETE /dav/networkselftest-" + uniqueExtension.toLatin1() + ".txt HTTP/1.0\r\n"
<< Chat::send("DELETE /dav/networkselftest-" + uniqueExtension + ".txt HTTP/1.0\r\n"
"Host: " + QtNetworkSettings::serverName().toLatin1() + "\r\n"
"Connection: close\r\n"
"\r\n")