summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qhash/tst_qhash.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/tools/qhash/tst_qhash.cpp')
-rw-r--r--tests/auto/corelib/tools/qhash/tst_qhash.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
index 6ea33fb37f..6a5c6b5670 100644
--- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp
+++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
@@ -62,6 +62,7 @@ private slots:
void compare();
void compare2();
void iterators(); // sligthly modified from tst_QMap
+ void keyIterator();
void keys_values_uniqueKeys(); // slightly modified from tst_QMap
void noNeedlessRehashes();
@@ -965,6 +966,34 @@ void tst_QHash::iterators()
}
}
+void tst_QHash::keyIterator()
+{
+ QHash<int, int> hash;
+
+ for (int i = 0; i < 100; ++i)
+ hash.insert(i, i*100);
+
+ QHash<int, int>::key_iterator key_it = hash.keyBegin();
+ QHash<int, int>::const_iterator it = hash.cbegin();
+ for (int i = 0; i < 100; ++i) {
+ QCOMPARE(*key_it, it.key());
+ key_it++;
+ it++;
+ }
+
+ key_it = std::find(hash.keyBegin(), hash.keyEnd(), 50);
+ it = std::find(hash.cbegin(), hash.cend(), 50 * 100);
+
+ QVERIFY(key_it != hash.keyEnd());
+ QCOMPARE(*key_it, it.key());
+ QCOMPARE(*(key_it++), (it++).key());
+ QCOMPARE(*(key_it--), (it--).key());
+ QCOMPARE(*(++key_it), (++it).key());
+ QCOMPARE(*(--key_it), (--it).key());
+
+ QCOMPARE(std::count(hash.keyBegin(), hash.keyEnd(), 99), 1);
+}
+
void tst_QHash::rehash_isnt_quadratic()
{
// this test should be incredibly slow if rehash() is quadratic