summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp')
-rw-r--r--tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp307
1 files changed, 230 insertions, 77 deletions
diff --git a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp
index e4f3759c6f..35a734cf02 100644
--- a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp
+++ b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp
@@ -1,6 +1,6 @@
// Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com>
// Copyright (C) 2019 Mail.ru Group.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#undef QT_NO_CAST_FROM_ASCII
#undef QT_NO_CAST_TO_ASCII
@@ -23,6 +23,8 @@
Q_DECLARE_METATYPE(QLatin1String)
+namespace {
+
struct QAnyStringViewUsingL1 : QAnyStringView {}; // QAnyStringView with Latin-1 content
struct QAnyStringViewUsingU8 : QAnyStringView {}; // QAnyStringView with Utf-8 content
struct QAnyStringViewUsingU16 : QAnyStringView {}; // QAnyStringView with Utf-16 content
@@ -30,7 +32,6 @@ struct QAnyStringViewUsingU16 : QAnyStringView {}; // QAnyStringView with Utf-1
template <typename T>
QString toQString(const T &t) { return QString(t); }
QString toQString(QStringView view) { return view.toString(); }
-QString toQString(QUtf8StringView view) { return view.toString(); }
template <typename Iterable>
QStringList toQStringList(const Iterable &i) {
@@ -43,44 +44,7 @@ QStringList toQStringList(const Iterable &i) {
template <typename LHS, typename RHS>
constexpr bool is_fake_comparator_v = false;
-// FIXME: these are missing at the time of writing, add them, then remove the dummies here:
-#define MAKE_RELOP(op, A1, A2) \
- static bool operator op (A1 lhs, A2 rhs) \
- { return toQString(lhs) op toQString(rhs); } \
- /*end*/
-#define MAKE_ALL(A1, A2) \
- template <> constexpr bool is_fake_comparator_v<A1, A2> = true; \
- MAKE_RELOP(==, A1, A2) \
- MAKE_RELOP(!=, A1, A2) \
- MAKE_RELOP(<, A1, A2) \
- MAKE_RELOP(>, A1, A2) \
- MAKE_RELOP(<=, A1, A2) \
- MAKE_RELOP(>=, A1, A2) \
- /*end*/
-
-MAKE_ALL(QByteArray, QChar)
-MAKE_ALL(QByteArray, QLatin1String)
-MAKE_ALL(QByteArray, char16_t)
-MAKE_ALL(char16_t, QByteArray)
-
-MAKE_ALL(const char*, QChar)
-
-MAKE_ALL(QChar, QByteArray)
-MAKE_ALL(QChar, const char*)
-MAKE_ALL(QChar, QUtf8StringView)
-
-MAKE_ALL(QString, QUtf8StringView)
-MAKE_ALL(QByteArray, QUtf8StringView)
-MAKE_ALL(const char*, QUtf8StringView)
-
-MAKE_ALL(QUtf8StringView, QChar)
-MAKE_ALL(QUtf8StringView, char16_t)
-MAKE_ALL(QUtf8StringView, QStringView)
-MAKE_ALL(QUtf8StringView, QLatin1String)
-
-#undef MAKE_ALL
-#undef MAKE_RELOP
-// END FIXME
+} // namespace
static constexpr int sign(int i) noexcept
{
@@ -130,6 +94,7 @@ private Q_SLOTS:
void overload_QAnyStringView() { overload<QAnyStringView>(); }
void overload_QLatin1String() { overload<QLatin1String>(); }
void overload_QByteArray() { overload<QByteArray>(); }
+ void overload_QByteArrayView() { overload<QByteArrayView>(); }
void overload_const_char_star() { overload<const char*>(); }
void overload_const_char8_t_star() { IF_CHAR8T(overload<const char8_t*>()); }
void overload_const_char16_t_star() { overload<const char16_t*>(); }
@@ -160,7 +125,7 @@ private:
void compare_impl() const;
private Q_SLOTS:
- // test all combinations of {QChar, char16_t, QString, QStringView, QLatin1String, QByteArray, const char*}
+ // test all combinations of {QChar, char16_t, QString, QStringView, QLatin1String, QByteArray/View, const char*}
void compare_QChar_QChar_data() { compare_data(false); }
void compare_QChar_QChar() { compare_impl<QChar, QChar>(); }
void compare_QChar_char16_t_data() { compare_data(false); }
@@ -175,6 +140,8 @@ private Q_SLOTS:
void compare_QChar_QLatin1String() { compare_impl<QChar, QLatin1String>(); }
void compare_QChar_QByteArray_data() { compare_data(false); }
void compare_QChar_QByteArray() { compare_impl<QChar, QByteArray>(); }
+ void compare_QChar_QByteArrayView_data() { compare_data(false); }
+ void compare_QChar_QByteArrayView() { compare_impl<QChar, QByteArrayView>(); }
void compare_QChar_const_char_star_data() { compare_data(false); }
void compare_QChar_const_char_star() { compare_impl<QChar, const char *>(); }
@@ -192,6 +159,8 @@ private Q_SLOTS:
void compare_char16_t_QLatin1String() { compare_impl<char16_t, QLatin1String>(); }
void compare_char16_t_QByteArray_data() { compare_data(false); }
void compare_char16_t_QByteArray() { compare_impl<char16_t, QByteArray>(); }
+ void compare_char16_t_QByteArrayView_data() { compare_data(false); }
+ void compare_char16_t_QByteArrayView() { compare_impl<char16_t, QByteArrayView>(); }
//void compare_char16_t_const_char_star_data() { compare_data(false); }
//void compare_char16_t_const_char_star() { compare_impl<char16_t, const char *>(); }
@@ -209,6 +178,8 @@ private Q_SLOTS:
void compare_QString_QLatin1String() { compare_impl<QString, QLatin1String>(); }
void compare_QString_QByteArray_data() { compare_data(); }
void compare_QString_QByteArray() { compare_impl<QString, QByteArray>(); }
+ void compare_QString_QByteArrayView_data() { compare_data(); }
+ void compare_QString_QByteArrayView() { compare_impl<QString, QByteArrayView>(); }
void compare_QString_const_char_star_data() { compare_data(); }
void compare_QString_const_char_star() { compare_impl<QString, const char *>(); }
@@ -221,15 +192,15 @@ private Q_SLOTS:
void compare_QStringView_QStringView_data() { compare_data(); }
void compare_QStringView_QStringView() { compare_impl<QStringView, QStringView>(); }
void compare_QStringView_QUtf8StringView_data() { compare_data(); }
- void compare_QStringView_QUtf8StringView() { compare_impl<QStringView, QStringView>(); }
+ void compare_QStringView_QUtf8StringView() { compare_impl<QStringView, QUtf8StringView>(); }
void compare_QStringView_QLatin1String_data() { compare_data(); }
void compare_QStringView_QLatin1String() { compare_impl<QStringView, QLatin1String>(); }
-#ifdef NOT_YET_IMPLMENTED
void compare_QStringView_QByteArray_data() { compare_data(); }
void compare_QStringView_QByteArray() { compare_impl<QStringView, QByteArray>(); }
+ void compare_QStringView_QByteArrayView_data() { compare_data(); }
+ void compare_QStringView_QByteArrayView() { compare_impl<QStringView, QByteArrayView>(); }
void compare_QStringView_const_char_star_data() { compare_data(); }
void compare_QStringView_const_char_star() { compare_impl<QStringView, const char *>(); }
-#endif
void compare_QUtf8StringView_QChar_data() { compare_data(false); }
void compare_QUtf8StringView_QChar() { compare_impl<QUtf8StringView, QChar>(); }
@@ -243,12 +214,12 @@ private Q_SLOTS:
void compare_QUtf8StringView_QUtf8StringView() { compare_impl<QUtf8StringView, QUtf8StringView>(); }
void compare_QUtf8StringView_QLatin1String_data() { compare_data(); }
void compare_QUtf8StringView_QLatin1String() { compare_impl<QUtf8StringView, QLatin1String>(); }
-#ifdef NOT_YET_IMPLMENTED
void compare_QUtf8StringView_QByteArray_data() { compare_data(); }
void compare_QUtf8StringView_QByteArray() { compare_impl<QUtf8StringView, QByteArray>(); }
+ void compare_QUtf8StringView_QByteArrayView_data() { compare_data(); }
+ void compare_QUtf8StringView_QByteArrayView() { compare_impl<QUtf8StringView, QByteArrayView>(); }
void compare_QUtf8StringView_const_char_star_data() { compare_data(); }
void compare_QUtf8StringView_const_char_star() { compare_impl<QUtf8StringView, const char *>(); }
-#endif
void compare_QLatin1String_QChar_data() { compare_data(false); }
void compare_QLatin1String_QChar() { compare_impl<QLatin1String, QChar>(); }
@@ -264,6 +235,8 @@ private Q_SLOTS:
void compare_QLatin1String_QLatin1String() { compare_impl<QLatin1String, QLatin1String>(); }
void compare_QLatin1String_QByteArray_data() { compare_data(); }
void compare_QLatin1String_QByteArray() { compare_impl<QLatin1String, QByteArray>(); }
+ void compare_QLatin1String_QByteArrayView_data() { compare_data(); }
+ void compare_QLatin1String_QByteArrayView() { compare_impl<QLatin1String, QByteArrayView>(); }
void compare_QLatin1String_const_char_star_data() { compare_data(); }
void compare_QLatin1String_const_char_star() { compare_impl<QLatin1String, const char *>(); }
@@ -273,31 +246,54 @@ private Q_SLOTS:
void compare_QByteArray_char16_t() { compare_impl<QByteArray, char16_t>(); }
void compare_QByteArray_QString_data() { compare_data(); }
void compare_QByteArray_QString() { compare_impl<QByteArray, QString>(); }
-#ifdef NOT_YET_IMPLEMENTED
void compare_QByteArray_QStringView_data() { compare_data(); }
void compare_QByteArray_QStringView() { compare_impl<QByteArray, QStringView>(); }
-#endif
void compare_QByteArray_QUtf8StringView_data() { compare_data(); }
void compare_QByteArray_QUtf8StringView() { compare_impl<QByteArray, QUtf8StringView>(); }
void compare_QByteArray_QLatin1String_data() { compare_data(); }
void compare_QByteArray_QLatin1String() { compare_impl<QByteArray, QLatin1String>(); }
void compare_QByteArray_QByteArray_data() { compare_data(); }
void compare_QByteArray_QByteArray() { compare_impl<QByteArray, QByteArray>(); }
+ void compare_QByteArray_QByteArrayView_data() { compare_data(); }
+ void compare_QByteArray_QByteArrayView() { compare_impl<QByteArray, QByteArrayView>(); }
void compare_QByteArray_const_char_star_data() { compare_data(); }
void compare_QByteArray_const_char_star() { compare_impl<QByteArray, const char *>(); }
+ void compare_QByteArrayView_QChar_data() { compare_data(false); }
+ void compare_QByteArrayView_QChar() { compare_impl<QByteArrayView, QChar>(); }
+ void compare_QByteArrayView_char16_t_data() { compare_data(false); }
+ void compare_QByteArrayView_char16_t() { compare_impl<QByteArrayView, char16_t>(); }
+ void compare_QByteArrayView_QString_data() { compare_data(); }
+ void compare_QByteArrayView_QString() { compare_impl<QByteArrayView, QString>(); }
+ void compare_QByteArrayView_QStringView_data() { compare_data(); }
+ void compare_QByteArrayView_QStringView() { compare_impl<QByteArrayView, QStringView>(); }
+ void compare_QByteArrayView_QUtf8StringView_data() { compare_data(); }
+ void compare_QByteArrayView_QUtf8StringView() { compare_impl<QByteArrayView, QUtf8StringView>(); }
+ void compare_QByteArrayView_QLatin1String_data() { compare_data(); }
+ void compare_QByteArrayView_QLatin1String() { compare_impl<QByteArrayView, QLatin1String>(); }
+ void compare_QByteArrayView_QByteArray_data() { compare_data(); }
+ void compare_QByteArrayView_QByteArray() { compare_impl<QByteArrayView, QByteArray>(); }
+ void compare_QByteArrayView_QByteArrayView_data() { compare_data(); }
+ void compare_QByteArrayView_QByteArrayView() { compare_impl<QByteArrayView, QByteArrayView>(); }
+ void compare_QByteArrayView_const_char_star_data() { compare_data(); }
+ void compare_QByteArrayView_const_char_star() { compare_impl<QByteArrayView, const char *>(); }
+
void compare_const_char_star_QChar_data() { compare_data(false); }
void compare_const_char_star_QChar() { compare_impl<const char *, QChar>(); }
//void compare_const_char_star_char16_t_data() { compare_data(false); }
//void compare_const_char_star_char16_t() { compare_impl<const char *, char16_t>(); }
void compare_const_char_star_QString_data() { compare_data(); }
void compare_const_char_star_QString() { compare_impl<const char *, QString>(); }
+ void compare_const_char_star_QStringView_data() { compare_data(); }
+ void compare_const_char_star_QStringView() { compare_impl<const char *, QStringView>(); }
void compare_const_char_star_QUtf8StringView_data() { compare_data(); }
void compare_const_char_star_QUtf8StringView() { compare_impl<const char *, QUtf8StringView>(); }
void compare_const_char_star_QLatin1String_data() { compare_data(false); }
void compare_const_char_star_QLatin1String() { compare_impl<const char *, QLatin1String>(); }
void compare_const_char_star_QByteArray_data() { compare_data(); }
void compare_const_char_star_QByteArray() { compare_impl<const char *, QByteArray>(); }
+ void compare_const_char_star_QByteArrayView_data() { compare_data(); }
+ void compare_const_char_star_QByteArrayView() { compare_impl<const char *, QByteArrayView>(); }
//void compare_const_char_star_const_char_star_data() { compare_data(); }
//void compare_const_char_star_const_char_star() { compare_impl<const char *, const char *>(); }
@@ -321,6 +317,8 @@ private Q_SLOTS:
void member_compare_QChar_QLatin1String() { member_compare_impl<QChar, QLatin1String>(); }
void member_compare_QChar_QByteArray_data() { member_compare_data(false); }
void member_compare_QChar_QByteArray() { member_compare_impl<QChar, QByteArray>(); }
+ void member_compare_QChar_QByteArrayView_data() { member_compare_data(false); }
+ void member_compare_QChar_QByteArrayView() { member_compare_impl<QChar, QByteArrayView>(); }
void member_compare_QChar_const_char_star_data() { member_compare_data(false); }
void member_compare_QChar_const_char_star() { member_compare_impl<QChar, const char *>(); }
#endif
@@ -339,6 +337,10 @@ private Q_SLOTS:
void member_compare_QString_QLatin1String() { member_compare_impl<QString, QLatin1String>(); }
void member_compare_QString_QByteArray_data() { member_compare_data(); }
void member_compare_QString_QByteArray() { member_compare_impl<QString, QByteArray>(); }
+#ifdef NOT_YET_IMPLEMENTED
+ void member_compare_QString_QByteArrayView_data() { member_compare_data(); }
+ void member_compare_QString_QByteArrayView() { member_compare_impl<QString, QByteArrayView>(); }
+#endif
void member_compare_QString_const_char_star_data() { member_compare_data(); }
void member_compare_QString_const_char_star() { member_compare_impl<QString, const char *>(); }
@@ -352,9 +354,13 @@ private Q_SLOTS:
void member_compare_QStringView_QStringView() { member_compare_impl<QStringView, QStringView>(); }
void member_compare_QStringView_QLatin1String_data() { member_compare_data(); }
void member_compare_QStringView_QLatin1String() { member_compare_impl<QStringView, QLatin1String>(); }
+ void member_compare_QStringView_QUtf8StringView_data() { member_compare_data(); }
+ void member_compare_QStringView_QUtf8StringView() { member_compare_impl<QStringView, QUtf8StringView>(); }
#ifdef NOT_YET_IMPLEMENTED
void member_compare_QStringView_QByteArray_data() { member_compare_data(); }
void member_compare_QStringView_QByteArray() { member_compare_impl<QStringView, QByteArray>(); }
+ void member_compare_QStringView_QByteArrayView_data() { member_compare_data(); }
+ void member_compare_QStringView_QByteArrayView() { member_compare_impl<QStringView, QByteArrayView>(); }
void member_compare_QStringView_const_char_star_data() { member_compare_data(); }
void member_compare_QStringView_const_char_star() { member_compare_impl<QStringView, const char *>(); }
#endif
@@ -371,12 +377,18 @@ private Q_SLOTS:
void member_compare_QLatin1String_QStringView() { member_compare_impl<QLatin1String, QStringView>(); }
void member_compare_QLatin1String_QLatin1String_data() { member_compare_data(); }
void member_compare_QLatin1String_QLatin1String() { member_compare_impl<QLatin1String, QLatin1String>(); }
+ void member_compare_QLatin1String_QUtf8StringView_data() { member_compare_data(); }
+ void member_compare_QLatin1String_QUtf8StringView() { member_compare_impl<QLatin1String, QUtf8StringView>(); }
#ifdef NOT_YET_IMPLEMENTED
void member_compare_QLatin1String_QByteArray_data() { member_compare_data(); }
void member_compare_QLatin1String_QByteArray() { member_compare_impl<QLatin1String, QByteArray>(); }
+ void member_compare_QLatin1String_QByteArrayView_data() { member_compare_data(); }
+ void member_compare_QLatin1String_QByteArrayView() { member_compare_impl<QLatin1String, QByteArrayView>(); }
void member_compare_QLatin1String_const_char_star_data() { member_compare_data(); }
void member_compare_QLatin1String_const_char_star() { member_compare_impl<QLatin1String, const char *>(); }
+#endif
+#ifdef NOT_YET_IMPLEMENTED
void member_compare_QByteArray_QChar_data() { member_compare_data(false); }
void member_compare_QByteArray_QChar() { member_compare_impl<QByteArray, QChar>(); }
void member_compare_QByteArray_char16_t_data() { member_compare_data(false); }
@@ -388,9 +400,41 @@ private Q_SLOTS:
#endif
void member_compare_QByteArray_QByteArray_data() { member_compare_data(); }
void member_compare_QByteArray_QByteArray() { member_compare_impl<QByteArray, QByteArray>(); }
+ void member_compare_QByteArray_QByteArrayView_data() { member_compare_data(); }
+ void member_compare_QByteArray_QByteArrayView() { member_compare_impl<QByteArray, QByteArrayView>(); }
void member_compare_QByteArray_const_char_star_data() { member_compare_data(); }
void member_compare_QByteArray_const_char_star() { member_compare_impl<QByteArray, const char *>(); }
+#ifdef NOT_YET_IMPLEMENTED
+ void member_compare_QByteArrayView_QChar_data() { member_compare_data(false); }
+ void member_compare_QByteArrayView_QChar() { member_compare_impl<QByteArrayView, QChar>(); }
+ void member_compare_QByteArrayView_char16_t_data() { member_compare_data(false); }
+ void member_compare_QByteArrayView_char16_t() { member_compare_impl<QByteArrayView, char16_t>(); }
+ void member_compare_QByteArrayView_QString_data() { member_compare_data(); }
+ void member_compare_QByteArrayView_QString() { member_compare_impl<QByteArrayView, QString>(); }
+ void member_compare_QByteArrayView_QLatin1String_data() { member_compare_data(); }
+ void member_compare_QByteArrayView_QLatin1String() { member_compare_impl<QByteArrayView, QLatin1String>(); }
+#endif
+ void member_compare_QByteArrayView_QByteArray_data() { member_compare_data(); }
+ void member_compare_QByteArrayView_QByteArray() { member_compare_impl<QByteArrayView, QByteArray>(); }
+ void member_compare_QByteArrayView_QByteArrayView_data() { member_compare_data(); }
+ void member_compare_QByteArrayView_QByteArrayView() { member_compare_impl<QByteArrayView, QByteArrayView>(); }
+ void member_compare_QByteArrayView_const_char_star_data() { member_compare_data(); }
+ void member_compare_QByteArrayView_const_char_star() { member_compare_impl<QByteArrayView, const char *>(); }
+
+#ifdef NOT_YET_IMPLEMENTED
+ void member_compare_QUtf8StringView_QChar_data() { member_compare_data(false); }
+ void member_compare_QUtf8StringView_QChar() { member_compare_impl<QUtf8StringView, QChar>(); }
+ void member_compare_QUtf8StringView_char16_t_data() { member_compare_data(false); }
+ void member_compare_QUtf8StringView_char16_t() { member_compare_impl<QUtf8StringView, char16_t>(); }
+#endif
+ void member_compare_QUtf8StringView_QString_data() { member_compare_data(); }
+ void member_compare_QUtf8StringView_QString() { member_compare_impl<QUtf8StringView, QString>(); }
+ void member_compare_QUtf8StringView_QLatin1String_data() { member_compare_data(); }
+ void member_compare_QUtf8StringView_QLatin1String() { member_compare_impl<QUtf8StringView, QLatin1String>(); }
+ void member_compare_QUtf8StringView_QUtf8StringView_data() { member_compare_data(); }
+ void member_compare_QUtf8StringView_QUtf8StringView() { member_compare_impl<QUtf8StringView, QUtf8StringView>(); }
+
private:
void localeAwareCompare_data();
template<typename LHS, typename RHS>
@@ -612,6 +656,7 @@ private:
void sliced_data();
template <typename String> void sliced_impl();
+ template <typename String> void slice_impl();
void first_data();
template <typename String> void first_impl();
@@ -632,8 +677,16 @@ private Q_SLOTS:
void mid_QUtf8StringView() { mid_impl<QUtf8StringView>(); }
void mid_QLatin1String_data() { mid_data(); }
void mid_QLatin1String() { mid_impl<QLatin1String>(); }
+ void mid_QAnyStringViewUsingL1_data() { mid_data(); }
+ void mid_QAnyStringViewUsingL1() { mid_impl<QAnyStringViewUsingL1>(); }
+ void mid_QAnyStringViewUsingU8_data() { mid_data(); }
+ void mid_QAnyStringViewUsingU8() { mid_impl<QAnyStringViewUsingU8>(); }
+ void mid_QAnyStringViewUsingU16_data() { mid_data(); }
+ void mid_QAnyStringViewUsingU16() { mid_impl<QAnyStringViewUsingU16>(); }
void mid_QByteArray_data() { mid_data(); }
void mid_QByteArray() { mid_impl<QByteArray>(); }
+ void mid_QByteArrayView_data() { mid_data(); }
+ void mid_QByteArrayView() { mid_impl<QByteArrayView>(); }
void left_QString_data() { left_data(); }
void left_QString() { left_impl<QString>(); }
@@ -643,8 +696,16 @@ private Q_SLOTS:
void left_QUtf8StringView() { left_impl<QUtf8StringView>(); }
void left_QLatin1String_data() { left_data(); }
void left_QLatin1String() { left_impl<QLatin1String>(); }
+ void left_QAnyStringViewUsingL1_data() { left_data(); }
+ void left_QAnyStringViewUsingL1() { left_impl<QAnyStringViewUsingL1>(); }
+ void left_QAnyStringViewUsingU8_data() { left_data(); }
+ void left_QAnyStringViewUsingU8() { left_impl<QAnyStringViewUsingU8>(); }
+ void left_QAnyStringViewUsingU16_data() { left_data(); }
+ void left_QAnyStringViewUsingU16() { left_impl<QAnyStringViewUsingU16>(); }
void left_QByteArray_data();
void left_QByteArray() { left_impl<QByteArray>(); }
+ void left_QByteArrayView_data() { left_data(); }
+ void left_QByteArrayView() { left_impl<QByteArrayView>(); }
void right_QString_data() { right_data(); }
void right_QString() { right_impl<QString>(); }
@@ -654,8 +715,16 @@ private Q_SLOTS:
void right_QUtf8StringView() { right_impl<QUtf8StringView>(); }
void right_QLatin1String_data() { right_data(); }
void right_QLatin1String() { right_impl<QLatin1String>(); }
+ void right_QAnyStringViewUsingL1_data() { right_data(); }
+ void right_QAnyStringViewUsingL1() { right_impl<QAnyStringViewUsingL1>(); }
+ void right_QAnyStringViewUsingU8_data() { right_data(); }
+ void right_QAnyStringViewUsingU8() { right_impl<QAnyStringViewUsingU8>(); }
+ void right_QAnyStringViewUsingU16_data() { right_data(); }
+ void right_QAnyStringViewUsingU16() { right_impl<QAnyStringViewUsingU16>(); }
void right_QByteArray_data();
void right_QByteArray() { right_impl<QByteArray>(); }
+ void right_QByteArrayView_data() { right_data(); }
+ void right_QByteArrayView() { right_impl<QByteArrayView>(); }
void sliced_QString_data() { sliced_data(); }
void sliced_QString() { sliced_impl<QString>(); }
@@ -665,8 +734,21 @@ private Q_SLOTS:
void sliced_QLatin1String() { sliced_impl<QLatin1String>(); }
void sliced_QUtf8StringView_data() { sliced_data(); }
void sliced_QUtf8StringView() { sliced_impl<QUtf8StringView>(); }
+ void sliced_QAnyStringViewUsingL1_data() { sliced_data(); }
+ void sliced_QAnyStringViewUsingL1() { sliced_impl<QAnyStringViewUsingL1>(); }
+ void sliced_QAnyStringViewUsingU8_data() { sliced_data(); }
+ void sliced_QAnyStringViewUsingU8() { sliced_impl<QAnyStringViewUsingU8>(); }
+ void sliced_QAnyStringViewUsingU16_data() { sliced_data(); }
+ void sliced_QAnyStringViewUsingU16() { sliced_impl<QAnyStringViewUsingU16>(); }
void sliced_QByteArray_data() { sliced_data(); }
void sliced_QByteArray() { sliced_impl<QByteArray>(); }
+ void sliced_QByteArrayView_data() { sliced_data(); }
+ void sliced_QByteArrayView() { sliced_impl<QByteArrayView>(); }
+
+ void slice_QString_data() { sliced_data(); }
+ void slice_QString() { slice_impl<QString>(); }
+ void slice_QByteArray_data() { sliced_data(); }
+ void slice_QByteArray() { slice_impl<QByteArray>(); }
void first_truncate_QString_data() { first_data(); }
void first_truncate_QString() { first_impl<QString>(); }
@@ -676,8 +758,16 @@ private Q_SLOTS:
void first_truncate_QLatin1String() { first_impl<QLatin1String>(); }
void first_truncate_QUtf8StringView_data() { first_data(); }
void first_truncate_QUtf8StringView() { first_impl<QUtf8StringView>(); }
+ void first_truncate_QAnyStringViewUsingL1_data() { first_data(); }
+ void first_truncate_QAnyStringViewUsingL1() { first_impl<QAnyStringViewUsingL1>(); }
+ void first_truncate_QAnyStringViewUsingU8_data() { first_data(); }
+ void first_truncate_QAnyStringViewUsingU8() { first_impl<QAnyStringViewUsingU8>(); }
+ void first_truncate_QAnyStringViewUsingU16_data() { first_data(); }
+ void first_truncate_QAnyStringViewUsingU16() { first_impl<QAnyStringViewUsingU16>(); }
void first_truncate_QByteArray_data() { first_data(); }
void first_truncate_QByteArray() { first_impl<QByteArray>(); }
+ void first_truncate_QByteArrayView_data() { first_data(); }
+ void first_truncate_QByteArrayView() { first_impl<QByteArrayView>(); }
void last_QString_data() { last_data(); }
void last_QString() { last_impl<QString>(); }
@@ -687,19 +777,35 @@ private Q_SLOTS:
void last_QLatin1String() { last_impl<QLatin1String>(); }
void last_QUtf8StringView_data() { last_data(); }
void last_QUtf8StringView() { last_impl<QUtf8StringView>(); }
+ void last_QAnyStringViewUsingL1_data() { last_data(); }
+ void last_QAnyStringViewUsingL1() { last_impl<QAnyStringViewUsingL1>(); }
+ void last_QAnyStringViewUsingU8_data() { last_data(); }
+ void last_QAnyStringViewUsingU8() { last_impl<QAnyStringViewUsingU8>(); }
+ void last_QAnyStringViewUsingU16_data() { last_data(); }
+ void last_QAnyStringViewUsingU16() { last_impl<QAnyStringViewUsingU16>(); }
void last_QByteArray_data() { last_data(); }
void last_QByteArray() { last_impl<QByteArray>(); }
+ void last_QByteArrayView_data() { last_data(); }
+ void last_QByteArrayView() { last_impl<QByteArrayView>(); }
void chop_QString_data() { chop_data(); }
void chop_QString() { chop_impl<QString>(); }
void chop_QStringView_data() { chop_data(); }
void chop_QStringView() { chop_impl<QStringView>(); }
- void chop_QUtf8StringView_data() { chop_data(); }
- void chop_QUtf8StringView() { chop_impl<QUtf8StringView>(); }
void chop_QLatin1String_data() { chop_data(); }
void chop_QLatin1String() { chop_impl<QLatin1String>(); }
+ void chop_QUtf8StringView_data() { chop_data(); }
+ void chop_QUtf8StringView() { chop_impl<QUtf8StringView>(); }
+ void chop_QAnyStringViewUsingL1_data() { chop_data(); }
+ void chop_QAnyStringViewUsingL1() { chop_impl<QAnyStringViewUsingL1>(); }
+ void chop_QAnyStringViewUsingU8_data() { chop_data(); }
+ void chop_QAnyStringViewUsingU8() { chop_impl<QAnyStringViewUsingU8>(); }
+ void chop_QAnyStringViewUsingU16_data() { chop_data(); }
+ void chop_QAnyStringViewUsingU16() { chop_impl<QAnyStringViewUsingU16>(); }
void chop_QByteArray_data() { chop_data(); }
void chop_QByteArray() { chop_impl<QByteArray>(); }
+ void chop_QByteArrayView_data() { chop_data(); }
+ void chop_QByteArrayView() { chop_impl<QByteArrayView>(); }
private:
void trimmed_data();
@@ -714,6 +820,8 @@ private Q_SLOTS:
void trim_trimmed_QLatin1String() { trimmed_impl<QLatin1String>(); }
void trim_trimmed_QByteArray_data() { trimmed_data(); }
void trim_trimmed_QByteArray() { trimmed_impl<QByteArray>(); }
+ void trim_trimmed_QByteArrayView_data() { trimmed_data(); }
+ void trim_trimmed_QByteArrayView() { trimmed_impl<QByteArrayView>(); }
private:
void toNumber_data();
@@ -726,19 +834,23 @@ private Q_SLOTS:
void toNumber_QString() { toNumber_impl<QString>(); }
void toNumber_QStringView_data() { toNumber_data(); }
void toNumber_QStringView() { toNumber_impl<QStringView>(); }
- void toNumber_QByteArray_data() { toNumber_data(); }
- void toNumber_QByteArray() { toNumber_impl<QByteArray>(); }
void toNumber_QLatin1String_data() { toNumber_data(); }
void toNumber_QLatin1String() { toNumber_impl<QLatin1String>(); }
+ void toNumber_QByteArray_data() { toNumber_data(); }
+ void toNumber_QByteArray() { toNumber_impl<QByteArray>(); }
+ void toNumber_QByteArrayView_data() { toNumber_data(); }
+ void toNumber_QByteArrayView() { toNumber_impl<QByteArrayView>(); }
void toNumberWithBases_QString_data() { toNumberWithBases_data(); }
void toNumberWithBases_QString() { toNumberWithBases_impl<QString>(); }
void toNumberWithBases_QStringView_data() { toNumberWithBases_data(); }
void toNumberWithBases_QStringView() { toNumberWithBases_impl<QStringView>(); }
- void toNumberWithBases_QByteArray_data() { toNumberWithBases_data(); }
- void toNumberWithBases_QByteArray() { toNumberWithBases_impl<QByteArray>(); }
void toNumberWithBases_QLatin1String_data() { toNumberWithBases_data(); }
void toNumberWithBases_QLatin1String() { toNumberWithBases_impl<QLatin1String>(); }
+ void toNumberWithBases_QByteArray_data() { toNumberWithBases_data(); }
+ void toNumberWithBases_QByteArray() { toNumberWithBases_impl<QByteArray>(); }
+ void toNumberWithBases_QByteArrayView_data() { toNumberWithBases_data(); }
+ void toNumberWithBases_QByteArrayView() { toNumberWithBases_impl<QByteArrayView>(); }
private:
void count_data();
@@ -1010,6 +1122,10 @@ void tst_QStringApiSymmetry::overload()
// check the common overload sets defined above to be free of ambiguities
// for arguments of type T
+ QT_WARNING_PUSH
+ // GCC complains about "t" and "ct"
+ QT_WARNING_DISABLE_GCC("-Wmaybe-uninitialized")
+
using CT = const T;
T t = {};
@@ -1058,6 +1174,7 @@ void tst_QStringApiSymmetry::overload()
overload_sr_v(CT());
}
}
+ QT_WARNING_POP
}
void tst_QStringApiSymmetry::overload_special()
@@ -1179,6 +1296,7 @@ MAKE(QString) { return sv.toString(); }
MAKE(QStringView) { return sv; }
MAKE(QLatin1String) { return l1; }
MAKE(QByteArray) { return u8; }
+MAKE(QByteArrayView) { return u8; }
MAKE(const char *) { return u8.data(); }
MAKE(const char16_t *) { return sv.utf16(); } // assumes `sv` doesn't represent a substring
MAKE(std::u16string) { return sv.toString().toStdU16String(); }
@@ -1193,6 +1311,7 @@ MAKE(QAnyStringViewUsingU16) { return {QAnyStringView{sv}}; }
template <typename> constexpr bool is_bytearray_like_v = false;
template <> constexpr bool is_bytearray_like_v<const char *> = true;
template <> constexpr bool is_bytearray_like_v<QByteArray> = true;
+template <> constexpr bool is_bytearray_like_v<QByteArrayView> = true;
template <typename LHS, typename RHS>
constexpr bool has_nothrow_member_compare_v = is_bytearray_like_v<LHS> == is_bytearray_like_v<RHS>;
@@ -1241,6 +1360,11 @@ void tst_QStringApiSymmetry::compare_impl() const
CHECK(<=);
CHECK(>=);
#undef CHECK
+ // Test that all string-like types implemente compareThreeWay() as a friend
+ // function.
+ const Qt::strong_ordering expectedOrdering =
+ Qt::compareThreeWay(caseSensitiveCompareResult, 0);
+ QCOMPARE_EQ(qCompareThreeWay(lhs, rhs), expectedOrdering);
}
template <typename LHS, typename RHS>
@@ -1320,8 +1444,9 @@ void tst_QStringApiSymmetry::localeAwareCompare_data()
return false;
};
#else
- // Otherwise, trust that setlocale() reconfigures QString::localeAwareCompare():
- const auto canTest = [](const char *) { return true; };
+ const auto canTest = [](const char *wanted) {
+ return QLocale(wanted) == QLocale::c() || QLocale(wanted) == QLocale::system().collation();
+ };
#endif
// Update tailpiece's max-value for this if you add a new locale group
int countGroups = 0;
@@ -2019,7 +2144,6 @@ void tst_QStringApiSymmetry::mid_data()
ROW(abc, 0, -1, abc, abc);
ROW(abc, 0, 5, abc, abc);
ROW(abc, -1, 1, abc, null);
- ROW(abc, -1, 2, abc, a);
ROW(abc, -1, 4, abc, abc);
ROW(abc, 1, -1, bc, bc);
ROW(abc, 1, 1, bc, b);
@@ -2275,6 +2399,27 @@ void tst_QStringApiSymmetry::sliced_impl()
}
}
+template <typename String>
+void tst_QStringApiSymmetry::slice_impl()
+{
+ QFETCH(const QStringView, unicode);
+ QFETCH(const QLatin1String, latin1);
+ QFETCH(const int, pos);
+ QFETCH(const int, n);
+ QFETCH(const QAnyStringView, result);
+ QFETCH(const QAnyStringView, result2);
+
+ const auto str = make<String>(unicode, latin1, unicode.toUtf8());
+
+ auto s = str;
+ s.slice(pos);
+ QCOMPARE_EQ(s, result);
+
+ s = str;
+ s.slice(pos, n);
+ QCOMPARE_EQ(s, result2);
+}
+
void tst_QStringApiSymmetry::first_data()
{
QTest::addColumn<QStringView>("unicode");
@@ -2467,18 +2612,20 @@ void tst_QStringApiSymmetry::trimmed_data()
QTest::addColumn<QString>("unicode");
QTest::addColumn<QAnyStringView>("result");
- const auto latin1Whitespace = QLatin1String(" \r\n\t\f\v");
+ const auto latin1Whitespace = QLatin1StringView(" \r\n\t\f\v");
QTest::addRow("null") << QString() << QAnyStringView();
auto add = [latin1Whitespace](const QString &str) {
- // run through all substrings of latin1Whitespace
- for (int len = 0; len < latin1Whitespace.size(); ++len) {
- for (int pos = 0; pos < latin1Whitespace.size() - len; ++pos) {
- const QString unicode = latin1Whitespace.mid(pos, len) + str + latin1Whitespace.mid(pos, len);
- const QScopedArrayPointer<const char> escaped(QTest::toString(unicode));
- QTest::addRow("%s", escaped.data()) << unicode << QAnyStringView(str);
- }
+ auto row = [&](QLatin1StringView spaces) {
+ const QString unicode = spaces + str + spaces;
+ const QScopedArrayPointer<const char> escaped(QTest::toString(unicode));
+ QTest::addRow("%s", escaped.data()) << unicode << QAnyStringView(str);
+ };
+ row({}); // The len = 0 case of the following.
+ for (qsizetype len = 1; len < latin1Whitespace.size(); ++len) {
+ for (qsizetype pos = 0; pos < latin1Whitespace.size() - len; ++pos)
+ row (latin1Whitespace.mid(pos, len));
}
};
@@ -2942,9 +3089,9 @@ void tst_QStringApiSymmetry::indexOf_data(bool rhsHasVariableLength)
<< minus1Pos << minus1Pos;
#define ROW(h, n, st, cs, cis) \
- QTest::addRow("haystack: %s, needle: %s", #h, #n) << h << QLatin1String(#h) \
- << n << QLatin1String(#n) \
- << qsizetype(st) << qsizetype(cs) << qsizetype(cis)
+ QTest::addRow("haystack: %s, needle: %s, start: %d", #h, #n, st) \
+ << h << QLatin1String(#h) << n << QLatin1String(#n) \
+ << qsizetype(st) << qsizetype(cs) << qsizetype(cis)
ROW(abc, a, 0, 0, 0);
ROW(abc, A, 0, -1, 0);
@@ -3033,7 +3180,7 @@ void tst_QStringApiSymmetry::contains_data(bool rhsHasVariableLength)
QTest::addRow("haystack: null, needle: empty") << null << QLatin1String()
<< empty << QLatin1String("") << true << true;
QTest::addRow("haystack: a, needle: empty") << a << QLatin1String("a")
- << empty << QLatin1String("") << true << true;;
+ << empty << QLatin1String("") << true << true;
QTest::addRow("haystack: empty, needle: empty") << empty << QLatin1String("")
<< empty << QLatin1String("") << true << true;
}
@@ -3113,14 +3260,18 @@ void tst_QStringApiSymmetry::lastIndexOf_data(bool rhsHasVariableLength)
<< a << QLatin1String("a") << minus1Pos << minus1Pos << minus1Pos;
if (rhsHasVariableLength) {
- QTest::addRow("haystack: a, needle: null") << a << QLatin1String("a")
- << null << QLatin1String() << qsizetype(1) << qsizetype(1) << qsizetype(1);
- QTest::addRow("haystack: a, needle: empty") << a << QLatin1String("a")
- << empty << QLatin1String("") << qsizetype(1) << qsizetype(1) << qsizetype(1);
- QTest::addRow("haystack: a, needle: null") << a << QLatin1String("a")
- << null << QLatin1String() << qsizetype(2) << minus1Pos << minus1Pos;
- QTest::addRow("haystack: a, needle: empty") << a << QLatin1String("a")
- << empty << QLatin1String("") << qsizetype(2) << minus1Pos << minus1Pos;
+ QTest::addRow("haystack: a, needle: null, start 1")
+ << a << QLatin1String("a")
+ << null << QLatin1String() << qsizetype(1) << qsizetype(1) << qsizetype(1);
+ QTest::addRow("haystack: a, needle: empty, start 1")
+ << a << QLatin1String("a")
+ << empty << QLatin1String("") << qsizetype(1) << qsizetype(1) << qsizetype(1);
+ QTest::addRow("haystack: a, needle: null, start 2")
+ << a << QLatin1String("a")
+ << null << QLatin1String() << qsizetype(2) << minus1Pos << minus1Pos;
+ QTest::addRow("haystack: a, needle: empty, start 2")
+ << a << QLatin1String("a")
+ << empty << QLatin1String("") << qsizetype(2) << minus1Pos << minus1Pos;
}
#define ROW(h, n, st, cs, cis) \
@@ -3442,6 +3593,8 @@ void tst_QStringApiSymmetry::isValidUtf8_data()
row = 0;
QTest::addRow("overlong-%02d", row++) << QByteArray("\xc0\x00") << false;
QTest::addRow("overlong-%02d", row++) << QByteArray("\xc1\xff") << false;
+ QTest::addRow("overlong-%02d", row++) << QByteArray("\xc1\xbf") << false;
+ QTest::addRow("overlong-%02d", row++) << QByteArray("\xc1\x01") << false;
QTest::addRow("overlong-%02d", row++) << QByteArray("\xe0\x00\x00") << false;
QTest::addRow("overlong-%02d", row++) << QByteArray("\xe0\xa0\x7f") << false;
QTest::addRow("overlong-%02d", row++) << QByteArray("\xf0\x00\x00\x00") << false;