diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/declarative/qbindablemap/tst_qbindablemap.cpp | 77 | ||||
-rw-r--r-- | tests/auto/declarative/qmlecmascript/data/TypeForDynamicCreation.qml | 2 | ||||
-rw-r--r-- | tests/auto/declarative/qmlecmascript/data/dynamicCreation.qml | 5 | ||||
-rw-r--r-- | tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp | 29 | ||||
-rw-r--r-- | tests/auto/declarative/qmllanguage/data/scriptString.qml | 6 | ||||
-rw-r--r-- | tests/auto/declarative/qmllanguage/testtypes.cpp | 2 | ||||
-rw-r--r-- | tests/auto/declarative/qmllanguage/testtypes.h | 31 | ||||
-rw-r--r-- | tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp | 19 | ||||
-rw-r--r-- | tests/auto/declarative/qmlpropertymap/qmlpropertymap.pro (renamed from tests/auto/declarative/qbindablemap/qbindablemap.pro) | 2 | ||||
-rw-r--r-- | tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp | 110 |
10 files changed, 193 insertions, 90 deletions
diff --git a/tests/auto/declarative/qbindablemap/tst_qbindablemap.cpp b/tests/auto/declarative/qbindablemap/tst_qbindablemap.cpp deleted file mode 100644 index c1b31c2..0000000 --- a/tests/auto/declarative/qbindablemap/tst_qbindablemap.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include <qtest.h> -#include <QtDeclarative/qmlengine.h> -#include <QtDeclarative/qmlcontext.h> -#include <QtDeclarative/qbindablemap.h> -#include <QtDeclarative/qmlcomponent.h> -#include <QtDeclarative/qfxtext.h> -#include <QSignalSpy> - -class tst_QBindableMap : public QObject -{ - Q_OBJECT -public: - tst_QBindableMap() {} - -private slots: - void insert(); - void clear(); - void changed(); -}; - -void tst_QBindableMap::insert() -{ - QBindableMap 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_QBindableMap::clear() -{ - QBindableMap 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_QBindableMap::changed() -{ - QBindableMap 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_QBindableMap) - -#include "tst_qbindablemap.moc" diff --git a/tests/auto/declarative/qmlecmascript/data/TypeForDynamicCreation.qml b/tests/auto/declarative/qmlecmascript/data/TypeForDynamicCreation.qml new file mode 100644 index 0000000..56e0625 --- /dev/null +++ b/tests/auto/declarative/qmlecmascript/data/TypeForDynamicCreation.qml @@ -0,0 +1,2 @@ +import Qt.test 1.0 +MyQmlObject{objectName:"objectThree"} diff --git a/tests/auto/declarative/qmlecmascript/data/dynamicCreation.qml b/tests/auto/declarative/qmlecmascript/data/dynamicCreation.qml index ef39590..ed5e571 100644 --- a/tests/auto/declarative/qmlecmascript/data/dynamicCreation.qml +++ b/tests/auto/declarative/qmlecmascript/data/dynamicCreation.qml @@ -13,4 +13,9 @@ MyQmlObject{ var component = createComponent('dynamicCreation.helper.qml'); obj.objectProperty = component.createObject(); } + + function createThree() + { + obj.objectProperty = createQmlObject('TypeForDynamicCreation{}', obj); + } } diff --git a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp index f24882a..34b49e6 100644 --- a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp +++ b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp @@ -56,6 +56,7 @@ private slots: void signalParameterTypes(); void objectsCompareAsEqual(); void scriptAccess(); + void dynamicCreation_data(); void dynamicCreation(); void dynamicDestruction(); void objectToString(); @@ -639,27 +640,33 @@ void tst_qmlecmascript::scriptAccess() QCOMPARE(object->property("test3").toInt(), 0); } +void tst_qmlecmascript::dynamicCreation_data() +{ + QTest::addColumn<QString>("method"); + QTest::addColumn<QString>("createdName"); + + QTest::newRow("One") << "createOne" << "objectOne"; + QTest::newRow("Two") << "createTwo" << "objectTwo"; + QTest::newRow("Three") << "createThree" << "objectThree"; +} + /* Test using createQmlObject to dynamically generate an item Also using createComponent is tested. */ void tst_qmlecmascript::dynamicCreation() { + QFETCH(QString, method); + QFETCH(QString, createdName); + QmlComponent component(&engine, TEST_FILE("dynamicCreation.qml")); MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create()); QVERIFY(object != 0); - QObject *createdQmlObject = 0; - QObject *createdComponent = 0; - - QMetaObject::invokeMethod(object, "createOne"); - createdQmlObject = object->objectProperty(); - QVERIFY(createdQmlObject); - QCOMPARE(createdQmlObject->objectName(), QString("objectOne")); - QMetaObject::invokeMethod(object, "createTwo"); - createdComponent = object->objectProperty(); - QVERIFY(createdComponent); - QCOMPARE(createdComponent->objectName(), QString("objectTwo")); + QMetaObject::invokeMethod(object, method.toUtf8()); + QObject *created = object->objectProperty(); + QVERIFY(created); + QCOMPARE(created->objectName(), createdName); } /* diff --git a/tests/auto/declarative/qmllanguage/data/scriptString.qml b/tests/auto/declarative/qmllanguage/data/scriptString.qml new file mode 100644 index 0000000..51e6e48 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/scriptString.qml @@ -0,0 +1,6 @@ +import Test 1.0 + +MyTypeObject { + scriptProperty: foo + bar + grouped.script: print(1921) +} diff --git a/tests/auto/declarative/qmllanguage/testtypes.cpp b/tests/auto/declarative/qmllanguage/testtypes.cpp index c11e195..58d99f1 100644 --- a/tests/auto/declarative/qmllanguage/testtypes.cpp +++ b/tests/auto/declarative/qmllanguage/testtypes.cpp @@ -7,4 +7,4 @@ QML_DEFINE_TYPE(Test,1,0,0,MyContainer,MyContainer); QML_DEFINE_TYPE(Test,1,0,0,MyPropertyValueSource,MyPropertyValueSource); QML_DEFINE_TYPE(Test,1,0,0,MyDotPropertyObject,MyDotPropertyObject); QML_DEFINE_TYPE(Test,1,0,0,MyNamespacedType,MyNamespace::MyNamespacedType); - +QML_DEFINE_NOCREATE_TYPE(MyGroupedObject); diff --git a/tests/auto/declarative/qmllanguage/testtypes.h b/tests/auto/declarative/qmllanguage/testtypes.h index b1da9fb..355ff8b 100644 --- a/tests/auto/declarative/qmllanguage/testtypes.h +++ b/tests/auto/declarative/qmllanguage/testtypes.h @@ -10,6 +10,7 @@ #include <QtDeclarative/qmlcomponent.h> #include <QtDeclarative/qmlparserstatus.h> #include <QtDeclarative/qmlpropertyvaluesource.h> +#include <QtDeclarative/qmlscriptstring.h> class MyInterface { @@ -112,6 +113,21 @@ private: }; QML_DECLARE_TYPE(MyQmlObject); +class MyGroupedObject : public QObject +{ + Q_OBJECT + Q_PROPERTY(QmlScriptString script READ script WRITE setScript); +public: + QmlScriptString script() const { return m_script; } + void setScript(const QmlScriptString &s) { m_script = s; } + +private: + QmlScriptString m_script; +}; + +QML_DECLARE_TYPE(MyGroupedObject); + + class MyTypeObject : public QObject { Q_OBJECT @@ -142,6 +158,9 @@ class MyTypeObject : public QObject Q_PROPERTY(bool boolProperty READ boolProperty WRITE setBoolProperty); Q_PROPERTY(QVariant variantProperty READ variantProperty WRITE setVariantProperty); + Q_PROPERTY(QmlScriptString scriptProperty READ scriptProperty WRITE setScriptProperty); + Q_PROPERTY(MyGroupedObject *grouped READ grouped CONSTANT); + public: MyTypeObject() : objectPropertyValue(0), componentPropertyValue(0) {} @@ -334,6 +353,17 @@ public: variantPropertyValue = v; } + QmlScriptString scriptPropertyValue; + QmlScriptString scriptProperty() const { + return scriptPropertyValue; + } + void setScriptProperty(const QmlScriptString &v) { + scriptPropertyValue = v; + } + + MyGroupedObject groupedValue; + MyGroupedObject *grouped() { return &groupedValue; } + void doAction() { emit action(); } signals: void action(); @@ -365,6 +395,7 @@ private: QML_DECLARE_TYPE(MyContainer); + class MyPropertyValueSource : public QObject, public QmlPropertyValueSource { Q_OBJECT diff --git a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp index 8d4ae65..97038e6 100644 --- a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp +++ b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp @@ -63,6 +63,7 @@ private slots: void i18n(); void i18n_data(); void onCompleted(); + void scriptString(); void importsBuiltin_data(); void importsBuiltin(); @@ -739,6 +740,24 @@ void tst_qmllanguage::onCompleted() QVERIFY(object != 0); } +// Check that assignments to QmlScriptString properties work +void tst_qmllanguage::scriptString() +{ + QmlComponent component(&engine, TEST_FILE("scriptString.qml")); + VERIFY_ERRORS(0); + + MyTypeObject *object = qobject_cast<MyTypeObject*>(component.create()); + QVERIFY(object != 0); + QCOMPARE(object->scriptProperty().script(), QString("foo + bar")); + QCOMPARE(object->scriptProperty().scopeObject(), object); + QCOMPARE(object->scriptProperty().context(), qmlContext(object)); + + QVERIFY(object->grouped() != 0); + QCOMPARE(object->grouped()->script().script(), QString("print(1921)")); + QCOMPARE(object->grouped()->script().scopeObject(), object); + QCOMPARE(object->grouped()->script().context(), qmlContext(object)); +} + // Check that first child of qml is of given type. Empty type insists on error. void tst_qmllanguage::testType(const QString& qml, const QString& type) { diff --git a/tests/auto/declarative/qbindablemap/qbindablemap.pro b/tests/auto/declarative/qmlpropertymap/qmlpropertymap.pro index b042405..94f138f 100644 --- a/tests/auto/declarative/qbindablemap/qbindablemap.pro +++ b/tests/auto/declarative/qmlpropertymap/qmlpropertymap.pro @@ -1,3 +1,3 @@ load(qttest_p4) contains(QT_CONFIG,declarative): QT += declarative -SOURCES += tst_qbindablemap.cpp +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..7d3cc43 --- /dev/null +++ b/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp @@ -0,0 +1,110 @@ +#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 operatorInsert(); + void clear(); + void changed(); + void count(); +}; + +void tst_QmlPropertyMap::insert() +{ + QmlPropertyMap map; + 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.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.insert(QLatin1String("key1"),100); + QVERIFY(map.keys().count() == 1); + + QCOMPARE(map.value(QLatin1String("key1")), QVariant(100)); + + map.clear(QLatin1String("key1")); + QVERIFY(map.keys().count() == 1); + QCOMPARE(map.value(QLatin1String("key1")), QVariant()); +} + +void tst_QmlPropertyMap::changed() +{ + QmlPropertyMap map; + QSignalSpy spy(&map, SIGNAL(valueChanged(const QString&))); + map.insert(QLatin1String("key1"),100); + map.insert(QLatin1String("key2"),200); + QCOMPARE(spy.count(), 0); + + map.clear(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")); +} + +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" |