QQmlPropertyMap: Verify that inserting duplicate keys behaves

Even if those keys are empty, they do not result in duplicate entries.
Empty keys are allowed, even if that doesn't make sense in practice.

Fixes: QTBUG-109029
Change-Id: I8c6bc6599318c99c1afd0a9edd7b29cd32759f06
Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
This commit is contained in:
Volker Hilsheimer 2022-12-02 17:24:22 +01:00
parent b12c7ca751
commit a8efd5dda8
1 changed files with 29 additions and 0 deletions

View File

@ -23,6 +23,7 @@ private slots:
void insert();
void insertMany();
void insertDuplicate();
void operatorInsert();
void operatorValue();
void clear();
@ -191,6 +192,34 @@ void tst_QQmlPropertyMap::insertMany()
QCOMPARE(map.value(QStringLiteral("key1")).toInt(), 100);
}
void tst_QQmlPropertyMap::insertDuplicate()
{
QHash<QString, QVariant> values;
values.insert(QLatin1String("key2"), 200);
values.insert(QLatin1String("key1"), "Hello World");
auto expectedCount = values.count();
QQmlPropertyMap map;
map.insert(values);
QCOMPARE(map.keys().size(), expectedCount);
map.insert(QStringLiteral("key2"), 24);
QCOMPARE(map.keys().size(), expectedCount);
QCOMPARE(map.value(QStringLiteral("key2")).toInt(), 24);
map.insert(QString(), QVariant("Empty1"));
QCOMPARE(map.keys().size(), ++expectedCount);
map.insert(QString(), QVariant("Empty2"));
QCOMPARE(map.keys().size(), expectedCount);
QHash<QString, QVariant> emptyKeyMap;
emptyKeyMap.insert(QString(), 200);
emptyKeyMap.insert(QString(), 400);
map.insert(emptyKeyMap);
QCOMPARE(map.keys().size(), expectedCount);
}
void tst_QQmlPropertyMap::operatorInsert()
{
QQmlPropertyMap map;