From 8b0cc9db9b5b09b00e573d1dc0dbfcca177c8a9d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 25 Jul 2014 14:19:20 +0200 Subject: 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 --- tests/auto/corelib/tools/qhash/tst_qhash.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tests/auto') 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 hash{{1, "hello"}, {2, "initializer_list"}}; + QHash 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 stdh = {{1, "bar"}, {1, "hello"}, {2, "initializer_list"}}; + // QCOMPARE(stdh.size(), 2UL); + // QCOMPARE(stdh[1], QString("bar")); + QMultiHash multiHash{{"il", 1}, {"il", 2}, {"il", 3}}; QCOMPARE(multiHash.count(), 3); QList values = multiHash.values("il"); -- cgit v1.2.3