summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qhash/tst_qhash.cpp
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-12-09 01:00:35 +0100
committerLars Knoll <lars.knoll@qt.io>2019-12-09 10:16:01 +0100
commitbef74b6c3a0a9c8649ea8eb333d80015f76863e4 (patch)
tree41cdf5b6776c90a6d04a1d6680f4d47a90593746 /tests/auto/corelib/tools/qhash/tst_qhash.cpp
parentf8d2975b6a8b36bf8dd304c99783947a72081b79 (diff)
parent4c3c63d4cbb81b38e88e06b72749e7e01497b6f1 (diff)
Merge remote-tracking branch 'origin/5.15' into dev
Diffstat (limited to 'tests/auto/corelib/tools/qhash/tst_qhash.cpp')
-rw-r--r--tests/auto/corelib/tools/qhash/tst_qhash.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
index f0eeb70ccb..91cd3eb0bd 100644
--- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp
+++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
@@ -69,6 +69,7 @@ private slots:
void initializerList();
void eraseValidIteratorOnSharedHash();
void equal_range();
+ void insert_hash();
};
struct IdentityTracker {
@@ -1636,5 +1637,77 @@ void tst_QHash::equal_range()
}
}
+void tst_QHash::insert_hash()
+{
+ {
+ QHash<int, int> hash;
+ hash.insert(1, 1);
+ hash.insert(2, 2);
+ hash.insert(0, -1);
+
+ QHash<int, int> hash2;
+ hash2.insert(0, 0);
+ hash2.insert(3, 3);
+ hash2.insert(4, 4);
+
+ hash.insert(hash2);
+
+ QCOMPARE(hash.count(), 5);
+ for (int i = 0; i < 5; ++i)
+ QCOMPARE(hash[i], i);
+ }
+ {
+ QHash<int, int> hash;
+ hash.insert(0, 5);
+
+ QHash<int, int> hash2;
+
+ hash.insert(hash2);
+
+ QCOMPARE(hash.count(), 1);
+ QCOMPARE(hash[0], 5);
+ }
+ {
+ QHash<int, int> hash;
+ QHash<int, int> hash2;
+ hash2.insert(0, 5);
+
+ hash.insert(hash2);
+
+ QCOMPARE(hash.count(), 1);
+ QCOMPARE(hash[0], 5);
+ QCOMPARE(hash, hash2);
+ }
+ {
+ QHash<int, int> hash;
+ hash.insert(0, 7);
+ hash.insert(2, 5);
+ hash.insert(7, 55);
+
+ // insert into ourself, nothing should happen
+ hash.insert(hash);
+
+ QCOMPARE(hash.count(), 3);
+ QCOMPARE(hash[0], 7);
+ QCOMPARE(hash[2], 5);
+ QCOMPARE(hash[7], 55);
+ }
+ {
+ // This will use a QMultiHash and then insert that into QHash,
+ // the ordering is undefined so we won't test that but make
+ // sure this isn't adding multiple entries with the same key
+ // to the QHash.
+ QHash<int, int> hash;
+ QMultiHash<int, int> hash2;
+ hash2.insert(0, 5);
+ hash2.insert(0, 6);
+ hash2.insert(0, 7);
+
+ hash.insert(hash2);
+
+ QCOMPARE(hash.count(), 1);
+ }
+}
+
QTEST_APPLESS_MAIN(tst_QHash)
#include "tst_qhash.moc"