summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qmlqt
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/declarative/qmlqt')
-rw-r--r--tests/auto/declarative/qmlqt/data/createComponent.qml23
-rw-r--r--tests/auto/declarative/qmlqt/data/createComponentData.qml5
-rw-r--r--tests/auto/declarative/qmlqt/data/createQmlObject.qml31
-rw-r--r--tests/auto/declarative/qmlqt/tst_qmlqt.cpp53
4 files changed, 112 insertions, 0 deletions
diff --git a/tests/auto/declarative/qmlqt/data/createComponent.qml b/tests/auto/declarative/qmlqt/data/createComponent.qml
new file mode 100644
index 0000000..57f50d8
--- /dev/null
+++ b/tests/auto/declarative/qmlqt/data/createComponent.qml
@@ -0,0 +1,23 @@
+import Qt 4.6
+
+Object {
+ property bool incorrectArgCount1: false
+ property bool incorrectArgCount2: false
+ property bool emptyArg: false
+
+ property string relativeUrl
+ property string absoluteUrl
+
+ Component.onCompleted: {
+ // Test that using incorrect argument count returns a null object
+ incorrectArgCount1 = (createComponent() == null);
+ incorrectArgCount2 = (createComponent("main.qml", 10) == null);
+ emptyArg = (createComponent("") == null);
+
+ var r = createComponent("createComponentData.qml");
+ relativeUrl = r.url;
+
+ var a = createComponent("http://www.example.com/test.qml");
+ absoluteUrl = a.url;
+ }
+}
diff --git a/tests/auto/declarative/qmlqt/data/createComponentData.qml b/tests/auto/declarative/qmlqt/data/createComponentData.qml
new file mode 100644
index 0000000..145fe78
--- /dev/null
+++ b/tests/auto/declarative/qmlqt/data/createComponentData.qml
@@ -0,0 +1,5 @@
+import Qt 4.6
+
+Object {
+ property int test: 1913
+}
diff --git a/tests/auto/declarative/qmlqt/data/createQmlObject.qml b/tests/auto/declarative/qmlqt/data/createQmlObject.qml
new file mode 100644
index 0000000..8e8919a
--- /dev/null
+++ b/tests/auto/declarative/qmlqt/data/createQmlObject.qml
@@ -0,0 +1,31 @@
+import Qt 4.6
+
+Item {
+ id: root
+
+ property bool incorrectArgCount1: false
+ property bool incorrectArgCount2: false
+ property bool emptyArg: false
+ property bool noParent: false
+ property bool notReady: false
+ property bool runtimeError: false
+ property bool errors: false
+
+ property bool success: false
+
+ Component.onCompleted: {
+ // errors
+ incorrectArgCount1 = (createQmlObject() == null);
+ incorrectArgCount2 = (createQmlObject("import Qt 4.6\nObject{}", root, "main.qml", 10) == null);
+ emptyArg = (createQmlObject("", root) == null);
+ errors = (createQmlObject("import Qt 4.6\nObject{\nproperty int test: 13\nproperty int test: 13\n}", root, "main.qml") == null);
+ noParent = (createQmlObject("import Qt 4.6\nObject{\nproperty int test: 13}", 0) == null);
+ notReady = (createQmlObject("import Qt 4.6\nObject{\nBlah{}\n}", root, "http://www.example.com/main.qml") == null);
+ runtimeError = (createQmlObject("import Qt 4.6\nObject{property int test\nonTestChanged: Object{}\n}", root) == null);
+
+ var o = createQmlObject("import Qt 4.6\nObject{\nproperty int test: 13\n}", root);
+ success = (o.test == 13);
+
+ createQmlObject("import Qt 4.6\nItem {}\n", root);
+ }
+}
diff --git a/tests/auto/declarative/qmlqt/tst_qmlqt.cpp b/tests/auto/declarative/qmlqt/tst_qmlqt.cpp
index 4d09aee..292102a 100644
--- a/tests/auto/declarative/qmlqt/tst_qmlqt.cpp
+++ b/tests/auto/declarative/qmlqt/tst_qmlqt.cpp
@@ -47,6 +47,7 @@
#include <QDir>
#include <QVector3D>
#include <QCryptographicHash>
+#include <QmlGraphicsItem>
class tst_qmlqt : public QObject
{
@@ -69,6 +70,8 @@ private slots:
void playSound();
void openUrlExternally();
void md5();
+ void createComponent();
+ void createQmlObject();
private:
QmlEngine engine;
@@ -299,6 +302,56 @@ void tst_qmlqt::md5()
delete object;
}
+void tst_qmlqt::createComponent()
+{
+ QmlComponent component(&engine, TEST_FILE("createComponent.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QCOMPARE(object->property("incorrectArgCount1").toBool(), true);
+ QCOMPARE(object->property("incorrectArgCount2").toBool(), true);
+ QCOMPARE(object->property("emptyArg").toBool(), true);
+
+ QCOMPARE(object->property("absoluteUrl").toString(), QString("http://www.example.com/test.qml"));
+ QCOMPARE(object->property("relativeUrl").toString(), TEST_FILE("createComponentData.qml").toString());
+
+ delete object;
+}
+
+void tst_qmlqt::createQmlObject()
+{
+ QmlComponent component(&engine, TEST_FILE("createQmlObject.qml"));
+
+ QString warning1 = "QmlEngine::createQmlObject():";
+ QString warning2 = " " + TEST_FILE("main.qml").toString() + ":4:1: Duplicate property name";
+ QString warning3 = "QmlEngine::createQmlObject(): Component is not ready";
+ QString warning4 = "QmlEngine::createQmlObject():";
+ QString warning5 = " :3: Cannot assign object type QObject with no default method";
+
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warning3));
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warning4));
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warning5));
+
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QCOMPARE(object->property("incorrectArgCount1").toBool(), true);
+ QCOMPARE(object->property("incorrectArgCount2").toBool(), true);
+ QCOMPARE(object->property("emptyArg").toBool(), true);
+ QCOMPARE(object->property("errors").toBool(), true);
+ QCOMPARE(object->property("noParent").toBool(), true);
+ QCOMPARE(object->property("notReady").toBool(), true);
+ QCOMPARE(object->property("runtimeError").toBool(), true);
+ QCOMPARE(object->property("success").toBool(), true);
+
+ QmlGraphicsItem *item = qobject_cast<QmlGraphicsItem *>(object);
+ QVERIFY(item != 0);
+ QVERIFY(item->childItems().count() == 1);
+
+ delete object;
+}
QTEST_MAIN(tst_qmlqt)