summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qmlecmascript
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/declarative/qmlecmascript')
-rw-r--r--tests/auto/declarative/qmlecmascript/data/dynamicCreation.helper.qml5
-rw-r--r--tests/auto/declarative/qmlecmascript/data/dynamicCreation.qml16
-rw-r--r--tests/auto/declarative/qmlecmascript/data/dynamicDeletion.qml20
-rw-r--r--tests/auto/declarative/qmlecmascript/data/qmlToString.qml11
-rw-r--r--tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp67
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 15a7860..c7f0424 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"
@@ -55,6 +56,9 @@ private slots:
void signalParameterTypes();
void objectsCompareAsEqual();
void scriptAccess();
+ void dynamicCreation();
+ void dynamicDestruction();
+ void objectToString();
private:
QmlEngine engine;
@@ -615,6 +619,69 @@ void tst_qmlecmascript::scriptAccess()
QCOMPARE(object->property("test3").toInt(), 0);
}
+/*
+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"