summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/serialization/qcborvalue
diff options
context:
space:
mode:
authorTatiana Borisova <tatiana.borisova@qt.io>2024-03-06 15:25:13 +0100
committerTatiana Borisova <tatiana.borisova@qt.io>2024-03-19 00:48:23 +0100
commit2b2cd119e134699f5428f0eb5686fa9eaef67a57 (patch)
tree594fa41c0978842331a3d2f1848c631a9724d504 /tests/auto/corelib/serialization/qcborvalue
parent5401a9a6cd3263eda15911c3fbfc81ebea2e798f (diff)
QCborValueConstRef/QCborValueRef: use new comparison helper macros
Replace public operators operator==() and operator!=() of QCborValueConstRef and QCborValueRef classes to friend methods comparesEqual(). Replace public operator<() of QCborValueConstRef and QCborValueRef classes to friend methods compareThreeWay() respectively. Use QT_CORE_REMOVED_SINCE to get rid of current comparison methods and replace them with a friend. Delete #if 0 && __has_include(<compare>) blocks, since they are not required anymore. Add comparison() test-case for QCborValueConstRef/QCborValueRef testing. Add QCborValue::operator==()/QCborValue::operator!=()/ QCborValue::operator<() and QCborValueRef::operator==()/ QCborValueRef::operator!=()/QCborValueRef::operator<() operators to the removed_api file. Task-number: QTBUG-120300 Change-Id: I2e8e4e32b7b5b49da321364cc12986e9c64b5f37 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/serialization/qcborvalue')
-rw-r--r--tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp84
1 files changed, 77 insertions, 7 deletions
diff --git a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp
index 7a49f01538..960d37e9de 100644
--- a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp
+++ b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp
@@ -27,7 +27,7 @@ private slots:
void tagged();
void extendedTypes_data();
void extendedTypes();
- void compareCompiles() { QTestPrivate::testAllComparisonOperatorsCompile<QCborValue>(); }
+ void compareCompiles();
void copyCompare_data() { basics_data(); }
void copyCompare();
@@ -79,6 +79,8 @@ private slots:
void mapNested();
void sorting();
+ void comparison_data();
+ void comparison();
void toCbor_data();
void toCbor();
@@ -446,6 +448,16 @@ void tst_QCborValue::extendedTypes_data()
<< QCborValue(uuid.toRfc4122() + "\1\2\3\4") << QCborValue(uuid.toRfc4122());
}
+void tst_QCborValue::compareCompiles()
+{
+ QTestPrivate::testAllComparisonOperatorsCompile<QCborValue>();
+ QTestPrivate::testAllComparisonOperatorsCompile<QCborValueRef, QCborValueConstRef>();
+ QTestPrivate::testAllComparisonOperatorsCompile<QCborValueConstRef, QCborValue>();
+ QTestPrivate::testAllComparisonOperatorsCompile<QCborValueRef, QCborValue>();
+ QTestPrivate::testAllComparisonOperatorsCompile<QCborValueRef>();
+ QTestPrivate::testAllComparisonOperatorsCompile<QCborValueConstRef>();
+}
+
void tst_QCborValue::extendedTypes()
{
QFETCH(QCborValue, extended);
@@ -1110,8 +1122,7 @@ void tst_QCborValue::mapMutation()
QVERIFY(v.isTrue());
QCOMPARE(m, QCborMap({{42, true}}));
QVERIFY(m.begin()->isTrue());
- QVERIFY(m.begin().value() == v);
- QVERIFY(v == m.begin().value());
+ QT_TEST_EQUALITY_OPS(m.begin().value(), v, true);
}
QVERIFY(m == QCborMap({{42, true}}));
@@ -1135,10 +1146,10 @@ void tst_QCborValue::mapMutation()
auto end = m.end();
QCOMPARE(end - it, 2);
QCOMPARE(it + 2, end);
- QCOMPARE(it.key(), QCborValue(42));
- QCOMPARE(it.value(), QCborValue(2.5));
- QCOMPARE((++it).value(), QCborValue(nullptr));
- QCOMPARE(it.key(), QCborValue(nullptr));
+ QT_TEST_EQUALITY_OPS(it.key(), QCborValue(42), true);
+ QT_TEST_EQUALITY_OPS(it.value(), QCborValue(2.5), true);
+ QT_TEST_EQUALITY_OPS((++it).value(), QCborValue(nullptr), true);
+ QT_TEST_EQUALITY_OPS(it.key(), QCborValue(nullptr), true);
QVERIFY(m2 == m);
QVERIFY(m == m2);
@@ -1191,11 +1202,13 @@ void tst_QCborValue::mapMutateWithCopies()
// see QTBUG-83366
QCborMap map;
map[QLatin1String("value")] = "TEST";
+ QT_TEST_EQUALITY_OPS(map[QLatin1String("value")], "TEST", true);
QCOMPARE(map.size(), 1);
QCOMPARE(map.value("value"), "TEST");
QCborValue v = map.value("value");
map[QLatin1String("prop2")] = v;
+ QT_TEST_EQUALITY_OPS(map[QLatin1String("prop2")], v, true);
QCOMPARE(map.size(), 2);
QCOMPARE(map.value("value"), "TEST");
QCOMPARE(map.value("prop2"), "TEST");
@@ -1209,6 +1222,7 @@ void tst_QCborValue::mapMutateWithCopies()
// same as previous, but this is a QJsonValueRef
QCborValueRef rv = map[QLatin1String("prop2")];
rv = map[QLatin1String("value")];
+ QT_TEST_EQUALITY_OPS(map[QLatin1String("value")], rv, true);
QCOMPARE(map.size(), 2);
QCOMPARE(map.value("value"), "TEST");
QCOMPARE(map.value("prop2"), "TEST");
@@ -1223,6 +1237,7 @@ void tst_QCborValue::mapMutateWithCopies()
// after we create the source QCborValueRef
QCborValueRef rv = map[QLatin1String("value")];
map[QLatin1String("prop2")] = rv;
+ QT_TEST_EQUALITY_OPS(map[QLatin1String("prop2")], rv, true);
QCOMPARE(map.size(), 2);
QCOMPARE(map.value("value"), "TEST");
QCOMPARE(map.value("prop2"), "TEST");
@@ -3068,6 +3083,61 @@ void tst_QCborValue::testlibFormatting()
QCOMPARE(actual, expected);
}
+void tst_QCborValue::comparison_data()
+{
+ QTest::addColumn<QCborValue>("lhs");
+ QTest::addColumn<QCborValue>("rhs");
+ QTest::addColumn<Qt::strong_ordering>("expectedOrdering");
+
+ auto addRow = [](QCborValue lhs, QCborValue rhs, Qt::strong_ordering order) {
+ QTest::addRow("%s-cmp-%s", qPrintable(lhs.toDiagnosticNotation()),
+ qPrintable(rhs.toDiagnosticNotation()))
+ << lhs << rhs << order;
+ };
+ // typical, sorts as expected
+ addRow(0, 0, Qt::strong_ordering::equivalent);
+ addRow(1, 0, Qt::strong_ordering::greater);
+ addRow(0, 1, Qt::strong_ordering::less);
+ addRow(10.0, 10.0, Qt::strong_ordering::equivalent);
+ addRow(10.5, 10.8, Qt::strong_ordering::less);
+ addRow(-10.5, -10.8, Qt::strong_ordering::less);
+ addRow("Qt","Qt", Qt::strong_ordering::equivalent);
+ addRow("qt","Qt", Qt::strong_ordering::greater);
+
+ // atypical gotchas
+ addRow(0, -1, Qt::strong_ordering::less);
+ addRow(10, 10.0, Qt::strong_ordering::less);
+ addRow(0, "Qt", Qt::strong_ordering::less);
+
+}
+
+void tst_QCborValue::comparison()
+{
+ QFETCH(QCborValue, lhs);
+ QFETCH(QCborValue, rhs);
+ QFETCH(Qt::strong_ordering, expectedOrdering);
+
+ QCborArray array{lhs, rhs};
+
+ QCborValueConstRef lhsCRef = array.constBegin()[0];
+ QCborValueConstRef rhsCRef = array.constBegin()[1];
+ QCborValueRef lhsRef = array[0];
+ QCborValueRef rhsRef = array[1];
+
+ // QCborValue vs QCborValue
+ QT_TEST_ALL_COMPARISON_OPS(lhs, rhs, expectedOrdering);
+ // QCborValueConstRef vs QCborValueConstRef
+ QT_TEST_ALL_COMPARISON_OPS(lhsCRef, rhsCRef, expectedOrdering);
+ // QCborValueRef vs QCborValueRef
+ QT_TEST_ALL_COMPARISON_OPS(lhsRef, rhsRef, expectedOrdering);
+ // QCborValue vs QCborValueConstRef (and reverse)
+ QT_TEST_ALL_COMPARISON_OPS(lhs, rhsCRef, expectedOrdering);
+ // QCborValue vs QCborValueRef (and reverse)
+ QT_TEST_ALL_COMPARISON_OPS(lhs, rhsRef, expectedOrdering);
+ // QCborValueConstRef vs QCborValueRef (and reverse)
+ QT_TEST_ALL_COMPARISON_OPS(lhsCRef, rhsRef, expectedOrdering);
+}
+
QTEST_MAIN(tst_QCborValue)
#include "tst_qcborvalue.moc"