summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/serialization/qcborvalue
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2021-11-11 15:45:46 -0800
committerThiago Macieira <thiago.macieira@intel.com>2022-02-15 17:00:03 -0800
commit3531f578d3b55fb151ae99112acdfd20228855fa (patch)
tree7f9775efefa6d991dabee5adfcc51689e57b6df7 /tests/auto/corelib/serialization/qcborvalue
parent800f60657d28ad96e0021b4dcd812e3a3be4dcb1 (diff)
QCborArray: allow large but in-range keys
The 0x10000 limit should not apply if the key is a valid index in the array. Change-Id: I5e52dc5b093c43a3b678fffd16b6a2a5a69acd61 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests/auto/corelib/serialization/qcborvalue')
-rw-r--r--tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp
index fcbe739a39..16884987f4 100644
--- a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp
+++ b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp
@@ -74,6 +74,7 @@ private slots:
void arrayPrepend();
void arrayValueRef_data() { basics_data(); }
void arrayValueRef();
+ void arrayValueRefLargeKey();
void arrayInsertRemove_data() { basics_data(); }
void arrayInsertRemove();
void arrayInsertTagged_data() { basics_data(); }
@@ -1320,6 +1321,30 @@ void tst_QCborValue::arrayValueRef()
iteratorCheck(a.constBegin());
}
+void tst_QCborValue::arrayValueRefLargeKey()
+{
+ // make sure the access via QCborValue & QCborValueRef don't convert this
+ // array to a map
+ constexpr qsizetype LargeKey = 0x10000;
+ QCborArray a;
+ a[LargeKey + 1] = 123;
+
+ QCborValue v(a);
+ QCOMPARE(qAsConst(v)[LargeKey], QCborValue());
+ QCOMPARE(qAsConst(v)[LargeKey + 1], 123);
+ QCOMPARE(v[LargeKey], QCborValue());
+ QCOMPARE(v[LargeKey + 1], 123);
+ QCOMPARE(v.type(), QCborValue::Array);
+
+ QCborArray outer = { QCborValue(a) };
+ QCborValueRef ref = outer[0];
+ QCOMPARE(qAsConst(ref)[LargeKey], QCborValue());
+ QCOMPARE(qAsConst(ref)[LargeKey + 1], 123);
+ QCOMPARE(ref[LargeKey], QCborValue());
+ QCOMPARE(ref[LargeKey + 1], 123);
+ QCOMPARE(ref.type(), QCborValue::Array);
+}
+
void tst_QCborValue::mapValueRef()
{
QFETCH(QCborValue, v);