diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2024-02-12 18:46:51 +0100 |
---|---|---|
committer | Ivan Solovev <ivan.solovev@qt.io> | 2024-02-20 01:04:33 +0100 |
commit | 1f92ff3ee08259d56209191cff24983b5969d50c (patch) | |
tree | 760d68e6e16d106ef4a05b4804cdf56ea3a5dc58 | |
parent | 9b945b381a78b56b14d46ec314f0f69264ac0602 (diff) |
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 <thiago.macieira@intel.com>
-rw-r--r-- | src/corelib/text/qbytearray.h | 11 | ||||
-rw-r--r-- | tests/auto/corelib/text/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 f057fa0bb7..a673383438 100644 --- a/src/corelib/text/qbytearray.h +++ b/src/corelib/text/qbytearray.h @@ -9,6 +9,7 @@ #include <QtCore/qnamespace.h> #include <QtCore/qarraydata.h> #include <QtCore/qarraydatapointer.h> +#include <QtCore/qcompare.h> #include <QtCore/qcontainerfwd.h> #include <QtCore/qbytearrayalgorithms.h> #include <QtCore/qbytearrayview.h> @@ -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 8cf04c40ea..635b9cfa52 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<QByteArray, QLatin1String>(); } void compare_QByteArray_QByteArray_data() { compare_data(); } void compare_QByteArray_QByteArray() { compare_impl<QByteArray, QByteArray>(); } -#ifdef AMBIGUOUS_CALL void compare_QByteArray_QByteArrayView_data() { compare_data(); } void compare_QByteArray_QByteArrayView() { compare_impl<QByteArray, QByteArrayView>(); } -#endif void compare_QByteArray_const_char_star_data() { compare_data(); } void compare_QByteArray_const_char_star() { compare_impl<QByteArray, const char *>(); } @@ -318,10 +316,8 @@ private Q_SLOTS: void compare_QByteArrayView_QUtf8StringView() { compare_impl<QByteArrayView, QUtf8StringView>(); } void compare_QByteArrayView_QLatin1String_data() { compare_data(); } void compare_QByteArrayView_QLatin1String() { compare_impl<QByteArrayView, QLatin1String>(); } -#ifdef AMBIGUOUS_CALL void compare_QByteArrayView_QByteArray_data() { compare_data(); } void compare_QByteArrayView_QByteArray() { compare_impl<QByteArrayView, QByteArray>(); } -#endif void compare_QByteArrayView_QByteArrayView_data() { compare_data(); } void compare_QByteArrayView_QByteArrayView() { compare_impl<QByteArrayView, QByteArrayView>(); } #ifdef AMBIGUOUS_CALL |