diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-10-21 00:57:02 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-10-21 01:43:24 (GMT) |
commit | 2c70994c3b9b0839ef5d489e6dfcaaf6c4ed6b4d (patch) | |
tree | d00f145d9c4cd72bfcb6038aa86a22c9efb83a73 /tests/auto/declarative/qmlpropertymap | |
parent | b8c939903b8afc0abe38ab2e315a5bda32221aae (diff) | |
download | Qt-2c70994c3b9b0839ef5d489e6dfcaaf6c4ed6b4d.zip Qt-2c70994c3b9b0839ef5d489e6dfcaaf6c4ed6b4d.tar.gz Qt-2c70994c3b9b0839ef5d489e6dfcaaf6c4ed6b4d.tar.bz2 |
Rename QBindableMap to QmlPropertyMap.
Task-number: QT-2316
Diffstat (limited to 'tests/auto/declarative/qmlpropertymap')
-rw-r--r-- | tests/auto/declarative/qmlpropertymap/qmlpropertymap.pro | 3 | ||||
-rw-r--r-- | tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp | 77 |
2 files changed, 80 insertions, 0 deletions
diff --git a/tests/auto/declarative/qmlpropertymap/qmlpropertymap.pro b/tests/auto/declarative/qmlpropertymap/qmlpropertymap.pro new file mode 100644 index 0000000..94f138f --- /dev/null +++ b/tests/auto/declarative/qmlpropertymap/qmlpropertymap.pro @@ -0,0 +1,3 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative +SOURCES += tst_qmlpropertymap.cpp diff --git a/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp b/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp new file mode 100644 index 0000000..a923234 --- /dev/null +++ b/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp @@ -0,0 +1,77 @@ +#include <qtest.h> +#include <QtDeclarative/qmlengine.h> +#include <QtDeclarative/qmlcontext.h> +#include <QtDeclarative/qmlpropertymap.h> +#include <QtDeclarative/qmlcomponent.h> +#include <QtDeclarative/qfxtext.h> +#include <QSignalSpy> + +class tst_QmlPropertyMap : public QObject +{ + Q_OBJECT +public: + tst_QmlPropertyMap() {} + +private slots: + void insert(); + void clear(); + void changed(); +}; + +void tst_QmlPropertyMap::insert() +{ + QmlPropertyMap map; + map.setValue(QLatin1String("key1"),100); + map.setValue(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"); + QCOMPARE(map.value(QLatin1String("key1")), QVariant("Hello World")); +} + +void tst_QmlPropertyMap::clear() +{ + QmlPropertyMap map; + map.setValue(QLatin1String("key1"),100); + QVERIFY(map.keys().count() == 1); + + QCOMPARE(map.value(QLatin1String("key1")), QVariant(100)); + + map.clearValue(QLatin1String("key1")); + QVERIFY(map.keys().count() == 1); + QCOMPARE(map.value(QLatin1String("key1")), QVariant()); +} + +void tst_QmlPropertyMap::changed() +{ + QmlPropertyMap map; + QSignalSpy spy(&map, SIGNAL(changed(const QString&))); + map.setValue(QLatin1String("key1"),100); + map.setValue(QLatin1String("key2"),200); + QCOMPARE(spy.count(), 0); + + map.clearValue(QLatin1String("key1")); + QCOMPARE(spy.count(), 0); + + //make changes in QML + QmlEngine engine; + QmlContext *ctxt = engine.rootContext(); + ctxt->setContextProperty(QLatin1String("testdata"), &map); + QmlComponent component(&engine, "import Qt 4.6\nText { text: { testdata.key1 = 'Hello World'; 'X' } }", + QUrl("file://")); + QVERIFY(component.isReady()); + QFxText *txt = qobject_cast<QFxText*>(component.create()); + QVERIFY(txt); + QCOMPARE(txt->text(), QString('X')); + QCOMPARE(spy.count(), 1); + QList<QVariant> arguments = spy.takeFirst(); + QCOMPARE(arguments.at(0).toString(),QLatin1String("key1")); + QCOMPARE(map.value(QLatin1String("key1")), QVariant("Hello World")); +} + +QTEST_MAIN(tst_QmlPropertyMap) + +#include "tst_qmlpropertymap.moc" |