diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2011-02-10 09:47:57 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2011-02-10 09:47:57 (GMT) |
commit | 6da5d0be4d98c0cb47352cd79a86b729d6e77ffc (patch) | |
tree | 60ac6b27c3ee2b0a895183191664655b2876fe73 | |
parent | abb425e3db6c20c5271788cb1ec4e1fe37b9ea5b (diff) | |
parent | ad8ff4b6f6204a982d6050a45997d3a27be01fac (diff) | |
download | Qt-6da5d0be4d98c0cb47352cd79a86b729d6e77ffc.zip Qt-6da5d0be4d98c0cb47352cd79a86b729d6e77ffc.tar.gz Qt-6da5d0be4d98c0cb47352cd79a86b729d6e77ffc.tar.bz2 |
Merge branch 'master' of scm.dev.nokia.troll.no:qt/qt-air-staging into master-integration
* 'master' of scm.dev.nokia.troll.no:qt/qt-air-staging:
Update tests for QScriptEngineAgent.
-rw-r--r-- | tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp | 57 |
1 files changed, 50 insertions, 7 deletions
diff --git a/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp b/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp index dce09d3..d89f9f1 100644 --- a/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp +++ b/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp @@ -73,6 +73,7 @@ signals: void testSignal(double arg); private slots: + void unloadRecursion(); void scriptLoadAndUnload_statement(); void scriptLoadAndUnload(); void scriptLoadAndUnload_eval(); @@ -345,6 +346,46 @@ QVariant ScriptEngineSpy::extension(Extension ext, const QVariant &arg) return QVariant(); } +static void collectScriptObjects(QScriptEngine *engine) +{ + // We call garbage collection few times to collect objects that + // are unreferenced after first gc. We try to force full gc. + engine->collectGarbage(); + engine->collectGarbage(); + engine->collectGarbage(); +} + +class EvaluatingAgent : public QScriptEngineAgent { +public: + EvaluatingAgent(QScriptEngine *engine) + : QScriptEngineAgent(engine) + , count(0) + {} + + virtual void scriptUnload(qint64) + { + if (++count > 10) // recursion breaker. + return; + // check if recursive evaluation works + engine()->evaluate(";"); + collectScriptObjects(engine()); + } + + bool isOk() const { return count > 10; } +private: + int count; +}; + +void tst_QScriptEngineAgent::unloadRecursion() +{ + QScriptEngine engine; + EvaluatingAgent *agent = new EvaluatingAgent(&engine); + engine.setAgent(agent); + engine.evaluate(";"); + collectScriptObjects(&engine); + QVERIFY(agent->isOk()); +} + void tst_QScriptEngineAgent::scriptLoadAndUnload_statement() { QScriptEngine eng; @@ -358,6 +399,8 @@ void tst_QScriptEngineAgent::scriptLoadAndUnload_statement() int lineNumber = 123; eng.evaluate(code, fileName, lineNumber); + // Script object have to be garbage collected first. + collectScriptObjects(&eng); QCOMPARE(spy->count(), 2); QCOMPARE(spy->at(0).type, ScriptEngineEvent::ScriptLoad); @@ -377,6 +420,8 @@ void tst_QScriptEngineAgent::scriptLoadAndUnload_statement() int lineNumber = 456; eng.evaluate(code, fileName, lineNumber); + // Script object have to be garbage collected first. + collectScriptObjects(&eng); QCOMPARE(spy->count(), 2); QCOMPARE(spy->at(0).type, ScriptEngineEvent::ScriptLoad); @@ -414,7 +459,8 @@ void tst_QScriptEngineAgent::scriptLoadAndUnload() code = "foo = null"; eng.evaluate(code); - QCOMPARE(spy->count(), 3); + collectScriptObjects(&eng); // foo() is GC'ed + QCOMPARE(spy->count(), 4); QCOMPARE(spy->at(1).type, ScriptEngineEvent::ScriptLoad); QVERIFY(spy->at(1).scriptId != -1); @@ -425,8 +471,6 @@ void tst_QScriptEngineAgent::scriptLoadAndUnload() QCOMPARE(spy->at(2).type, ScriptEngineEvent::ScriptUnload); QCOMPARE(spy->at(2).scriptId, spy->at(1).scriptId); - eng.collectGarbage(); // foo() is GC'ed - QCOMPARE(spy->count(), 4); QCOMPARE(spy->at(3).type, ScriptEngineEvent::ScriptUnload); QCOMPARE(spy->at(3).scriptId, spy->at(0).scriptId); } @@ -448,6 +492,7 @@ void tst_QScriptEngineAgent::scriptLoadAndUnload() code = "bar = foo(); foo = null"; eng.evaluate(code); + collectScriptObjects(&eng); QCOMPARE(spy->count(), 3); QCOMPARE(spy->at(1).type, ScriptEngineEvent::ScriptLoad); @@ -458,14 +503,12 @@ void tst_QScriptEngineAgent::scriptLoadAndUnload() QCOMPARE(spy->at(2).type, ScriptEngineEvent::ScriptUnload); QCOMPARE(spy->at(2).scriptId, spy->at(1).scriptId); - eng.collectGarbage(); // foo() is not GC'ed + collectScriptObjects(&eng); // foo() is not GC'ed QCOMPARE(spy->count(), 3); code = "bar = null"; eng.evaluate(code); - QCOMPARE(spy->count(), 5); - - eng.collectGarbage(); // foo() is GC'ed + collectScriptObjects(&eng); // foo() is GC'ed QCOMPARE(spy->count(), 6); } delete spy; |