summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2021-07-07 14:51:36 +0200
committerIvan Solovev <ivan.solovev@qt.io>2021-07-08 14:41:14 +0200
commit82499f81478032911d8f788aa28e8d780b31c973 (patch)
tree5de5dedfb0d594078ec103a6b0daa82161765533 /tests/auto/corelib/tools
parent0ac8722d25503a74fe8aed3e6129bc5fd5de9447 (diff)
QMultiHash::find - prevent detaching shared null
Do not detach when find(key, value) is called on an empty QMultiHash. As a drive-by: fix return value for QMultiHash::remove() in case of empty QMultiHash. Task-number: QTBUG-91736 Pick-to: 6.2 6.1 Change-Id: I1e32f359e7ee9ce8403dae79d02e0b88a20ec4a5 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r--tests/auto/corelib/tools/qhash/tst_qhash.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
index 6ad7d15c77..375f9048c0 100644
--- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp
+++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
@@ -668,12 +668,17 @@ void tst_QHash::empty()
//copied from tst_QMap
void tst_QHash::find()
{
+ const QHash<int, QString> constEmptyHash;
+ QVERIFY(constEmptyHash.find(1) == constEmptyHash.end());
+ QVERIFY(!constEmptyHash.isDetached());
+
QHash<int, QString> map1;
QString testString="Teststring %0";
QString compareString;
int i,count=0;
QVERIFY(map1.find(1) == map1.end());
+ QVERIFY(!map1.isDetached());
map1.insert(1,"Mensch");
map1.insert(1,"Mayer");
@@ -682,6 +687,16 @@ void tst_QHash::find()
QCOMPARE(map1.find(1).value(), QLatin1String("Mayer"));
QCOMPARE(map1.find(2).value(), QLatin1String("Hej"));
+ const QMultiHash<int, QString> constEmptyMultiHash;
+ QVERIFY(constEmptyMultiHash.find(1) == constEmptyMultiHash.cend());
+ QVERIFY(constEmptyMultiHash.find(1, "value") == constEmptyMultiHash.cend());
+ QVERIFY(!constEmptyMultiHash.isDetached());
+
+ QMultiHash<int, QString> emptyMultiHash;
+ QVERIFY(emptyMultiHash.find(1) == emptyMultiHash.end());
+ QVERIFY(emptyMultiHash.find(1, "value") == emptyMultiHash.end());
+ QVERIFY(!emptyMultiHash.isDetached());
+
QMultiHash<int, QString> multiMap(map1);
for (i = 3; i < 10; ++i) {
compareString = testString.arg(i);