summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2024-03-25 18:46:04 -0700
committerThiago Macieira <thiago.macieira@intel.com>2024-03-26 16:14:55 -0700
commitfacb6f9477fe2f4a9b133819e7f1a2ea0b59a4e3 (patch)
treed0466e0c0e1135d9e16af2583a1cd843d5b01044
parenta30912b90667368b74b006432e7de51c583da30e (diff)
QCborMap: add missing comparator to QCborValueConstRef
And ensure all combination of CBOR types are tested. Amends e5ebb9022ab9e00ab01d0bce527755da77083217 Change-Id: I5f663c2f9f4149af84fefffd17c02d352cd41f3f Reviewed-by: Tatiana Borisova <tatiana.borisova@qt.io>
-rw-r--r--src/corelib/serialization/qcbormap.cpp2
-rw-r--r--src/corelib/serialization/qcbormap.h13
-rw-r--r--tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp12
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<QCborContainerPrivate> 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<QCborValue>();
QTestPrivate::testAllComparisonOperatorsCompile<QCborValueRef>();
QTestPrivate::testAllComparisonOperatorsCompile<QCborValueConstRef>();
QTestPrivate::testAllComparisonOperatorsCompile<QCborArray>();
QTestPrivate::testAllComparisonOperatorsCompile<QCborMap>();
+
+ // QCborValue, Ref and ConstRef
QTestPrivate::testAllComparisonOperatorsCompile<QCborValueRef, QCborValueConstRef>();
QTestPrivate::testAllComparisonOperatorsCompile<QCborValueConstRef, QCborValue>();
QTestPrivate::testAllComparisonOperatorsCompile<QCborValueRef, QCborValue>();
- QTestPrivate::testAllComparisonOperatorsCompile<QCborValueConstRef, QCborArray>();
- QTestPrivate::testAllComparisonOperatorsCompile<QCborValueRef, QCborArray>();
+
+ // QCbor{Array,Map} <=> QCborValue{,Ref,ConstRef}
+ QTestPrivate::testAllComparisonOperatorsCompile<QCborArray, QCborValue>();
+ QTestPrivate::testAllComparisonOperatorsCompile<QCborArray, QCborValueRef>();
+ QTestPrivate::testAllComparisonOperatorsCompile<QCborArray, QCborValueConstRef>();
QTestPrivate::testAllComparisonOperatorsCompile<QCborMap, QCborValue>();
+ QTestPrivate::testAllComparisonOperatorsCompile<QCborMap, QCborValueRef>();
+ QTestPrivate::testAllComparisonOperatorsCompile<QCborMap, QCborValueConstRef>();
}
void tst_QCborValue::extendedTypes()