From fa3a9815a3c4b1b7cd464648e67c16d299773f87 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Thu, 22 Oct 2009 11:11:27 +1000 Subject: Test createQmlObject URL resolution (must be relative to calling context). Task-number:QT-2339 See also c1a241652c587e6da92bf853608aed37938e1e48 Also make test more data-driven (and hence independently reported). --- .../qmlecmascript/data/TypeForDynamicCreation.qml | 2 ++ .../qmlecmascript/data/dynamicCreation.qml | 5 ++++ .../qmlecmascript/tst_qmlecmascript.cpp | 29 ++++++++++++++-------- 3 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 tests/auto/declarative/qmlecmascript/data/TypeForDynamicCreation.qml 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("method"); + QTest::addColumn("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(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); } /* -- cgit v0.12