summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qurluts46/tst_qurluts46.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/io/qurluts46/tst_qurluts46.cpp')
-rw-r--r--tests/auto/corelib/io/qurluts46/tst_qurluts46.cpp89
1 files changed, 47 insertions, 42 deletions
diff --git a/tests/auto/corelib/io/qurluts46/tst_qurluts46.cpp b/tests/auto/corelib/io/qurluts46/tst_qurluts46.cpp
index a550397ee8..d163ed19bf 100644
--- a/tests/auto/corelib/io/qurluts46/tst_qurluts46.cpp
+++ b/tests/auto/corelib/io/qurluts46/tst_qurluts46.cpp
@@ -1,34 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2021 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtCore/QUrl>
#include <QtCore/QFile>
#include <QTest>
+#include <QSet>
+#include <QByteArray>
#include <algorithm>
class tst_QUrlUts46 : public QObject
@@ -39,11 +16,11 @@ private Q_SLOTS:
void idnaTestV2();
private:
- // All error codes:
- // A3, A4_1, A4_2,
+ // All error codes in UTR #46 revision 31 (Unicode 15.1):
+ // A4_1, A4_2,
// B1, B2, B3, B4, B5, B6,
// C1, C2,
- // P1, P4,
+ // P4,
// V1, V2, V3, V5, V6,
// X4_2
//
@@ -51,7 +28,38 @@ private:
static const QSet<QByteArray> fatalErrors;
};
-const QSet<QByteArray> tst_QUrlUts46::fatalErrors = { "A3", "A4_2", "P1", "X4_2" };
+const QSet<QByteArray> tst_QUrlUts46::fatalErrors = {
+ "A4_2", // Empty ASCII label
+};
+
+/**
+ * Replace \uXXXX escapes in test case fields.
+ */
+static QString unescapeField(const QString &field)
+{
+ static const QRegularExpression re(R"(\\u([[:xdigit:]]{4}))");
+
+ QString result;
+ qsizetype lastIdx = 0;
+
+ for (const auto &match : re.globalMatch(field)) {
+ // Add stuff before the match
+ result.append(field.mid(lastIdx, match.capturedStart() - lastIdx));
+ bool ok = false;
+ auto c = match.captured(1).toUInt(&ok, 16);
+ if (!ok) {
+ qFatal("Failed to parse a Unicode escape: %s", qPrintable(match.captured(1)));
+ }
+
+ result.append(QChar(c));
+ lastIdx = match.capturedEnd();
+ }
+
+ // Append the unescaped end
+ result.append(field.mid(lastIdx));
+
+ return result;
+}
void tst_QUrlUts46::idnaTestV2_data()
{
@@ -73,7 +81,7 @@ void tst_QUrlUts46::idnaTestV2_data()
Q_ASSERT(s.startsWith('[') && s.endsWith(']'));
- const auto errors = s.sliced(1, s.length() - 2).split(',');
+ const auto errors = s.sliced(1, s.size() - 2).split(',');
// NOTE: empty string is not in fatalErrors and it's ok
return std::all_of(errors.begin(), errors.end(),
[](auto &e) { return !fatalErrors.contains(e.trimmed()); });
@@ -92,7 +100,7 @@ void tst_QUrlUts46::idnaTestV2_data()
Q_ASSERT(fields.size() == 7);
for (auto &field : fields)
- field = field.trimmed();
+ field = unescapeField(field.trimmed()).toUtf8();
const QString &source = fields[0];
QString toUnicode = fields[1].isEmpty() ? source : fields[1];
@@ -118,22 +126,19 @@ void tst_QUrlUts46::idnaTestV2()
QFETCH(QString, toAsciiT);
QFETCH(bool, toAsciiTOk);
- auto dashesOk = [](const QString &domain) {
- const auto labels = domain.split(u'.');
- return std::all_of(labels.begin(), labels.end(), [](const QString &label) {
- return label.isEmpty() || !(label.startsWith(u'-') || label.endsWith(u'-'));
- });
- };
-
QString toAceN = QUrl::toAce(source);
- if (toAsciiNOk && dashesOk(toAsciiN))
+ if (toUnicodeOk && toAsciiNOk)
QCOMPARE(toAceN, toAsciiN);
+ else if (toAsciiNOk)
+ QVERIFY(toAceN.isEmpty() || toAceN == toAsciiN);
else
QCOMPARE(toAceN, QString());
QString toAceT = QUrl::toAce(source, QUrl::AceTransitionalProcessing);
- if (toAsciiTOk && dashesOk(toAsciiT))
+ if (toUnicodeOk && toAsciiTOk)
QCOMPARE(toAceT, toAsciiT);
+ else if (toAsciiTOk)
+ QVERIFY(toAceT.isEmpty() || toAceT == toAsciiT);
else
QCOMPARE(toAceT, QString());