tst_QMap: 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: I4f7d1228f2b90a904b6c3f99e54afcd9970b723e
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
Marc Mutz 2014-07-25 14:32:37 +02:00
parent 443bc6ab18
commit 34237d62f6

View File

@ -1179,11 +1179,16 @@ void tst_QMap::checkMostLeftNode()
void tst_QMap::initializerList()
{
#ifdef Q_COMPILER_INITIALIZER_LISTS
QMap<int, QString> map{{1, "hello"}, {2, "initializer_list"}};
QMap<int, QString> map = {{1, "bar"}, {1, "hello"}, {2, "initializer_list"}};
QCOMPARE(map.count(), 2);
QVERIFY(map[1] == "hello");
QVERIFY(map[2] == "initializer_list");
// note the difference to std::map:
// std::map<int, QString> stdm = {{1, "bar"}, {1, "hello"}, {2, "initializer_list"}};
// QCOMPARE(stdm.size(), 2UL);
// QCOMPARE(stdm[1], QString("bar"));
QMultiMap<QString, int> multiMap{{"il", 1}, {"il", 2}, {"il", 3}};
QCOMPARE(multiMap.count(), 3);
QList<int> values = multiMap.values("il");