From facb6f9477fe2f4a9b133819e7f1a2ea0b59a4e3 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 25 Mar 2024 18:46:04 -0700 Subject: QCborMap: add missing comparator to QCborValueConstRef And ensure all combination of CBOR types are tested. Amends e5ebb9022ab9e00ab01d0bce527755da77083217 Change-Id: I5f663c2f9f4149af84fefffd17c02d352cd41f3f Reviewed-by: Tatiana Borisova --- src/corelib/serialization/qcbormap.cpp | 2 +- src/corelib/serialization/qcbormap.h | 13 +++++++++++++ .../corelib/serialization/qcborvalue/tst_qcborvalue.cpp | 12 ++++++++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/corelib/serialization/qcbormap.cpp b/src/corelib/serialization/qcbormap.cpp index 9367a2ab9b..00c0bb0b6d 100644 --- a/src/corelib/serialization/qcbormap.cpp +++ b/src/corelib/serialization/qcbormap.cpp @@ -19,7 +19,7 @@ using namespace QtCbor; \brief The QCborMap class is used to hold an associative container representable in CBOR. \compares strong - \compareswith strong QCborValue + \compareswith strong QCborValue QCborValueConstRef \endcompareswith This class can be used to hold an associative container in CBOR, a map diff --git a/src/corelib/serialization/qcbormap.h b/src/corelib/serialization/qcbormap.h index 55935e113e..087334fdff 100644 --- a/src/corelib/serialization/qcbormap.h +++ b/src/corelib/serialization/qcbormap.h @@ -326,6 +326,19 @@ private: } Q_DECLARE_STRONGLY_ORDERED(QCborMap, QCborValue) + friend bool comparesEqual(const QCborMap &lhs, const QCborValueConstRef &rhs) noexcept + { + return lhs.compare(rhs.toMap()) == 0; + } + + friend Qt::strong_ordering compareThreeWay(const QCborMap &lhs, + const QCborValueConstRef &rhs) noexcept + { + int c = lhs.compare(rhs.toMap()); + return Qt::compareThreeWay(c, 0); + } + Q_DECLARE_STRONGLY_ORDERED(QCborMap, QCborValueConstRef) + explicit QCborMap(QCborContainerPrivate &dd) noexcept; QExplicitlySharedDataPointer d; }; diff --git a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp index e3544a4056..37f1569bbc 100644 --- a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp +++ b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp @@ -452,17 +452,25 @@ void tst_QCborValue::extendedTypes_data() void tst_QCborValue::compareCompiles() { + // homogeneous types QTestPrivate::testAllComparisonOperatorsCompile(); QTestPrivate::testAllComparisonOperatorsCompile(); QTestPrivate::testAllComparisonOperatorsCompile(); QTestPrivate::testAllComparisonOperatorsCompile(); QTestPrivate::testAllComparisonOperatorsCompile(); + + // QCborValue, Ref and ConstRef QTestPrivate::testAllComparisonOperatorsCompile(); QTestPrivate::testAllComparisonOperatorsCompile(); QTestPrivate::testAllComparisonOperatorsCompile(); - QTestPrivate::testAllComparisonOperatorsCompile(); - QTestPrivate::testAllComparisonOperatorsCompile(); + + // QCbor{Array,Map} <=> QCborValue{,Ref,ConstRef} + QTestPrivate::testAllComparisonOperatorsCompile(); + QTestPrivate::testAllComparisonOperatorsCompile(); + QTestPrivate::testAllComparisonOperatorsCompile(); QTestPrivate::testAllComparisonOperatorsCompile(); + QTestPrivate::testAllComparisonOperatorsCompile(); + QTestPrivate::testAllComparisonOperatorsCompile(); } void tst_QCborValue::extendedTypes() -- cgit v1.2.3