diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2009-10-07 08:26:35 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2009-10-07 08:26:35 (GMT) |
commit | fdec8807127844c55fcc0bb43ad0ab7db1d81a07 (patch) | |
tree | f1643e784ab2561bc8e74d3b6ab9ad60d9e59019 /tests | |
parent | 8a54ed9524befc4a172cdc19a18d9953f3a01df0 (diff) | |
parent | 68573410fb50d95a6ce27cd001d2e140b0b4aedd (diff) | |
download | Qt-fdec8807127844c55fcc0bb43ad0ab7db1d81a07.zip Qt-fdec8807127844c55fcc0bb43ad0ab7db1d81a07.tar.gz Qt-fdec8807127844c55fcc0bb43ad0ab7db1d81a07.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Conflicts:
doc/src/declarative/tutorial1.qdoc
doc/src/declarative/tutorial2.qdoc
doc/src/declarative/tutorial3.qdoc
Diffstat (limited to 'tests')
5 files changed, 119 insertions, 0 deletions
diff --git a/tests/auto/declarative/qmlecmascript/data/dynamicCreation.helper.qml b/tests/auto/declarative/qmlecmascript/data/dynamicCreation.helper.qml new file mode 100644 index 0000000..b26d6e1 --- /dev/null +++ b/tests/auto/declarative/qmlecmascript/data/dynamicCreation.helper.qml @@ -0,0 +1,5 @@ +import Qt.test 1.0 + +MyQmlObject{ + objectName: "objectTwo" +} diff --git a/tests/auto/declarative/qmlecmascript/data/dynamicCreation.qml b/tests/auto/declarative/qmlecmascript/data/dynamicCreation.qml new file mode 100644 index 0000000..ef39590 --- /dev/null +++ b/tests/auto/declarative/qmlecmascript/data/dynamicCreation.qml @@ -0,0 +1,16 @@ +import Qt.test 1.0 + +MyQmlObject{ + id: obj + objectName: "obj" + function createOne() + { + obj.objectProperty = createQmlObject('import Qt.test 1.0; MyQmlObject{objectName:"objectOne"}', obj); + } + + function createTwo() + { + var component = createComponent('dynamicCreation.helper.qml'); + obj.objectProperty = component.createObject(); + } +} diff --git a/tests/auto/declarative/qmlecmascript/data/dynamicDeletion.qml b/tests/auto/declarative/qmlecmascript/data/dynamicDeletion.qml new file mode 100644 index 0000000..ba87b32 --- /dev/null +++ b/tests/auto/declarative/qmlecmascript/data/dynamicDeletion.qml @@ -0,0 +1,20 @@ +import Qt.test 1.0 + +MyQmlObject{ + id: obj + objectName: "obj" + function create() + { + obj.objectProperty = createQmlObject('import Qt.test 1.0; MyQmlObject{objectName:"emptyObject"}', obj); + } + + function killOther() + { + obj.objectProperty.destroy(100); + } + + function killMe() + { + obj.destroy();//Must not segfault + } +} diff --git a/tests/auto/declarative/qmlecmascript/data/qmlToString.qml b/tests/auto/declarative/qmlecmascript/data/qmlToString.qml new file mode 100644 index 0000000..ac296ce --- /dev/null +++ b/tests/auto/declarative/qmlecmascript/data/qmlToString.qml @@ -0,0 +1,11 @@ +import Qt.test 1.0 + +MyQmlObject{ + id: obj + objectName: "objName" + function testToString() + { + obj.stringProperty = obj.toString(); + } + +} diff --git a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp index d5d20b6..3f01192 100644 --- a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp +++ b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp @@ -5,6 +5,7 @@ #include <QtDeclarative/qmlcontext.h> #include <QtCore/qfileinfo.h> #include <QtCore/qdebug.h> +#include <QtCore/private/qguard_p.h> #include <QtCore/qdir.h> #include "testtypes.h" @@ -50,6 +51,9 @@ private slots: void outerBindingOverridesInnerBinding(); void aliasPropertyAndBinding(); void nonExistantAttachedObject(); + void dynamicCreation(); + void dynamicDestruction(); + void objectToString(); private: QmlEngine engine; @@ -531,6 +535,69 @@ void tst_qmlecmascript::aliasPropertyAndBinding() QCOMPARE(object->property("c3").toInt(), 19); } +/* + Test using createQmlObject to dynamically generate an item + Also using createComponent is tested. +*/ +void tst_qmlecmascript::dynamicCreation() +{ + 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")); +} + +/* + Tests the destroy function +*/ +void tst_qmlecmascript::dynamicDestruction() +{ + QmlComponent component(&engine, TEST_FILE("dynamicDeletion.qml")); + QGuard<MyQmlObject> object = qobject_cast<MyQmlObject*>(component.create()); + QVERIFY(object != 0); + QGuard<QObject> createdQmlObject = 0; + + QMetaObject::invokeMethod(object, "create"); + createdQmlObject = object->objectProperty(); + QVERIFY(createdQmlObject); + QCOMPARE(createdQmlObject->objectName(), QString("emptyObject")); + + QMetaObject::invokeMethod(object, "killOther"); + QVERIFY(createdQmlObject); + QTest::qWait(0); + QVERIFY(createdQmlObject); + QTest::qWait(100); + QVERIFY(!createdQmlObject); + + QMetaObject::invokeMethod(object, "killMe"); + QVERIFY(object); + QTest::qWait(0); + QVERIFY(!object); +} + +/* + tests that id.toString() works +*/ +void tst_qmlecmascript::objectToString() +{ + QmlComponent component(&engine, TEST_FILE("qmlToString.qml")); + MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create()); + QVERIFY(object != 0); + QMetaObject::invokeMethod(object, "testToString"); + QVERIFY(object->stringProperty().startsWith("Qml Object, \"objName\" MyQmlObject_QML_15")); +} + QTEST_MAIN(tst_qmlecmascript) #include "tst_qmlecmascript.moc" |