summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2022-06-02 13:50:12 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2022-06-03 21:53:14 +0200
commit3dcf1779be43373f820fb924c3fed21d05d5c5d2 (patch)
treed95a6e03d1ffb47f2d8b172b5eb1c14d6c918d3b /tests/auto/corelib/io
parent259df3ca0b860f6ea485e7121dd7931f6ee18464 (diff)
tst_QUrlQuery: improve formatting of lists of pairs of strings
The compare() implementation made its actual and expected seem to have different types (using a typedef name for one, when the other was of the type that expands to) and the formatter it used was needlessly clunky. Use modern string literals and package a repeated null-or-quoted representation as a lambda, inline the resulting simplified prettyElement() into prettyPair(), which can now just take a pair rather than an iterator. Short-cut the empty list so that the comma-joined accumulation could initialize with the first entry and loop over the rest, always joining with a comma. Undo commit f776595cc10aaafc7162f382a8fa11afffb0e708's mistaken update to the copyright header and update correctly. Change-Id: I99258dafa01e79f9ec384d9b375a59376eb7fb53 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/io')
-rw-r--r--tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp48
1 files changed, 18 insertions, 30 deletions
diff --git a/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp b/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp
index c6985557d1..0fc4e3902b 100644
--- a/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp
+++ b/tests/auto/corelib/io/qurlquery/tst_qurlquery.cpp
@@ -1,4 +1,5 @@
-// Copyright (C) 2016 Intel Corporation.
+// Copyright (C) 2022 The Qt Company Ltd.
+// Copyright (C) 2012 Intel Corporation.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtCore/QUrlQuery>
@@ -8,6 +9,8 @@ typedef QList<QPair<QString, QString> > QueryItems;
Q_DECLARE_METATYPE(QueryItems)
Q_DECLARE_METATYPE(QUrl::ComponentFormattingOptions)
+using namespace Qt::StringLiterals;
+
class tst_QUrlQuery : public QObject
{
Q_OBJECT
@@ -42,42 +45,27 @@ private Q_SLOTS:
void old_hasQueryItem();
};
-static QString prettyElement(const QString &key, const QString &value)
-{
- QString result;
- if (key.isNull())
- result += "null -> ";
- else
- result += '"' + key + "\" -> ";
- if (value.isNull())
- result += "null";
- else
- result += '"' + value + '"';
- return result;
-}
-
-static QString prettyPair(QList<QPair<QString, QString> >::const_iterator it)
+static QString prettyPair(const QPair<QString, QString> &pair)
{
- return prettyElement(it->first, it->second);
+ const auto represent = [](const QString &s) {
+ return s.isNull() ? u"null"_s : u'"' + s + u'"';
+ };
+ return represent(pair.first) + " -> "_L1 + represent(pair.second);
}
-template <typename T>
-static QByteArray prettyList(const T &items)
+static QByteArray prettyList(const QueryItems &items)
{
- QString result = "(";
- bool first = true;
- typename T::const_iterator it = items.constBegin();
- for ( ; it != items.constEnd(); ++it) {
- if (!first)
- result += ", ";
- first = false;
- result += prettyPair(it);
- }
- result += QLatin1Char(')');
+ if (items.isEmpty())
+ return "()";
+ auto it = items.constBegin();
+ QString result = u'(' + prettyPair(*it);
+ for (++it; it != items.constEnd(); ++it)
+ result += ", "_L1 + prettyPair(*it);
+ result += u')';
return result.toLocal8Bit();
}
-static bool compare(const QList<QPair<QString, QString> > &actual, const QueryItems &expected,
+static bool compare(const QueryItems &actual, const QueryItems &expected,
const char *actualStr, const char *expectedStr, const char *file, int line)
{
return QTest::compare_helper(actual == expected, "Compared values are not the same",