diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-10-02 08:11:48 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-10-02 08:14:44 (GMT) |
commit | 2d003378ff5e7621d5dcc810408039cfe13a8c0a (patch) | |
tree | 079e92fdcf9b73c4167e9ab1a001a79a8285de3f /tests/auto | |
parent | 686330063c26fc6ebe65c7374811c94e9680c2c0 (diff) | |
download | Qt-2d003378ff5e7621d5dcc810408039cfe13a8c0a.zip Qt-2d003378ff5e7621d5dcc810408039cfe13a8c0a.tar.gz Qt-2d003378ff5e7621d5dcc810408039cfe13a8c0a.tar.bz2 |
attempt to make QScriptEngine::collectGarbage() autotest more robust
Since the GC looks for pointers in the C stack, try to kill those
pointers before calling collectGarbage().
Reviewed-by: Simon Hausmann
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qscriptengine/tst_qscriptengine.cpp | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index f2c7157..25ee00f 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -48,6 +48,7 @@ #include <qgraphicsitem.h> #include <qstandarditemmodel.h> #include <QtCore/qnumeric.h> +#include <stdlib.h> Q_DECLARE_METATYPE(QList<int>) Q_DECLARE_METATYPE(QObjectList) @@ -60,6 +61,22 @@ Q_DECLARE_METATYPE(QObjectList) # define TOSTRING(x) STRINGIFY(x) # define SRCDIR "C:/Private/" TOSTRING(SYMBIAN_SRCDIR_UID) #endif + +// The JavaScriptCore GC marks the C stack. To try to ensure that there is +// no JSObject* left in stack memory by the compiler, we call this function +// to zap some bytes of memory before calling collectGarbage(). +static void zapSomeStack() +{ + char buf[4096]; + memset(buf, 0, sizeof(buf)); +} + +static void collectGarbage_helper(QScriptEngine &eng) +{ + zapSomeStack(); + eng.collectGarbage(); +} + class tst_QScriptEngine : public QObject { Q_OBJECT @@ -825,7 +842,7 @@ void tst_QScriptEngine::newQMetaObject() // verify that AutoOwnership is in effect instance = QScriptValue(); - eng.collectGarbage(); + collectGarbage_helper(eng); QVERIFY(!qpointer1); QVERIFY(qpointer2); @@ -835,7 +852,7 @@ void tst_QScriptEngine::newQMetaObject() QVERIFY(instance3.toQObject() == 0); // was child of instance QVERIFY(instance2.toQObject() != 0); instance2 = QScriptValue(); - eng.collectGarbage(); + collectGarbage_helper(eng); QVERIFY(instance2.toQObject() == 0); // with custom constructor @@ -922,14 +939,14 @@ void tst_QScriptEngine::getSetGlobalObject() QCOMPARE(eng.globalObject().toString(), QString::fromLatin1("[object Object]")); glob = QScriptValue(); // kill reference to old global object - eng.collectGarbage(); + collectGarbage_helper(eng); obj = eng.newObject(); eng.setGlobalObject(obj); QVERIFY(eng.globalObject().strictlyEquals(obj)); QVERIFY(eng.currentContext()->thisObject().strictlyEquals(obj)); QVERIFY(eng.currentContext()->activationObject().strictlyEquals(obj)); - eng.collectGarbage(); + collectGarbage_helper(eng); QVERIFY(eng.globalObject().strictlyEquals(obj)); QVERIFY(eng.currentContext()->thisObject().strictlyEquals(obj)); QVERIFY(eng.currentContext()->activationObject().strictlyEquals(obj)); @@ -2341,11 +2358,8 @@ void tst_QScriptEngine::collectGarbage() a = eng.newObject(); QPointer<QObject> ptr = new QObject(); QVERIFY(ptr != 0); - { - QScriptValue v = eng.newQObject(ptr, QScriptEngine::ScriptOwnership); - } - eng.collectGarbage(); - QEXPECT_FAIL("","collectGarbage not working", Continue); + (void)eng.newQObject(ptr, QScriptEngine::ScriptOwnership); + collectGarbage_helper(eng); QVERIFY(ptr == 0); } |