summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativeecmascript
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2010-03-09 04:22:07 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2010-03-09 04:22:07 (GMT)
commit6a5891e7bfd182a52fd71f1b5fdf4d73def63603 (patch)
tree483385969c470974d505c32184620add5f841d5c /tests/auto/declarative/qdeclarativeecmascript
parentc04a6e34b3d4da24d3cc26e192bebff2d3b79d19 (diff)
downloadQt-6a5891e7bfd182a52fd71f1b5fdf4d73def63603.zip
Qt-6a5891e7bfd182a52fd71f1b5fdf4d73def63603.tar.gz
Qt-6a5891e7bfd182a52fd71f1b5fdf4d73def63603.tar.bz2
Integrate QML's object ownership with the JS collector
QML now behaves in a way similar to QtScript when it comes to QObject ownership. QT-2803
Diffstat (limited to 'tests/auto/declarative/qdeclarativeecmascript')
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
index 4838288..d134750 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
+++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
@@ -126,6 +126,7 @@ private slots:
void attachedPropertyScope();
void scriptConnect();
void scriptDisconnect();
+ void ownership();
void bug1();
@@ -889,6 +890,7 @@ void tst_qdeclarativeecmascript::dynamicDestruction()
}
QVERIFY(!createdQmlObject);
+ QDeclarativeEngine::setObjectOwnership(object, QDeclarativeEngine::QMLOwnership);
QMetaObject::invokeMethod(object, "killMe");
QVERIFY(object);
QTest::qWait(0);
@@ -1890,7 +1892,57 @@ void tst_qdeclarativeecmascript::scriptDisconnect()
delete object;
}
+}
+
+class OwnershipObject : public QObject
+{
+ Q_OBJECT
+public:
+ OwnershipObject() { object = new QObject; }
+
+ QPointer<QObject> object;
+
+public slots:
+ QObject *getObject() { return object; }
+};
+
+void tst_qdeclarativeecmascript::ownership()
+{
+ OwnershipObject own;
+ QDeclarativeContext *context = new QDeclarativeContext(engine.rootContext());
+ context->addDefaultObject(&own);
+
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("ownership.qml"));
+
+ QVERIFY(own.object != 0);
+
+ QObject *object = component.create(context);
+ QDeclarativeEnginePrivate::getScriptEngine(&engine)->collectGarbage();
+ QCoreApplication::processEvents(QEventLoop::DeferredDeletion);
+
+ QVERIFY(own.object == 0);
+
+ delete object;
+ }
+
+ own.object = new QObject(&own);
+
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("ownership.qml"));
+
+ QVERIFY(own.object != 0);
+
+ QObject *object = component.create(context);
+ QDeclarativeEnginePrivate::getScriptEngine(&engine)->collectGarbage();
+
+ QCoreApplication::processEvents(QEventLoop::DeferredDeletion);
+
+ QVERIFY(own.object != 0);
+
+ delete object;
+ }
}
QTEST_MAIN(tst_qdeclarativeecmascript)