summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2024-02-09 14:52:35 -0800
committerThiago Macieira <thiago.macieira@intel.com>2024-03-12 17:23:08 -0800
commit9a2e21174a08cf282cb933c95380abd900102ae0 (patch)
tree59085f9646f7d2d88ee39b6136ca83c6772cb927 /tests/auto/corelib/tools
parentb53c153a10261eb851385f4aa0afb663797fdeb9 (diff)
QHash: implement the heterogeneous non-const operator[]
This complements the previous commit by adding the heterogeneous lookup in operator[]. Unlike the members of the previous commit, this one may insert into the hash, in which case it needs a way to cast from the heterogeneous type K to the actual Key type. Change-Id: I664b9f014ffc48cbb49bfffd17b037c1063dfb91 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r--tests/auto/corelib/tools/qhash/tst_qhash.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
index e31c22ab99..6b7b5955df 100644
--- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp
+++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
@@ -1262,6 +1262,15 @@ static void heterogeneousSearchTest(const QList<std::remove_const_t<String>> &ke
std::make_pair(hash.constEnd(), hash.constEnd()));
Helper::checkCounter();
+ // non-const versions
+ QCOMPARE_EQ(hash[keyView], keys.size()); // already there
+ Helper::checkCounter();
+
+ QCOMPARE_EQ(hash[otherKeyView], 0); // inserts
+ Helper::resetCounter();
+ hash[otherKeyView] = INT_MAX;
+ Helper::checkCounter();
+
if constexpr (IsMultiHash) {
hash.insert(key, keys.size());
QCOMPARE_EQ(hash.count(keyView), 2);
@@ -1303,7 +1312,7 @@ static void heterogeneousSearchTest(const QList<std::remove_const_t<String>> &ke
QCOMPARE_EQ(hash.remove(keyView), true);
}
- QCOMPARE_EQ(hash.take(otherKeyView), 0);
+ QCOMPARE_EQ(hash.take(otherKeyView), INT_MAX);
QVERIFY(hash.isEmpty());
Helper::checkCounter();