diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2024-03-05 12:28:26 +0100 |
---|---|---|
committer | Ivan Solovev <ivan.solovev@qt.io> | 2024-03-18 17:42:18 +0100 |
commit | aab82ff367c35503ae54b8a5a4121858efbac5ee (patch) | |
tree | 19409d067f848057b7f64f6101b4007bbed5f6b2 /tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp | |
parent | fff6562f8c074d75bda8b80f844dc63c6f2e64d5 (diff) |
tst_qstringapisymmetry: add qCompareThreeWay() checks
Check that all string-like types implement compareThreeWay() as a
(hidden) friend function.
This test revealed some problems: because QByteArrayView is implicitly
constructible from QLatin1StringView, the qCompareThreeWay() call
sometimes picked the compareThreeWay() overloads with QByteArrayView
instead of picking the "reversed" overloads that use QLatin1StringView.
This was leading to wrong results, because QByteArrayView is
interpreted as utf-8 data, not latin-1.
Explicitly add the missing compareThreeWay() and comparesEqual()
overloads.
Note that relational operators were never affected by this problem,
because in C++17 mode we explicitly generate the reversed versions,
and in C++20 mode the compiler does that for us.
Task-number: QTBUG-117661
Change-Id: Ia96af59c60ebf2fae6cf2a49231d6b6f401aceaa
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp')
-rw-r--r-- | tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp index e1a262b61a..35a734cf02 100644 --- a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp +++ b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp @@ -1360,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> |