summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/serialization/qcborvalue
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2021-11-09 14:45:09 -0800
committerThiago Macieira <thiago.macieira@intel.com>2022-02-15 17:00:03 -0800
commit04dc959d49e5e3742db759c131a0a78f21821653 (patch)
treec78573cbef0c41ad6cc579c5f31597060916081b /tests/auto/corelib/serialization/qcborvalue
parent9b8f064cd36e014ecb3e6b60e2190b74f69aee5a (diff)
Introduce Q{Json,Cbor}ValueConstRef
I screwed up when I wrote QCborValueRef by not having the ConstRef type. The code worked, but it wasn't const-correct, allowing you to write: const QCborArray &arr = something(); *arr.begin() = QCborArray(); This mistake was brought over to QJsonValue in Qt 6.0, so it has to be fixed for QJsonValue too. The actual fixes are in the next couple of commits. This change is believed to be binary-compatible: the Q{Json,Cbor}ValueRef classes continue to have the exact same size, except that they're now empty and have a new base class. They weren't trivial before this commit doesn't change that. [ChangeLog][Potentially Source-Incompatible Changes] The iterator classes for Qt's JSON and CBOR containers (array and map/object) had a const correctness issue which allowed a const_iterator to mutate the container being iterated on, even if that container was itself const. Qt 6.4 has a fix for this, but will cause compilation issues where QCborValueRef and QJsonValueRef were used where the correctness could be violated. To keep code compiling with both 6.3 and 6.4, either change to non-const iteration or replace the QxxxValueRef with a const QxxxValue reference. This change is binary-compatible. Change-Id: I5e52dc5b093c43a3b678fffd16b6063333765ae0 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'tests/auto/corelib/serialization/qcborvalue')
-rw-r--r--tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp
index 4fd4255b7d..fcbe739a39 100644
--- a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp
+++ b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp
@@ -135,6 +135,8 @@ private slots:
void cborValueRef_data();
void cborValueRef();
+ void cborValueConstRef_data() { cborValueRef_data(); }
+ void cborValueConstRef();
void cborValueRefMutatingArray_data() { cborValueRef_data(); }
void cborValueRefMutatingArray();
void cborValueRefMutatingMapIntKey_data() { cborValueRef_data(); }
@@ -2637,7 +2639,7 @@ void tst_QCborValue::cborValueRef_data()
QTest::newRow("Tagged") << QCborValue::Tag << QCborValue(QCborKnownTags::Base64, QByteArray());
}
-void tst_QCborValue::cborValueRef()
+template <typename ValueRef> static void cborValueRef_template()
{
const QCborArray otherArray = {2};
const QCborMap otherMap = { { 2, 21 } };
@@ -2648,7 +2650,7 @@ void tst_QCborValue::cborValueRef()
QFETCH(QCborValue, v);
QCborArray a = { v };
- const QCborValueRef ref = a[0];
+ const ValueRef ref = a[0];
QCOMPARE(ref, v);
QVERIFY(ref.compare(v) == 0);
@@ -2717,6 +2719,16 @@ void tst_QCborValue::cborValueRef()
QCOMPARE(ref.toDiagnosticNotation(), v.toDiagnosticNotation());
}
+void tst_QCborValue::cborValueRef()
+{
+ cborValueRef_template<QCborValueRef>();
+}
+
+void tst_QCborValue::cborValueConstRef()
+{
+ cborValueRef_template<QCborValueConstRef>();
+}
+
void tst_QCborValue::cborValueRefMutatingArray()
{
// complements arrayMutation()