diff options
author | Alan Alpert <alan.alpert@nokia.com> | 2009-10-07 05:18:06 (GMT) |
---|---|---|
committer | Alan Alpert <alan.alpert@nokia.com> | 2009-10-07 05:18:51 (GMT) |
commit | 07b3465405ccd59dc5c447cffc47cc1a17f674f0 (patch) | |
tree | 7b5d0d535b1a4ae27ea3383b03a5dafed935b19d /tests/auto/declarative | |
parent | 19d080d319dccac15654294af80530bed9ef11ea (diff) | |
download | Qt-07b3465405ccd59dc5c447cffc47cc1a17f674f0.zip Qt-07b3465405ccd59dc5c447cffc47cc1a17f674f0.tar.gz Qt-07b3465405ccd59dc5c447cffc47cc1a17f674f0.tar.bz2 |
Add three failing tests to the QML ECMAscript autotest
Tests the creation, deletion and toString functions for QML objects.
Task-number: QT-2252
Diffstat (limited to 'tests/auto/declarative')
5 files changed, 121 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..58ca26e --- /dev/null +++ b/tests/auto/declarative/qmlecmascript/data/dynamicCreation.helper.qml @@ -0,0 +1,5 @@ +import Qt.Test 1.0 + +MyQmlObject{ + objectName: "desolateObject" +} diff --git a/tests/auto/declarative/qmlecmascript/data/dynamicCreation.qml b/tests/auto/declarative/qmlecmascript/data/dynamicCreation.qml new file mode 100644 index 0000000..f3eb75f --- /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:"emptyObject"}', 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..618723f --- /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 killIt(wait) + { + if(obj.objectProperty == undefined || obj.objectProperty == null) + return; + if(wait > 0) + obj.objectProperty.destroy(wait); + else + obj.objectProperty.destroy(); + } +} 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..778b37f 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,71 @@ 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("emptyObject")); + + QMetaObject::invokeMethod(object, "createTwo"); + createdComponent = object->objectProperty(); + QVERIFY(createdComponent); + QCOMPARE(createdQmlObject->objectName(), QString("desolateObject")); +} + +/* + Tests the destroy function +*/ +void tst_qmlecmascript::dynamicDestruction() +{ + QmlComponent component(&engine, TEST_FILE("dynamicDeletion.qml")); + 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, "killIt", Q_ARG(int, 0)); + QVERIFY(createdQmlObject); + QTest::qWait(0); + QVERIFY(!createdQmlObject); + + QMetaObject::invokeMethod(object, "create"); + QVERIFY(createdQmlObject); + QMetaObject::invokeMethod(object, "killIt", Q_ARG(int, 100)); + QVERIFY(createdQmlObject); + QTest::qWait(0); + QVERIFY(createdQmlObject); + QTest::qWait(100); + QVERIFY(!createdQmlObject); +} + +/* + 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" |