From 2c0bdd38cbba17d3a7ebb51f2a693371f21db24c Mon Sep 17 00:00:00 2001 From: Ievgenii Meshcheriakov Date: Tue, 7 Sep 2021 11:27:21 +0200 Subject: 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 Reviewed-by: Thiago Macieira --- .../text/qstringapisymmetry/tst_qstringapisymmetry.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'tests/auto') 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 struct is_utf8_encoded : std::false_type {}; -template <> struct is_utf8_encoded : std::true_type {}; -template <> struct is_utf8_encoded : std::true_type {}; -template <> struct is_utf8_encoded : std::true_type {}; - -template struct is_latin1_encoded : std::false_type {}; -template <> struct is_latin1_encoded : std::true_type {}; +// Some types have ASCII-only case-insensitive compare, but are handled as containing +// UTF-8 when implicitly converted to QString. +template constexpr bool is_bytearray_like_v = false; +template <> constexpr bool is_bytearray_like_v = true; +template <> constexpr bool is_bytearray_like_v = true; template -constexpr bool has_nothrow_member_compare_v = is_utf8_encoded::value == is_utf8_encoded::value; +constexpr bool has_nothrow_member_compare_v = is_bytearray_like_v == is_bytearray_like_v; template 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::value && is_utf8_encoded::value && + if (is_bytearray_like_v && is_bytearray_like_v && 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); } -- cgit v1.2.3