tests/auto/network: Remove some placeholder formatting.

Use QByteArray/QString addition instead in loops and for
test row names.

Change-Id: I7974ace5b34f2da43e7511044e80de1e733245ac
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>
bb10
Friedemann Kleint 2015-10-19 11:14:55 +02:00
parent 733ac31ccc
commit 240d768ca6
13 changed files with 89 additions and 75 deletions

View File

@ -44,7 +44,7 @@
#include <algorithm>
#define TESTFILE QString("http://%1/qtest/cgi-bin/").arg(QtNetworkSettings::serverName())
#define TESTFILE QLatin1String("http://") + QtNetworkSettings::serverName() + QLatin1String("/qtest/cgi-bin/")
class tst_QAbstractNetworkCache : public QObject
{

View File

@ -290,10 +290,11 @@ void tst_QFtp::init()
#if !defined(Q_OS_WINCE)
srand(time(0));
uniqueExtension = QString("%1%2%3").arg((qulonglong)this).arg(rand()).arg((qulonglong)time(0));
uniqueExtension = QString::number((quintptr)this) + QString::number(rand())
+ QString::number((qulonglong)time(0));
#else
srand(0);
uniqueExtension = QString("%1%2%3").arg((qulonglong)this).arg(rand()).arg((qulonglong)(0));
uniqueExtension = QString::number((quintptr)this) + QString::number(rand()) + QLatin1Char('0');
#endif
}
@ -643,19 +644,20 @@ void tst_QFtp::get_data()
// test the two get() overloads in one routine
for ( int i=0; i<2; i++ ) {
QTest::newRow( QString("relPath01_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString()
const QByteArray iB = QByteArray::number(i);
QTest::newRow(("relPath01_" + iB).constData()) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString()
<< "qtest/rfc3252" << 1 << rfc3252 << (bool)(i==1);
QTest::newRow( QString("relPath02_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password")
QTest::newRow(("relPath02_" + iB).constData()) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password")
<< "qtest/rfc3252" << 1 << rfc3252 << (bool)(i==1);
QTest::newRow( QString("absPath01_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString()
QTest::newRow(("absPath01_" + iB).constData()) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString()
<< "/qtest/rfc3252" << 1 << rfc3252 << (bool)(i==1);
QTest::newRow( QString("absPath02_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password")
QTest::newRow(("absPath02_" + iB).constData()) << QtNetworkSettings::serverName() << (uint)21 << QString("ftptest") << QString("password")
<< "/var/ftp/qtest/rfc3252" << 1 << rfc3252 << (bool)(i==1);
QTest::newRow( QString("nonExist01_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString()
QTest::newRow(("nonExist01_" + iB).constData()) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString()
<< QString("foo") << 0 << QByteArray() << (bool)(i==1);
QTest::newRow( QString("nonExist02_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString()
QTest::newRow(("nonExist02_" + iB).constData()) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString()
<< QString("/foo") << 0 << QByteArray() << (bool)(i==1);
}
}
@ -734,7 +736,7 @@ void tst_QFtp::put_data()
// test the two put() overloads in one routine
for ( int i=0; i<2; i++ ) {
QTest::newRow( QString("relPath01_%1").arg(i).toLatin1().constData() ) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString()
QTest::newRow(("relPath01_" + QByteArray::number(i)).constData()) << QtNetworkSettings::serverName() << (uint)21 << QString() << QString()
<< QString("qtest/upload/rel01_%1") << rfc3252
<< (bool)(i==1) << 1;
/*

View File

@ -63,16 +63,16 @@ namespace QTest {
template<>
char *toString(const QList<QNetworkCookie> &list)
{
QString result = "QList(";
QByteArray result = "QList(";
bool first = true;
foreach (QNetworkCookie cookie, list) {
if (!first)
result += ", ";
first = false;
result += QString::fromLatin1("QNetworkCookie(%1)").arg(QLatin1String(cookie.toRawForm()));
result += "QNetworkCookie(" + cookie.toRawForm() + ')';
}
return qstrdup(result.append(')').toLocal8Bit());
result.append(')');
return qstrdup(result.constData());
}
}

View File

@ -72,16 +72,17 @@ namespace QTest {
template<>
char *toString(const QList<QNetworkCookie> &list)
{
QString result = "QList(";
QByteArray result = "QList(";
bool first = true;
foreach (QNetworkCookie cookie, list) {
if (!first)
result += ", ";
first = false;
result += QString::fromLatin1("QNetworkCookie(%1)").arg(QLatin1String(cookie.toRawForm()));
result += "QNetworkCookie(" + cookie.toRawForm() + ')';
}
return qstrdup(result.append(')').toLocal8Bit());
result.append(')');
return qstrdup(result.constData());
}
}

View File

@ -540,7 +540,7 @@ void tst_QNetworkDiskCache::expire()
std::sort(cacheList.begin(), cacheList.end());
for (int i = 0; i < cacheList.count(); ++i) {
QString fileName = cacheList[i];
QCOMPARE(fileName, QString("http://localhost:4/%1").arg(i + 6));
QCOMPARE(fileName, QLatin1String("http://localhost:4/") + QString::number(i + 6));
}
}
@ -782,7 +782,10 @@ void tst_QNetworkDiskCache::crashWhenParentingCache()
QNetworkAccessManager *manager = new QNetworkAccessManager();
QNetworkDiskCache *diskCache = new QNetworkDiskCache(manager); // parent to qnam!
// we expect the temp dir to be cleaned at some point anyway
diskCache->setCacheDirectory(QString("%1/cacheDir_%2").arg(QDir::tempPath()).arg(QCoreApplication::applicationPid()));
const QString diskCachePath = QDir::tempPath() + QLatin1String("/cacheDir_")
+ QString::number(QCoreApplication::applicationPid());
diskCache->setCacheDirectory(diskCachePath);
manager->setCache(diskCache);
QUrl url("http://127.0.0.1:" + QString::number(server.serverPort()));

View File

@ -125,9 +125,10 @@ class tst_QNetworkReply: public QObject
qsrand(QTime(0,0,0).msecsTo(QTime::currentTime()) + QCoreApplication::applicationPid());
seedCreated = true; // not thread-safe, but who cares
}
QString s = QString("%1-%2-%3").arg(QTime(0,0,0).msecsTo(QTime::currentTime())).arg(QCoreApplication::applicationPid()).arg(qrand());
return s;
};
return QString::number(QTime(0, 0, 0).msecsTo(QTime::currentTime()))
+ QLatin1Char('-') + QString::number(QCoreApplication::applicationPid())
+ QLatin1Char('-') + QString::number(qrand());
}
static QString tempRedirectReplyStr() {
QString s = "HTTP/1.1 307 Temporary Redirect\r\n"
@ -514,16 +515,16 @@ namespace QTest {
template<>
char *toString(const QList<QNetworkCookie> &list)
{
QString result = "QList(";
QByteArray result = "QList(";
bool first = true;
foreach (QNetworkCookie cookie, list) {
if (!first)
result += ", ";
first = false;
result += QString::fromLatin1("QNetworkCookie(%1)").arg(QLatin1String(cookie.toRawForm()));
result += "QNetworkCookie(" + cookie.toRawForm() + ')';
}
return qstrdup(result.append(')').toLocal8Bit());
result.append(')');
return qstrdup(result.constData());
}
}
@ -4816,7 +4817,7 @@ void tst_QNetworkReply::ioPostToHttpsUploadProgress()
server.listen(QHostAddress(QHostAddress::LocalHost), 0);
// create the request
QUrl url = QUrl(QString("https://127.0.0.1:%1/").arg(server.serverPort()));
QUrl url = QUrl(QLatin1String("https://127.0.0.1:") + QString::number(server.serverPort()) + QLatin1Char('/'));
QNetworkRequest request(url);
request.setRawHeader("Content-Type", "application/octet-stream");
@ -5032,7 +5033,7 @@ void tst_QNetworkReply::emitAllUploadProgressSignals()
server.listen(QHostAddress(QHostAddress::LocalHost), 0);
connect(&server, SIGNAL(newConnection()), &QTestEventLoop::instance(), SLOT(exitLoop()));
QUrl url = QUrl(QString("http://127.0.0.1:%1/").arg(server.serverPort()));
QUrl url = QUrl(QLatin1String("http://127.0.0.1:") + QString::number(server.serverPort()) + QLatin1Char('/'));
QNetworkRequest normalRequest(url);
normalRequest.setRawHeader("Content-Type", "application/octet-stream");
@ -5087,7 +5088,7 @@ void tst_QNetworkReply::ioPostToHttpEmptyUploadProgress()
server.listen(QHostAddress(QHostAddress::LocalHost), 0);
// create the request
QUrl url = QUrl(QString("http://127.0.0.1:%1/").arg(server.serverPort()));
QUrl url = QUrl(QLatin1String("http://127.0.0.1:") + QString::number(server.serverPort()) + QLatin1Char('/'));
QNetworkRequest request(url);
request.setRawHeader("Content-Type", "application/octet-stream");
QNetworkReplyPtr reply(manager.post(request, &buffer));
@ -6465,9 +6466,10 @@ public slots:
QByteArray data(amount, '@');
if (chunkedEncoding) {
client->write(QString(QString("%1").arg(amount,0,16).toUpper() + "\r\n").toLatin1());
client->write(QByteArray::number(amount, 16).toUpper());
client->write("\r\n");
client->write(data.constData(), amount);
client->write(QString("\r\n").toLatin1());
client->write("\r\n");
} else {
client->write(data.constData(), amount);
}
@ -8298,10 +8300,15 @@ void tst_QNetworkReply::putWithServerClosingConnectionImmediately()
server.m_expectedReplies = numUploads;
server.listen(QHostAddress(QHostAddress::LocalHost), 0);
QString urlPrefix = QLatin1String("http");
if (withSsl)
urlPrefix += QLatin1Char('s');
urlPrefix += QLatin1String("://127.0.0.1:");
urlPrefix += QString::number(server.serverPort());
urlPrefix += QLatin1String("/file=");
for (int i = 0; i < numUploads; i++) {
// create the request
QUrl url = QUrl(QString("http%1://127.0.0.1:%2/file=%3").arg(withSsl ? "s" : "").arg(server.serverPort()).arg(i));
QNetworkRequest request(url);
QNetworkRequest request(QUrl(urlPrefix + QString::number(i)));
QNetworkReply *reply = manager.put(request, sourceFile);
connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply, SLOT(ignoreSslErrors()));
connect(reply, SIGNAL(finished()), &server, SLOT(replyFinished()));

View File

@ -73,16 +73,16 @@ namespace QTest {
template<>
char *toString(const QList<QNetworkCookie> &list)
{
QString result = "QList(";
QByteArray result = "QList(";
bool first = true;
foreach (QNetworkCookie cookie, list) {
if (!first)
result += ", ";
first = false;
result += QString::fromLatin1("QNetworkCookie(%1)").arg(QLatin1String(cookie.toRawForm()));
result += "QNetworkCookie(" + cookie.toRawForm() + ')';
}
return qstrdup(result.append(')').toLocal8Bit());
result.append(')');
return qstrdup(result.constData());
}
}

View File

@ -132,8 +132,9 @@ int main(int argc, char** argv)
return SESSION_OPEN_ERROR;
}
QString output = QString("Started session for %1\n").arg(session->configuration().identifier());
oopSocket.write(output.toLatin1());
QByteArray output = "Started session for "
+ session->configuration().identifier().toLatin1() + '\n';
oopSocket.write(output);
oopSocket.waitForBytesWritten();
oopSocket.waitForReadyRead();

View File

@ -275,7 +275,7 @@ void tst_QDnsLookup::lookup()
QStringList mailExchanges;
foreach (const QDnsMailExchangeRecord &record, lookup.mailExchangeRecords()) {
QCOMPARE(record.name(), domain);
mailExchanges << QString("%1 %2").arg(QString::number(record.preference()), record.exchange());
mailExchanges << QString::number(record.preference()) + QLatin1Char(' ') + record.exchange();
}
QVERIFY2(mx_alternatives.contains(mailExchanges.join(';')),
qPrintable("Actual: " + mailExchanges.join(';') + "\nExpected one of:\n" + mx_alternatives.join('\n')));
@ -304,11 +304,9 @@ void tst_QDnsLookup::lookup()
QStringList services;
foreach (const QDnsServiceRecord &record, lookup.serviceRecords()) {
QCOMPARE(record.name(), domain);
services << QString("%1 %2 %3 %4").arg(
QString::number(record.priority()),
QString::number(record.weight()),
QString::number(record.port()),
record.target());
services << (QString::number(record.priority()) + QLatin1Char(' ')
+ QString::number(record.weight()) + QLatin1Char(' ')
+ QString::number(record.port()) + QLatin1Char(' ') + record.target());
}
QVERIFY2(srv_alternatives.contains(services.join(';')),
qPrintable("Actual: " + services.join(';') + "\nExpected one of:\n" + srv_alternatives.join('\n')));

View File

@ -327,8 +327,9 @@ void tst_QLocalSocket::listenAndConnect_data()
int connections = i;
if (i == 2)
connections = 5;
QTest::newRow(QString("null %1").arg(i).toLatin1()) << QString() << false << connections;
QTest::newRow(QString("tst_localsocket %1").arg(i).toLatin1()) << "tst_localsocket" << true << connections;
const QByteArray iB = QByteArray::number(i);
QTest::newRow(("null " + iB).constData()) << QString() << false << connections;
QTest::newRow(("tst_localsocket " + iB).constData()) << "tst_localsocket" << true << connections;
}
}

View File

@ -1119,12 +1119,13 @@ void tst_QUdpSocket::multicastTtlOption_data()
addresses += QHostAddress(QHostAddress::AnyIPv6);
foreach (const QHostAddress &address, addresses) {
QTest::newRow(QString("%1 0").arg(address.toString()).toLatin1()) << address << 0 << 0;
QTest::newRow(QString("%1 1").arg(address.toString()).toLatin1()) << address << 1 << 1;
QTest::newRow(QString("%1 2").arg(address.toString()).toLatin1()) << address << 2 << 2;
QTest::newRow(QString("%1 128").arg(address.toString()).toLatin1()) << address << 128 << 128;
QTest::newRow(QString("%1 255").arg(address.toString()).toLatin1()) << address << 255 << 255;
QTest::newRow(QString("%1 1024").arg(address.toString()).toLatin1()) << address << 1024 << 1;
const QByteArray addressB = address.toString().toLatin1();
QTest::newRow((addressB + " 0").constData()) << address << 0 << 0;
QTest::newRow((addressB + " 1").constData()) << address << 1 << 1;
QTest::newRow((addressB + " 2").constData()) << address << 2 << 2;
QTest::newRow((addressB + " 128").constData()) << address << 128 << 128;
QTest::newRow((addressB + " 255").constData()) << address << 255 << 255;
QTest::newRow((addressB + " 1024").constData()) << address << 1024 << 1;
}
}
@ -1163,13 +1164,14 @@ void tst_QUdpSocket::multicastLoopbackOption_data()
addresses += QHostAddress(QHostAddress::AnyIPv6);
foreach (const QHostAddress &address, addresses) {
QTest::newRow(QString("%1 0").arg(address.toString()).toLatin1()) << address << 0 << 0;
QTest::newRow(QString("%1 1").arg(address.toString()).toLatin1()) << address << 1 << 1;
QTest::newRow(QString("%1 2").arg(address.toString()).toLatin1()) << address << 2 << 1;
QTest::newRow(QString("%1 0 again").arg(address.toString()).toLatin1()) << address << 0 << 0;
QTest::newRow(QString("%1 2 again").arg(address.toString()).toLatin1()) << address << 2 << 1;
QTest::newRow(QString("%1 0 last time").arg(address.toString()).toLatin1()) << address << 0 << 0;
QTest::newRow(QString("%1 1 again").arg(address.toString()).toLatin1()) << address << 1 << 1;
const QByteArray addressB = address.toString().toLatin1();
QTest::newRow((addressB + " 0").constData()) << address << 0 << 0;
QTest::newRow((addressB + " 1").constData()) << address << 1 << 1;
QTest::newRow((addressB + " 2").constData()) << address << 2 << 1;
QTest::newRow((addressB + " 0 again").constData()) << address << 0 << 0;
QTest::newRow((addressB + " 2 again").constData()) << address << 2 << 1;
QTest::newRow((addressB + " 0 last time").constData()) << address << 0 << 0;
QTest::newRow((addressB + " 1 again").constData()) << address << 1 << 1;
}
}
@ -1266,9 +1268,8 @@ void tst_QUdpSocket::setMulticastInterface_data()
if ((iface.flags() & QNetworkInterface::IsUp) == 0)
continue;
foreach (const QNetworkAddressEntry &entry, iface.addressEntries()) {
QTest::newRow(QString("%1:%2").arg(iface.name()).arg(entry.ip().toString()).toLatin1())
<< iface
<< entry.ip();
const QByteArray testName = iface.name().toLatin1() + ':' + entry.ip().toString().toLatin1();
QTest::newRow(testName.constData()) << iface << entry.ip();
}
}
}

View File

@ -423,15 +423,15 @@ void tst_QSslCertificate::subjectAlternativeNames()
QMapIterator<QSsl::AlternativeNameEntryType, QString> it(altSubjectNames);
while (it.hasNext()) {
it.next();
QString type;
QByteArray type;
if (it.key() == QSsl::EmailEntry)
type = QLatin1String("email");
type = "email";
else if (it.key() == QSsl::DnsEntry)
type = QLatin1String("DNS");
type = "DNS";
else
QFAIL("unsupported alternative name type");
QString entry = QString("%1:%2").arg(type).arg(it.value());
QVERIFY(fileContents.contains(entry.toLatin1()));
const QByteArray entry = type + ':' + it.value().toLatin1();
QVERIFY(fileContents.contains(entry));
}
// verify that each entry in fileContents is present in subjAltNames

View File

@ -279,13 +279,13 @@ void tst_QSslKey::toEncryptedPemOrDer_data()
<< "aAzZ`1234567890-=~!@#$%^&*()_+[]{}\\|;:'\",.<>/?"; // ### add more (?)
foreach (KeyInfo keyInfo, keyInfoList) {
foreach (QString password, passwords) {
QString testName = QString("%1-%2-%3-%4-%5").arg(keyInfo.fileInfo.fileName())
.arg(keyInfo.algorithm == QSsl::Rsa ? "RSA" :
(keyInfo.algorithm == QSsl::Dsa ? "DSA" : "EC"))
.arg(keyInfo.type == QSsl::PrivateKey ? "PrivateKey" : "PublicKey")
.arg(keyInfo.format == QSsl::Pem ? "PEM" : "DER")
.arg(password);
QTest::newRow(testName.toLatin1())
const QByteArray testName = keyInfo.fileInfo.fileName().toLatin1()
+ '-' + (keyInfo.algorithm == QSsl::Rsa ? "RSA" :
(keyInfo.algorithm == QSsl::Dsa ? "DSA" : "EC"))
+ '-' + (keyInfo.type == QSsl::PrivateKey ? "PrivateKey" : "PublicKey")
+ '-' + (keyInfo.format == QSsl::Pem ? "PEM" : "DER")
+ password.toLatin1();
QTest::newRow(testName.constData())
<< keyInfo.fileInfo.absoluteFilePath() << keyInfo.algorithm << keyInfo.type
<< keyInfo.format << password;
}