summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMatthew Vogt <matthew.vogt@nokia.com>2012-02-22 16:12:26 +1000
committerQt by Nokia <qt-info@nokia.com>2012-02-22 08:16:48 +0100
commit136f2352f67eedc12a719aa239594a204c3ee5a7 (patch)
tree6790e6fc952c84f1748746960a12835084f454c9 /tests
parent6f96bf2d8d91cc03aa72fd90517f90ec5804d1ca (diff)
Add test verifying that QObject-derived pointer is passed correctly.
Ensure that an object derived from QObject is correctly passed to an invokable function from QML. Change-Id: I71eefe8c480e1f1574804d05244b53f29c7fbf0d Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/qobjectDerivedArgument.qml17
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp40
2 files changed, 57 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/qobjectDerivedArgument.qml b/tests/auto/declarative/qdeclarativeecmascript/data/qobjectDerivedArgument.qml
new file mode 100644
index 0000000000..bf4ab6fd7a
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/qobjectDerivedArgument.qml
@@ -0,0 +1,17 @@
+import QtQuick 2.0
+import Qt.test 1.0
+
+MyQmlObject {
+ id: root
+ stringProperty: 'hello'
+ property var child
+
+ property bool result: false
+
+ Component.onCompleted: {
+ child = invokable.createMyQmlObject('goodbye');
+
+ result = (invokable.getStringProperty(root) == 'hello') &&
+ (invokable.getStringProperty(child) == 'goodbye');
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
index 354087da8a..d30766f982 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
+++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
@@ -235,6 +235,7 @@ private slots:
void rewriteMultiLineStrings();
void revisionErrors();
void revision();
+ void invokableWithQObjectDerived();
void automaticSemicolon();
void unaryExpression();
@@ -6017,6 +6018,45 @@ void tst_qdeclarativeecmascript::tryStatement()
}
}
+class CppInvokableWithQObjectDerived : public QObject
+{
+ Q_OBJECT
+public:
+ CppInvokableWithQObjectDerived() {}
+ ~CppInvokableWithQObjectDerived() {}
+
+ Q_INVOKABLE MyQmlObject *createMyQmlObject(QString data)
+ {
+ MyQmlObject *obj = new MyQmlObject();
+ obj->setStringProperty(data);
+ return obj;
+ }
+
+ Q_INVOKABLE QString getStringProperty(MyQmlObject *obj)
+ {
+ return obj->stringProperty();
+ }
+};
+
+void tst_qdeclarativeecmascript::invokableWithQObjectDerived()
+{
+ CppInvokableWithQObjectDerived invokable;
+
+ {
+ QDeclarativeEngine engine;
+ engine.rootContext()->setContextProperty("invokable", &invokable);
+
+ QDeclarativeComponent component(&engine, testFileUrl("qobjectDerivedArgument.qml"));
+
+ QObject *object = component.create();
+
+ QVERIFY(object != 0);
+ QVERIFY(object->property("result").value<bool>() == true);
+
+ delete object;
+ }
+}
+
QTEST_MAIN(tst_qdeclarativeecmascript)
#include "tst_qdeclarativeecmascript.moc"