diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-10-21 04:57:07 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-10-21 04:57:50 (GMT) |
commit | 1208d2800d4810a472262d8e04f0cf3a59a3efdb (patch) | |
tree | 8f599585e1d77872fae50e4c3d1bc1da0a395070 /tests/auto | |
parent | 2b7c33da538e1fd596c679a089c1949cc8651103 (diff) | |
download | Qt-1208d2800d4810a472262d8e04f0cf3a59a3efdb.zip Qt-1208d2800d4810a472262d8e04f0cf3a59a3efdb.tar.gz Qt-1208d2800d4810a472262d8e04f0cf3a59a3efdb.tar.bz2 |
Give QmlPropertyMap a more complete API.
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp | 51 |
1 files changed, 42 insertions, 9 deletions
diff --git a/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp b/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp index a923234..7d3cc43 100644 --- a/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp +++ b/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp @@ -14,33 +14,49 @@ public: private slots: void insert(); + void operatorInsert(); void clear(); void changed(); + void count(); }; void tst_QmlPropertyMap::insert() { QmlPropertyMap map; - map.setValue(QLatin1String("key1"),100); - map.setValue(QLatin1String("key2"),200); + map.insert(QLatin1String("key1"),100); + map.insert(QLatin1String("key2"),200); QVERIFY(map.keys().count() == 2); QCOMPARE(map.value(QLatin1String("key1")), QVariant(100)); QCOMPARE(map.value(QLatin1String("key2")), QVariant(200)); - map.setValue(QLatin1String("key1"),"Hello World"); + map.insert(QLatin1String("key1"),"Hello World"); + QCOMPARE(map.value(QLatin1String("key1")), QVariant("Hello World")); +} + +void tst_QmlPropertyMap::operatorInsert() +{ + QmlPropertyMap map; + map[QLatin1String("key1")] = 100; + map[QLatin1String("key2")] = 200; + QVERIFY(map.keys().count() == 2); + + QCOMPARE(map.value(QLatin1String("key1")), QVariant(100)); + QCOMPARE(map.value(QLatin1String("key2")), QVariant(200)); + + map[QLatin1String("key1")] = "Hello World"; QCOMPARE(map.value(QLatin1String("key1")), QVariant("Hello World")); } void tst_QmlPropertyMap::clear() { QmlPropertyMap map; - map.setValue(QLatin1String("key1"),100); + map.insert(QLatin1String("key1"),100); QVERIFY(map.keys().count() == 1); QCOMPARE(map.value(QLatin1String("key1")), QVariant(100)); - map.clearValue(QLatin1String("key1")); + map.clear(QLatin1String("key1")); QVERIFY(map.keys().count() == 1); QCOMPARE(map.value(QLatin1String("key1")), QVariant()); } @@ -48,12 +64,12 @@ void tst_QmlPropertyMap::clear() void tst_QmlPropertyMap::changed() { QmlPropertyMap map; - QSignalSpy spy(&map, SIGNAL(changed(const QString&))); - map.setValue(QLatin1String("key1"),100); - map.setValue(QLatin1String("key2"),200); + QSignalSpy spy(&map, SIGNAL(valueChanged(const QString&))); + map.insert(QLatin1String("key1"),100); + map.insert(QLatin1String("key2"),200); QCOMPARE(spy.count(), 0); - map.clearValue(QLatin1String("key1")); + map.clear(QLatin1String("key1")); QCOMPARE(spy.count(), 0); //make changes in QML @@ -72,6 +88,23 @@ void tst_QmlPropertyMap::changed() QCOMPARE(map.value(QLatin1String("key1")), QVariant("Hello World")); } +void tst_QmlPropertyMap::count() +{ + QmlPropertyMap map; + QCOMPARE(map.isEmpty(), true); + map.insert(QLatin1String("key1"),100); + map.insert(QLatin1String("key2"),200); + QCOMPARE(map.count(), 2); + QCOMPARE(map.isEmpty(), false); + + map.insert(QLatin1String("key3"),"Hello World"); + QCOMPARE(map.count(), 3); + + //clearing doesn't remove the key + map.clear(QLatin1String("key3")); + QCOMPARE(map.count(), 3); +} + QTEST_MAIN(tst_QmlPropertyMap) #include "tst_qmlpropertymap.moc" |