diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-11-30 04:30:35 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-11-30 04:31:48 (GMT) |
commit | 46213b30d639505849d079b30e72ef8393e9a748 (patch) | |
tree | 4b144b2af2fd4cdd614e213342d27cec7550949c /tests | |
parent | 1de080649c6b810ed6bc05e883795687ecde1f3d (diff) | |
download | Qt-46213b30d639505849d079b30e72ef8393e9a748.zip Qt-46213b30d639505849d079b30e72ef8393e9a748.tar.gz Qt-46213b30d639505849d079b30e72ef8393e9a748.tar.bz2 |
Correctly handle CppOwnership even when a QDeclarativeData doesn't exist
Task-number: QTBUG-15695
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 14755f32..7c0a316 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -135,6 +135,7 @@ private slots: void scriptConnect(); void scriptDisconnect(); void ownership(); + void cppOwnershipReturnValue(); void qlistqobjectMethods(); void strictlyEquals(); void compiled(); @@ -2100,6 +2101,51 @@ void tst_qdeclarativeecmascript::ownership() } } +class CppOwnershipReturnValue : public QObject +{ + Q_OBJECT +public: + CppOwnershipReturnValue() : value(0) {} + + Q_INVOKABLE QObject *create() { + Q_ASSERT(value == 0); + + value = new QObject; + QDeclarativeEngine::setObjectOwnership(value, QDeclarativeEngine::CppOwnership); + return value; + } + + QPointer<QObject> value; +}; + +// QTBUG-15695. +// Test setObjectOwnership(CppOwnership) works even when there is no QDeclarativeData +void tst_qdeclarativeecmascript::cppOwnershipReturnValue() +{ + 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.create(); }\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 |