Improve reliability of propertyVarOwnership test
authorSimon Hausmann <simon.hausmann@digia.com>
Tue, 27 Aug 2013 10:11:18 +0000 (12:11 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 27 Aug 2013 11:55:22 +0000 (13:55 +0200)
In the last expect-to-collect-a-QObject test, avoid calling gc() from within
JavaScript and call it from C++ instead with zap stacking. That reduces the
probability of finding an old reference on the stack that would keep the
object alive.

Change-Id: Ia9c66dd188f31264a70ad4dbd20356d16aa7a057
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
tests/auto/qml/qqmlecmascript/data/propertyVarOwnership.5.qml
tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp

index c2325fb..580b95e 100644 (file)
@@ -21,8 +21,6 @@ Item {
     }
 
     function runTest() {
-        if (!createComponent()) return;
-        gc();  // collect object's v8object + varProperties, queues deleteLater.
         if (SingletonType.QObject.trackedObject() != null) return;        // v8object was previously collected.
         SingletonType.QObject.setTrackedObjectProperty("varprop");        // deferences varProperties of object.
         test = !(SingletonType.QObject.trackedObjectProperty("varprop")); // deferences varProperties of object.
index 166e6cb..5d02f79 100644 (file)
@@ -320,14 +320,20 @@ static void NO_INLINE zapSomeStack()
     memset(buf, 0, 4096);
 }
 
-static void gc(QQmlEngine &engine)
+static void gcWithoutDeferredObjectDeletion(QQmlEngine &engine)
 {
     zapSomeStack();
     engine.collectGarbage();
+}
+
+static void gc(QQmlEngine &engine)
+{
+    gcWithoutDeferredObjectDeletion(engine);
     QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
     QCoreApplication::processEvents();
 }
 
+
 void tst_qqmlecmascript::initTestCase()
 {
     QQmlDataTest::initTestCase();
@@ -4753,6 +4759,8 @@ void tst_qqmlecmascript::propertyVarOwnership()
     QQmlComponent component(&engine, testFileUrl("propertyVarOwnership.5.qml"));
     QObject *object = component.create();
     QVERIFY(object != 0);
+    QMetaObject::invokeMethod(object, "createComponent");
+    gcWithoutDeferredObjectDeletion(engine);
     QMetaObject::invokeMethod(object, "runTest");
     QCOMPARE(object->property("test").toBool(), true);
     delete object;