summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/serialization
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2018-05-19 14:58:43 -0700
committerThiago Macieira <thiago.macieira@intel.com>2018-07-04 03:04:21 +0000
commit2bb44414ff456873c885391e4a03afb67e7306da (patch)
tree9d6f7d1b2912cd494073c10e23fd61543535a022 /tests/auto/corelib/serialization
parentfcb0f68e77bb69544f0ae310baffd3ceff8a9e5d (diff)
QCborArray & Map: implement efficient take() / extract()
Questions: 1) should QCborMap::extract return value_type (a pair) instead of just the value? 2) should the both return the iterator to the next element too, like erase()? Change-Id: I052407b777ec43f78378fffd15302a9c14468db3 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/serialization')
-rw-r--r--tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp
index 0cd4c5cca0..7f0007b384 100644
--- a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp
+++ b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp
@@ -781,6 +781,7 @@ void tst_QCborValue::arrayPrepend()
a.prepend(nullptr);
QCOMPARE(a.at(1), QCborValue(0));
QCOMPARE(a.at(0), QCborValue(nullptr));
+ QCOMPARE(a.size(), 2);
}
void tst_QCborValue::arrayInsertRemove()
@@ -808,6 +809,11 @@ void tst_QCborValue::arrayInsertRemove()
it = a.erase(it);
QVERIFY(a.isEmpty());
QCOMPARE(it, a.end());
+
+ // reinsert the element so we can take it
+ a.append(v);
+ QCOMPARE(a.takeAt(0), v);
+ QVERIFY(a.isEmpty());
}
void tst_QCborValue::arrayStringElements()
@@ -836,6 +842,10 @@ void tst_QCborValue::arrayStringElements()
v2 = a.at(1);
QCOMPARE(v2.toString(), "World");
QCOMPARE(v2, QCborValue("World"));
+
+ QCOMPARE(a.takeAt(1).toString(), "World");
+ QCOMPARE(a.takeAt(0).toString(), "Hello");
+ QVERIFY(a.isEmpty());
}
void tst_QCborValue::mapStringValues()
@@ -862,6 +872,10 @@ void tst_QCborValue::mapStringValues()
v2 = (m.begin() + 1).value();
QCOMPARE(v2.toString(), "World");
QCOMPARE(v2, QCborValue("World"));
+
+ QCOMPARE(m.extract(m.begin() + 1).toString(), "World");
+ QCOMPARE(m.take(0).toString(), "Hello");
+ QVERIFY(m.isEmpty());
}
void tst_QCborValue::mapStringKeys()
@@ -914,6 +928,14 @@ void tst_QCborValue::mapInsertRemove()
QVERIFY(v == it.value());
QVERIFY(it.value() == r);
QVERIFY(r == it.value());
+
+ QCOMPARE(m.extract(it), v);
+ QVERIFY(!m.contains(42));
+
+ m[2] = v;
+ QCOMPARE(m.take(2), v);
+ QVERIFY(m.take(2).isUndefined());
+ QVERIFY(m.isEmpty());
}
void tst_QCborValue::arrayInsertTagged()
@@ -930,6 +952,9 @@ void tst_QCborValue::arrayInsertTagged()
QCOMPARE(a.at(1), tagged);
QCOMPARE(a.at(0).taggedValue(), v);
QCOMPARE(a.at(1).taggedValue(), v);
+ QCOMPARE(a.takeAt(0).taggedValue(), v);
+ QCOMPARE(a.takeAt(0).taggedValue(), v);
+ QVERIFY(a.isEmpty());
}
void tst_QCborValue::mapInsertTagged()
@@ -946,6 +971,10 @@ void tst_QCborValue::mapInsertTagged()
QCOMPARE(m.value(-21), tagged);
QCOMPARE(m.value(11).taggedValue(), v);
QCOMPARE((m.end() - 1).value().taggedValue(), v);
+ QCOMPARE(m.extract(m.end() - 1).taggedValue(), v);
+ QVERIFY(!m.contains(-21));
+ QCOMPARE(m.take(11).taggedValue(), v);
+ QVERIFY(m.isEmpty());
}
void tst_QCborValue::arraySelfAssign()
@@ -1109,6 +1138,8 @@ void tst_QCborValue::mapComplexKeys()
QVERIFY(m.contains(tagged));
r = 47;
QCOMPARE(m[tagged].toInteger(), 47);
+ QCOMPARE(m.take(tagged).toInteger(), 47);
+ QVERIFY(!m.contains(tagged));
}
void tst_QCborValue::sorting()