summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2014-07-25 14:19:20 +0200
committerMarc Mutz <marc.mutz@kdab.com>2014-07-25 14:52:33 +0200
commit8b0cc9db9b5b09b00e573d1dc0dbfcca177c8a9d (patch)
tree795dde491bce33390a6278052fa5f874a40b67de /tests/auto
parentb99fa32d70e6511ae8bc1c6e806dbbb042dc8090 (diff)
tst_QHash: verify that {}-style initialization drops duplicates
No actual reason for this test, except my curiority. Then again, it's good to have this check, too. Also checks that the last entry in the init_list "wins", which is not how std:: containers work. Change-Id: Ia284d093cd0029432372630e81657fb687b9516f Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/tools/qhash/tst_qhash.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
index 9c96aaf78d..9c9e8ad635 100644
--- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp
+++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
@@ -1327,11 +1327,16 @@ void tst_QHash::twoArguments_qHash()
void tst_QHash::initializerList()
{
#ifdef Q_COMPILER_INITIALIZER_LISTS
- QHash<int, QString> hash{{1, "hello"}, {2, "initializer_list"}};
+ QHash<int, QString> hash = {{1, "bar"}, {1, "hello"}, {2, "initializer_list"}};
QCOMPARE(hash.count(), 2);
QVERIFY(hash[1] == "hello");
QVERIFY(hash[2] == "initializer_list");
+ // note the difference to std::unordered_map:
+ // std::unordered_map<int, QString> stdh = {{1, "bar"}, {1, "hello"}, {2, "initializer_list"}};
+ // QCOMPARE(stdh.size(), 2UL);
+ // QCOMPARE(stdh[1], QString("bar"));
+
QMultiHash<QString, int> multiHash{{"il", 1}, {"il", 2}, {"il", 3}};
QCOMPARE(multiHash.count(), 3);
QList<int> values = multiHash.values("il");