From 1f92ff3ee08259d56209191cff24983b5969d50c Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Mon, 12 Feb 2024 18:46:51 +0100 Subject: [PATCH] Add QByteArray vs QByteArrayView relational operators ... by using the new comparison helper macors. This allows to enable related tests in tst_qstringapisymmetry. Task-number: QTBUG-108805 Change-Id: I2cef8f4a25889b74a921fea47995d59c3a49d368 Reviewed-by: Thiago Macieira --- src/corelib/text/qbytearray.h | 11 +++++++++++ .../qstringapisymmetry/tst_qstringapisymmetry.cpp | 4 ---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h index f057fa0bb78..a6733834384 100644 --- a/src/corelib/text/qbytearray.h +++ b/src/corelib/text/qbytearray.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -539,6 +540,16 @@ public: explicit inline QByteArray(DataPointer &&dd) : d(std::move(dd)) {} private: + friend bool comparesEqual(const QByteArray &lhs, const QByteArrayView &rhs) noexcept + { return QByteArrayView(lhs) == rhs; } + friend Qt::strong_ordering + compareThreeWay(const QByteArray &lhs, const QByteArrayView &rhs) noexcept + { + const int res = QtPrivate::compareMemory(QByteArrayView(lhs), rhs); + return Qt::compareThreeWay(res, 0); + } + Q_DECLARE_STRONGLY_ORDERED(QByteArray, QByteArrayView) + void reallocData(qsizetype alloc, QArrayData::AllocationOption option); void reallocGrowData(qsizetype n); void expand(qsizetype i); diff --git a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp index 8cf04c40ea6..635b9cfa52f 100644 --- a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp +++ b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp @@ -297,10 +297,8 @@ private Q_SLOTS: void compare_QByteArray_QLatin1String() { compare_impl(); } void compare_QByteArray_QByteArray_data() { compare_data(); } void compare_QByteArray_QByteArray() { compare_impl(); } -#ifdef AMBIGUOUS_CALL void compare_QByteArray_QByteArrayView_data() { compare_data(); } void compare_QByteArray_QByteArrayView() { compare_impl(); } -#endif void compare_QByteArray_const_char_star_data() { compare_data(); } void compare_QByteArray_const_char_star() { compare_impl(); } @@ -318,10 +316,8 @@ private Q_SLOTS: void compare_QByteArrayView_QUtf8StringView() { compare_impl(); } void compare_QByteArrayView_QLatin1String_data() { compare_data(); } void compare_QByteArrayView_QLatin1String() { compare_impl(); } -#ifdef AMBIGUOUS_CALL void compare_QByteArrayView_QByteArray_data() { compare_data(); } void compare_QByteArrayView_QByteArray() { compare_impl(); } -#endif void compare_QByteArrayView_QByteArrayView_data() { compare_data(); } void compare_QByteArrayView_QByteArrayView() { compare_impl(); } #ifdef AMBIGUOUS_CALL