From 07b3465405ccd59dc5c447cffc47cc1a17f674f0 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 7 Oct 2009 15:18:06 +1000 Subject: Add three failing tests to the QML ECMAscript autotest Tests the creation, deletion and toString functions for QML objects. Task-number: QT-2252 --- .../qmlecmascript/data/dynamicCreation.helper.qml | 5 ++ .../qmlecmascript/data/dynamicCreation.qml | 16 +++++ .../qmlecmascript/data/dynamicDeletion.qml | 20 +++++++ .../declarative/qmlecmascript/data/qmlToString.qml | 11 ++++ .../qmlecmascript/tst_qmlecmascript.cpp | 69 ++++++++++++++++++++++ 5 files changed, 121 insertions(+) create mode 100644 tests/auto/declarative/qmlecmascript/data/dynamicCreation.helper.qml create mode 100644 tests/auto/declarative/qmlecmascript/data/dynamicCreation.qml create mode 100644 tests/auto/declarative/qmlecmascript/data/dynamicDeletion.qml create mode 100644 tests/auto/declarative/qmlecmascript/data/qmlToString.qml 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 #include #include +#include #include #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(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(component.create()); + QVERIFY(object != 0); + QGuard 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(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" -- cgit v0.12