diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-01-13 12:39:44 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-01-13 14:32:40 +0100 |
commit | f1410debc7905e704b6ed16ae345e43765ef8ef5 (patch) | |
tree | 56c0acf733fff7bc08362b753bd7729421169709 /tests | |
parent | cfe0b08b5439a27b4fdd14c29620e0492543f506 (diff) |
Add a freeze() method to QQmlPropertyMap
After freezing a QQmlPropertyMap you cannot add any more properties, but
in turn the property access is cached, and therefore faster.
Task-number: QTBUG-57792
Change-Id: I2c6d768039c3b59eb2411194e463ee0de55f8bed
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp index 82930b3f4a..75ef397bba 100644 --- a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp +++ b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp @@ -63,6 +63,7 @@ private slots: void QTBUG_35906(); void QTBUG_48136(); void lookupsInSubTypes(); + void freeze(); }; class LazyPropertyMap : public QQmlPropertyMap, public QQmlParserStatus @@ -574,6 +575,26 @@ void tst_QQmlPropertyMap::lookupsInSubTypes() QCOMPARE(object->property("newProperty").toInt(), 42); } +void tst_QQmlPropertyMap::freeze() +{ + QQmlPropertyMap map; + + map.insert(QLatin1String("key1"),100); + map.insert(QLatin1String("key2"),200); + QCOMPARE(map.keys().count(), 2); + QVERIFY(map.contains(QLatin1String("key1"))); + QCOMPARE(map.value(QLatin1String("key1")), QVariant(100)); + QCOMPARE(map.value(QLatin1String("key2")), QVariant(200)); + + map.freeze(); + map.insert(QLatin1String("key3"), 32); + QCOMPARE(map.keys().count(), 2); + QVERIFY(!map.contains("key3")); + + map.insert(QLatin1String("key1"), QStringLiteral("Hello World")); + QCOMPARE(map.value("key1").toString(), QStringLiteral("Hello World")); +} + QTEST_MAIN(tst_QQmlPropertyMap) #include "tst_qqmlpropertymap.moc" |