diff options
Diffstat (limited to 'tests/auto/declarative/qdeclarativeecmascript')
-rw-r--r-- | tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 7c0a316..77fab91 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -136,6 +136,7 @@ private slots: void scriptDisconnect(); void ownership(); void cppOwnershipReturnValue(); + void ownershipCustomReturnValue(); void qlistqobjectMethods(); void strictlyEquals(); void compiled(); @@ -2106,6 +2107,7 @@ class CppOwnershipReturnValue : public QObject Q_OBJECT public: CppOwnershipReturnValue() : value(0) {} + ~CppOwnershipReturnValue() { delete value; } Q_INVOKABLE QObject *create() { Q_ASSERT(value == 0); @@ -2115,6 +2117,14 @@ public: return value; } + Q_INVOKABLE MyQmlObject *createQmlObject() { + Q_ASSERT(value == 0); + + MyQmlObject *rv = new MyQmlObject; + value = rv; + return rv; + } + QPointer<QObject> value; }; @@ -2146,6 +2156,33 @@ void tst_qdeclarativeecmascript::cppOwnershipReturnValue() QVERIFY(source.value != 0); } +// QTBUG-15697 +void tst_qdeclarativeecmascript::ownershipCustomReturnValue() +{ + CppOwnershipReturnValue source; + + { + QDeclarativeEngine engine; + engine.rootContext()->setContextProperty("source", &source); + + QVERIFY(source.value == 0); + + QDeclarativeComponent component(&engine); + component.setData("import QtQuick 1.0\nQtObject {\nComponent.onCompleted: { var a = source.createQmlObject(); }\n}\n", QUrl()); + + QObject *object = component.create(); + + QVERIFY(object != 0); + QVERIFY(source.value != 0); + + delete object; + } + + QCoreApplication::instance()->processEvents(QEventLoop::DeferredDeletion); + + QVERIFY(source.value == 0); +} + class QListQObjectMethodsObject : public QObject { Q_OBJECT |