summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJüri Valdmann <juri.valdmann@qt.io>2018-06-04 12:08:57 +0200
committerJüri Valdmann <juri.valdmann@qt.io>2018-06-06 06:10:38 +0000
commit542c5b698cb9586aac48cc4dda66a6a2f98c905e (patch)
treeedfdde1de98e132e6cb7bf4445638ed8f7ce8f3a /tests
parent6cd3360c4d5283893eeb1efe43e329073709b48c (diff)
Use range-based for instead of Q_FOREACH
Change-Id: Ibf016b795ff98fddfa29fb5dc63924a2d2159d71 Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/publicapi/tst_publicapi.cpp23
-rw-r--r--tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp4
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp23
-rw-r--r--tests/quicktestbrowser/main.cpp2
4 files changed, 29 insertions, 23 deletions
diff --git a/tests/auto/quick/publicapi/tst_publicapi.cpp b/tests/auto/quick/publicapi/tst_publicapi.cpp
index 27f1ec616..aa65509c3 100644
--- a/tests/auto/quick/publicapi/tst_publicapi.cpp
+++ b/tests/auto/quick/publicapi/tst_publicapi.cpp
@@ -55,7 +55,7 @@ private Q_SLOTS:
void publicAPI();
};
-static QList<const QMetaObject *> typesToCheck = QList<const QMetaObject *>()
+static const QList<const QMetaObject *> typesToCheck = QList<const QMetaObject *>()
<< &QQuickWebEngineView::staticMetaObject
<< &QQuickWebEngineCertificateError::staticMetaObject
<< &QQuickWebEngineDownloadItem::staticMetaObject
@@ -81,7 +81,7 @@ static QList<const QMetaObject *> typesToCheck = QList<const QMetaObject *>()
static QList<const char *> knownEnumNames = QList<const char *>();
-static QStringList hardcodedTypes = QStringList()
+static const QStringList hardcodedTypes = QStringList()
<< "QJSValue"
<< "QQmlListProperty<QQuickWebEngineScript>"
<< "QQmlWebChannel*"
@@ -92,7 +92,7 @@ static QStringList hardcodedTypes = QStringList()
<< "QWebEngineCookieStore*"
;
-static QStringList expectedAPI = QStringList()
+static const QStringList expectedAPI = QStringList()
<< "QQuickWebEngineAuthenticationDialogRequest.AuthenticationTypeHTTP --> AuthenticationType"
<< "QQuickWebEngineAuthenticationDialogRequest.AuthenticationTypeProxy --> AuthenticationType"
<< "QQuickWebEngineAuthenticationDialogRequest.accepted --> bool"
@@ -697,7 +697,7 @@ static bool isCheckedEnum(const QByteArray &typeName)
if (tokens.size() == 3) {
QByteArray &enumClass = tokens[0];
QByteArray &enumName = tokens[2];
- foreach (const QMetaObject *mo, typesToCheck) {
+ for (const QMetaObject *mo : typesToCheck) {
if (mo->className() != enumClass)
continue;
for (int i = mo->enumeratorOffset(); i < mo->enumeratorCount(); ++i)
@@ -706,7 +706,7 @@ static bool isCheckedEnum(const QByteArray &typeName)
}
} else if (tokens.size() == 1) {
QByteArray &enumName = tokens[0];
- foreach (const char *knownEnumName, knownEnumNames) {
+ for (const char *knownEnumName : qAsConst(knownEnumNames)) {
if (enumName == knownEnumName)
return true;
}
@@ -716,7 +716,7 @@ static bool isCheckedEnum(const QByteArray &typeName)
static bool isCheckedClass(const QByteArray &typeName)
{
- foreach (const QMetaObject *mo, typesToCheck) {
+ for (const QMetaObject *mo : typesToCheck) {
QByteArray moTypeName(mo->className());
if (moTypeName == typeName || moTypeName + "*" == typeName)
return true;
@@ -752,7 +752,8 @@ static void gatherAPI(const QString &prefix, const QMetaMethod &method, QStringL
*output << QString::fromLatin1("%1%2 --> %3").arg(prefix).arg(QString::fromLatin1(method.methodSignature())).arg(QString::fromLatin1(methodTypeName));
checkKnownType(methodTypeName);
- foreach (QByteArray paramType, method.parameterTypes())
+ const QList<QByteArray> paramTypes = method.parameterTypes();
+ for (const QByteArray &paramType : paramTypes)
checkKnownType(paramType);
}
}
@@ -773,23 +774,23 @@ static void gatherAPI(const QString &prefix, const QMetaObject *meta, QStringLis
void tst_publicapi::publicAPI()
{
QStringList actualAPI;
- foreach (const QMetaObject *meta, typesToCheck)
+ for (const QMetaObject *meta : typesToCheck)
gatherAPI(QString::fromLatin1(meta->className()) + ".", meta, &actualAPI);
// Uncomment to print the actual API.
// QStringList sortedAPI(actualAPI);
// std::sort(sortedAPI.begin(), sortedAPI.end());
- // foreach (QString actual, sortedAPI)
+ // for (const QString &actual : qAsConst(sortedAPI))
// printf(" << \"%s\"\n", qPrintable(actual));
// Make sure that nothing slips in the public API unintentionally.
- foreach (QString actual, actualAPI) {
+ for (const QString &actual : qAsConst(actualAPI)) {
if (!expectedAPI.contains(actual))
QEXPECT_FAIL("", qPrintable("Expected list is not up-to-date: " + actual), Continue);
QVERIFY2(expectedAPI.contains(actual), qPrintable(actual));
}
// Make sure that the expected list is up-to-date with intentionally added APIs.
- foreach (QString expected, expectedAPI) {
+ for (const QString &expected : expectedAPI) {
if (!actualAPI.contains(expected))
QEXPECT_FAIL("", qPrintable("Not implemented: " + expected), Continue);
QVERIFY2(actualAPI.contains(expected), qPrintable(expected));
diff --git a/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp b/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp
index 3c8025672..6209401cb 100644
--- a/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp
+++ b/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp
@@ -485,11 +485,11 @@ void tst_QWebEngineHistory::clear()
void tst_QWebEngineHistory::historyItemFromDeletedPage()
{
- QList<QWebEngineHistoryItem> items = page->history()->items();
+ const QList<QWebEngineHistoryItem> items = page->history()->items();
delete page;
page = 0;
- foreach (QWebEngineHistoryItem item, items) {
+ for (const QWebEngineHistoryItem &item : items) {
QVERIFY(!item.isValid());
QTRY_COMPARE(item.originalUrl(), QUrl());
QTRY_COMPARE(item.url(), QUrl());
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index 599d918b3..0015aa148 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -772,7 +772,8 @@ void tst_QWebEnginePage::updatePositionDependentActionsCrash()
QPoint pos(0, 0);
view.page()->updatePositionDependentActions(pos);
QMenu* contextMenu = 0;
- foreach (QObject* child, view.children()) {
+ const QList<QObject *> children = view.children();
+ for (QObject *child : children) {
contextMenu = qobject_cast<QMenu*>(child);
if (contextMenu)
break;
@@ -794,7 +795,8 @@ void tst_QWebEnginePage::contextMenuCrash()
view.page()->swallowContextMenuEvent(&event);
view.page()->updatePositionDependentActions(pos);
QMenu* contextMenu = 0;
- foreach (QObject* child, view.children()) {
+ const QList<QObject *> children = view.children();
+ for (QObject *child : children) {
contextMenu = qobject_cast<QMenu*>(child);
if (contextMenu)
break;
@@ -1838,8 +1840,8 @@ void tst_QWebEnginePage::findTextResult()
QCOMPARE(findTextSync(m_page, ""), false);
- QStringList words = (QStringList() << "foo" << "bar");
- foreach (QString subString, words) {
+ const QStringList words = { "foo", "bar" };
+ for (const QString &subString : words) {
QCOMPARE(findTextSync(m_page, subString), true);
QCOMPARE(findTextSync(m_page, ""), false);
}
@@ -1899,7 +1901,8 @@ void tst_QWebEnginePage::supportedContentType()
#endif
// Add supported image types...
- Q_FOREACH (const QByteArray& imageType, QImageWriter::supportedImageFormats()) {
+ const QList<QByteArray> supportedImageFormats = QImageWriter::supportedImageFormats();
+ for (const QByteArray &imageType : supportedImageFormats) {
const QString mimeType = getMimeTypeForExtension(imageType);
if (!mimeType.isEmpty())
contentTypes << mimeType;
@@ -1908,10 +1911,10 @@ void tst_QWebEnginePage::supportedContentType()
// Get the mime types supported by webengine...
const QStringList supportedContentTypes = m_page->supportedContentTypes();
- Q_FOREACH (const QString& mimeType, contentTypes)
+ for (const QString &mimeType : qAsConst(contentTypes))
QVERIFY2(supportedContentTypes.contains(mimeType), QString("'%1' is not a supported content type!").arg(mimeType).toLatin1());
- Q_FOREACH (const QString& mimeType, contentTypes)
+ for (const QString &mimeType : qAsConst(contentTypes))
QVERIFY2(m_page->supportsContentType(mimeType), QString("Cannot handle content types '%1'!").arg(mimeType).toLatin1());
#endif
}
@@ -2282,7 +2285,8 @@ void tst_QWebEnginePage::renderWidgetHostViewNotShowTopLevel()
// Make sure that RenderWidgetHostViewQtDelegateWidgets are not shown as top-level.
// They should only be made visible when parented to a QWebEngineView.
- foreach (QWidget *widget, QApplication::topLevelWidgets())
+ const QList<QWidget *> widgets = QApplication::topLevelWidgets();
+ for (QWidget *widget : widgets)
QCOMPARE(widget->isVisible(), false);
}
@@ -3612,7 +3616,8 @@ void tst_QWebEnginePage::setUrlToBadPort()
static QStringList collectHistoryUrls(QWebEngineHistory *history)
{
QStringList urls;
- foreach (const QWebEngineHistoryItem &i, history->items())
+ const QList<QWebEngineHistoryItem> items = history->items();
+ for (const QWebEngineHistoryItem &i : items)
urls << i.url().toString();
return urls;
}
diff --git a/tests/quicktestbrowser/main.cpp b/tests/quicktestbrowser/main.cpp
index 45661b5d4..00c1ee4ad 100644
--- a/tests/quicktestbrowser/main.cpp
+++ b/tests/quicktestbrowser/main.cpp
@@ -47,7 +47,7 @@ static QUrl startupUrl()
QUrl ret;
QStringList args(qApp->arguments());
args.takeFirst();
- Q_FOREACH (const QString& arg, args) {
+ for (const QString &arg : qAsConst(args)) {
if (arg.startsWith(QLatin1Char('-')))
continue;
ret = Utils::fromUserInput(arg);