summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2019-05-19 23:10:38 +0200
committerMarc Mutz <marc.mutz@kdab.com>2019-06-13 09:40:26 +0200
commitd2ed1074d051c870e7191d0a31f48fae9759e9d7 (patch)
tree5da6f8ee3e54b4dc93b38880067e657b767fa964 /tests
parent18e7e82d3f23a2a6954308c7a7c49ec23344b593 (diff)
tests: remove the last uses of Java-style iterators
... except where they are actually the component under test. Java-style iterators are scheduled for deprecation. Change-Id: If4399f7f74c5ffc0f7e65205e422edfa1d908ee8 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/global/qlogging/tst_qlogging.cpp14
-rw-r--r--tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp8
-rw-r--r--tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp4
-rw-r--r--tests/auto/other/qabstractitemmodelutils/dynamictreemodel.cpp17
-rw-r--r--tests/auto/other/qabstractitemmodelutils/dynamictreemodel.h2
-rw-r--r--tests/benchmarks/gui/painting/qtransform/tst_qtransform.cpp12
6 files changed, 23 insertions, 34 deletions
diff --git a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp
index f212fe6f27..23507ec2e6 100644
--- a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp
+++ b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp
@@ -870,12 +870,14 @@ void tst_qmessagehandler::setMessagePattern()
#endif
// make sure there is no QT_MESSAGE_PATTERN in the environment
- QStringList environment = m_baseEnvironment;
- QMutableListIterator<QString> iter(environment);
- while (iter.hasNext()) {
- if (iter.next().startsWith("QT_MESSAGE_PATTERN"))
- iter.remove();
- }
+ QStringList environment;
+ environment.reserve(m_baseEnvironment.size());
+ const auto doesNotStartWith = [](QLatin1String s) {
+ return [s](const QString &str) { return !str.startsWith(s); };
+ };
+ std::copy_if(m_baseEnvironment.cbegin(), m_baseEnvironment.cend(),
+ std::back_inserter(environment),
+ doesNotStartWith(QLatin1String("QT_MESSAGE_PATTERN")));
process.setEnvironment(environment);
process.start(appExe);
diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
index 550d80501e..3e5f38d4bc 100644
--- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
@@ -4147,10 +4147,10 @@ void tst_QNetworkReply::ioGetFromHttpWithCache()
request.setAttribute(QNetworkRequest::CacheSaveControlAttribute, false);
QFETCH(QStringList, extraHttpHeaders);
- QStringListIterator it(extraHttpHeaders);
- while (it.hasNext()) {
- QString header = it.next();
- QString value = it.next();
+ QVERIFY(extraHttpHeaders.size() % 2 == 0);
+ for (auto it = extraHttpHeaders.cbegin(), end = extraHttpHeaders.cend(); it != end; /*double-stepping*/) {
+ QString header = *it++;
+ QString value = *it++;
request.setRawHeader(header.toLatin1(), value.toLatin1()); // To latin1? Deal with it!
}
diff --git a/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp b/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp
index 0c8535f2de..efc0c26076 100644
--- a/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp
+++ b/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp
@@ -401,9 +401,7 @@ void tst_QSslCertificate::subjectAlternativeNames()
certificate.subjectAlternativeNames();
// verify that each entry in subjAltNames is present in fileContents
- QMapIterator<QSsl::AlternativeNameEntryType, QString> it(altSubjectNames);
- while (it.hasNext()) {
- it.next();
+ for (auto it = altSubjectNames.cbegin(), end = altSubjectNames.cend(); it != end; ++it) {
QByteArray type;
if (it.key() == QSsl::EmailEntry)
type = "email";
diff --git a/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.cpp b/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.cpp
index fc979bce2d..c8698242d5 100644
--- a/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.cpp
+++ b/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.cpp
@@ -80,13 +80,9 @@ qint64 DynamicTreeModel::findParentId(qint64 searchId) const
if (searchId <= 0)
return -1;
- QHashIterator<qint64, QList<QList<qint64> > > i(m_childItems);
- while (i.hasNext()) {
- i.next();
- QListIterator<QList<qint64> > j(i.value());
- while (j.hasNext()) {
- QList<qint64> l = j.next();
- if (l.contains(searchId))
+ for (auto i = m_childItems.cbegin(), end = m_childItems.cend(); i != end; ++i) {
+ for (const auto &list : i.value()) {
+ if (list.contains(searchId))
return i.key();
}
}
@@ -163,13 +159,12 @@ ModelChangeCommand::ModelChangeCommand(DynamicTreeModel *model, QObject *parent)
{
}
-QModelIndex ModelChangeCommand::findIndex(QList<int> rows)
+QModelIndex ModelChangeCommand::findIndex(const QList<int> &rows) const
{
const int col = 0;
QModelIndex parent = QModelIndex();
- QListIterator<int> i(rows);
- while (i.hasNext()) {
- parent = m_model->index(i.next(), col, parent);
+ for (int row : rows) {
+ parent = m_model->index(row, col, parent);
if (!parent.isValid())
qFatal("%s: parent must be valid", Q_FUNC_INFO);
}
diff --git a/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.h b/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.h
index 709751dd27..0807ffbe94 100644
--- a/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.h
+++ b/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.h
@@ -97,7 +97,7 @@ public:
m_rowNumbers = rowNumbers;
}
- QModelIndex findIndex(QList<int> rows);
+ QModelIndex findIndex(const QList<int> &rows) const;
void setStartRow(int row)
{
diff --git a/tests/benchmarks/gui/painting/qtransform/tst_qtransform.cpp b/tests/benchmarks/gui/painting/qtransform/tst_qtransform.cpp
index d7a7f383ac..12e85d4842 100644
--- a/tests/benchmarks/gui/painting/qtransform/tst_qtransform.cpp
+++ b/tests/benchmarks/gui/painting/qtransform/tst_qtransform.cpp
@@ -167,9 +167,7 @@ void tst_QTransform::func##_data() \
{ \
QTest::addColumn<QTransform>("transform"); \
QMap<const char *, QTransform> x = generateTransforms(); \
- QMapIterator<const char *, QTransform> it(x); \
- while (it.hasNext()) { \
- it.next(); \
+ for (auto it = x.begin(), end = x.end(); it != end; ++it) { \
QTest::newRow(it.key()) << it.value(); \
} \
}
@@ -180,14 +178,10 @@ void tst_QTransform::func##_data() \
QTest::addColumn<QTransform>("x1"); \
QTest::addColumn<QTransform>("x2"); \
QMap<const char *, QTransform> x = generateTransforms(); \
- QMapIterator<const char *, QTransform> it(x); \
- while (it.hasNext()) { \
- it.next(); \
+ for (auto it = x.cbegin(), end = x.cend(); it != end; ++it) { \
const char *key1 = it.key(); \
QTransform x1 = it.value(); \
- QMapIterator<const char *, QTransform> it2(x); \
- while (it2.hasNext()) { \
- it2.next(); \
+ for (auto it2 = x.cbegin(), end = x.cend(); it2 != end; ++it2) { \
QTest::newRow(QString("%1 + %2").arg(key1).arg(it2.key()).toLatin1().constData()) \
<< x1 << it2.value(); \
} \