diff options
Diffstat (limited to 'tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp')
-rw-r--r-- | tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp index 39af59d0b0..82930b3f4a 100644 --- a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp +++ b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp @@ -45,6 +45,7 @@ private slots: void initTestCase(); void insert(); + void insertMany(); void operatorInsert(); void operatorValue(); void clear(); @@ -153,6 +154,63 @@ void tst_QQmlPropertyMap::insert() QCOMPARE(map.value(QLatin1String("valueCHANGED")), QVariant(1)); } +void tst_QQmlPropertyMap::insertMany() +{ + QHash<QString, QVariant> values; + values.insert(QLatin1String("key2"), 200); + values.insert(QLatin1String("key1"), "Hello World"); + values.insert(QLatin1String("valueChange"), 1); + values.insert(QLatin1String("valueCHANGED"), 1); + + QQmlPropertyMap map; + map.insert(values); + QCOMPARE(map.keys().count(), 4); + QVERIFY(map.contains(QLatin1String("key1"))); + QCOMPARE(map.value(QLatin1String("key2")), QVariant(200)); + QCOMPARE(map.value(QLatin1String("key1")), QVariant("Hello World")); + //but 'valueChange' should be ok + QVERIFY(map.contains(QLatin1String("valueChange"))); + QCOMPARE(map.value(QLatin1String("valueChange")), QVariant(1)); + //'valueCHANGED' should be ok, too + QVERIFY(map.contains(QLatin1String("valueCHANGED"))); + QCOMPARE(map.value(QLatin1String("valueCHANGED")), QVariant(1)); + + values.insert(QLatin1String("keys"), 1); + values.insert(QStringLiteral("foobar"), 12); + values[QStringLiteral("key1")] = 100; + //inserting property names same with existing method(signal, slot, method) names is not allowed + //QQmlPropertyMap has an invokable keys() method + QTest::ignoreMessage(QtWarningMsg, "Creating property with name \"keys\" is not permitted, conflicts with internal symbols."); + map.insert(values); + QCOMPARE(map.keys().count(), 4); + QVERIFY(!map.contains(QLatin1String("keys"))); + QVERIFY(map.value(QLatin1String("keys")).isNull()); + + values.remove(QStringLiteral("keys")); + values.insert(QLatin1String("deleteLater"), 1); + //QQmlPropertyMap has a deleteLater() slot + QTest::ignoreMessage(QtWarningMsg, "Creating property with name \"deleteLater\" is not permitted, conflicts with internal symbols."); + map.insert(values); + QCOMPARE(map.keys().count(), 4); + QVERIFY(!map.contains(QLatin1String("deleteLater"))); + QVERIFY(map.value(QLatin1String("deleteLater")).isNull()); + + values.remove(QStringLiteral("deleteLater")); + values.insert(QLatin1String("valueChanged"), 1); + //QQmlPropertyMap has an valueChanged() signal + QTest::ignoreMessage(QtWarningMsg, "Creating property with name \"valueChanged\" is not permitted, conflicts with internal symbols."); + map.insert(values); + QCOMPARE(map.keys().count(), 4); + QVERIFY(!map.contains(QLatin1String("valueChanged"))); + QVERIFY(map.value(QLatin1String("valueChanged")).isNull()); + + values.remove(QStringLiteral("valueChanged")); + map.insert(values); // Adds "foobar" and changes "key1" + QCOMPARE(map.keys().count(), 5); + QCOMPARE(map.value(QStringLiteral("foobar")).toInt(), 12); + QCOMPARE(map.value(QStringLiteral("key1")).toInt(), 100); +} + void tst_QQmlPropertyMap::operatorInsert() { QQmlPropertyMap map; @@ -216,7 +274,7 @@ void tst_QQmlPropertyMap::changed() component.setData("import QtQuick 2.0\nText { text: { testdata.key1 = 'Hello World'; 'X' } }", QUrl::fromLocalFile("")); QVERIFY(component.isReady()); - QQuickText *txt = qobject_cast<QQuickText*>(component.create()); + QScopedPointer<QQuickText> txt(qobject_cast<QQuickText*>(component.create())); QVERIFY(txt); QCOMPARE(txt->text(), QString('X')); QCOMPARE(spy.count(), 1); |