summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorIevgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>2021-09-07 11:27:21 +0200
committerIevgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>2021-09-09 15:02:02 +0200
commit2c0bdd38cbba17d3a7ebb51f2a693371f21db24c (patch)
tree4e60895a407dd1d50ff18df08b51de2b5735de3c /tests/auto
parent8a66e3cfe56e3ec3e1567ecef77ddb6eba9e7238 (diff)
tst_qstringapisymmetry: Don't pretend that QByteArray contains UTF-8
The name of is_utf8_encoded type seems to imply that QByteArray and const char * contain UTF-8 encoded data. This is not always the case. When used with QByteArray API, those types are handled as containing ASCII-only. It's only when used with APIs of other classes (QString, QLatin1String) they are handled as UTF-8. This renames the check to is_bytearray_like_v and clarifies its usage. No need to handle QUtf8StringView this way because it works just fine with the current testcases. While at it, also remove unused is_latin1_encoded trait. Task-number: QTBUG-92021 Change-Id: I44e40cf3c0dd07e5b3cf1e47ff7a04f1c548aa97 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp18
1 files changed, 8 insertions, 10 deletions
diff --git a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp
index 31b1e130e5..2fdb3ad0b5 100644
--- a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp
+++ b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp
@@ -1041,16 +1041,14 @@ MAKE(QAnyStringViewUsingU8) { return {QAnyStringView{u8}}; }
MAKE(QAnyStringViewUsingU16) { return {QAnyStringView{sv}}; }
#undef MAKE
-template <typename> struct is_utf8_encoded : std::false_type {};
-template <> struct is_utf8_encoded<const char*> : std::true_type {};
-template <> struct is_utf8_encoded<QByteArray> : std::true_type {};
-template <> struct is_utf8_encoded<QUtf8StringView> : std::true_type {};
-
-template <typename> struct is_latin1_encoded : std::false_type {};
-template <> struct is_latin1_encoded<QLatin1String> : std::true_type {};
+// Some types have ASCII-only case-insensitive compare, but are handled as containing
+// UTF-8 when implicitly converted to QString.
+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 <typename LHS, typename RHS>
-constexpr bool has_nothrow_member_compare_v = is_utf8_encoded<LHS>::value == is_utf8_encoded<RHS>::value;
+constexpr bool has_nothrow_member_compare_v = is_bytearray_like_v<LHS> == is_bytearray_like_v<RHS>;
template <typename LHS, typename RHS>
void tst_QStringApiSymmetry::compare_impl() const
@@ -1119,11 +1117,11 @@ void tst_QStringApiSymmetry::member_compare_impl() const
QCOMPARE(sign(lhs.compare(rhs)), caseSensitiveCompareResult);
QCOMPARE(sign(lhs.compare(rhs, Qt::CaseSensitive)), caseSensitiveCompareResult);
- if (is_utf8_encoded<LHS>::value && is_utf8_encoded<RHS>::value &&
+ if (is_bytearray_like_v<LHS> && is_bytearray_like_v<RHS> &&
caseSensitiveCompareResult != caseInsensitiveCompareResult &&
(!QtPrivate::isAscii(lhsUnicode) || !QtPrivate::isAscii(rhsUnicode)))
{
- QEXPECT_FAIL("", "Qt is missing a case-insensitive UTF-8/UTF-8 comparator", Continue);
+ QEXPECT_FAIL("", "The types don't support non-ASCII case-insensitive comparison", Continue);
}
QCOMPARE(sign(lhs.compare(rhs, Qt::CaseInsensitive)), caseInsensitiveCompareResult);
}