diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-08-18 11:44:53 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-08-18 11:46:15 (GMT) |
commit | a2af6621a00cf0be03077132a271b2620a725bee (patch) | |
tree | 2489c6e6d7da146150ce53bb728ccff6adf73f6e /tests | |
parent | f21797769e5dc53ed3f5380a362dd975721aac71 (diff) | |
download | Qt-a2af6621a00cf0be03077132a271b2620a725bee.zip Qt-a2af6621a00cf0be03077132a271b2620a725bee.tar.gz Qt-a2af6621a00cf0be03077132a271b2620a725bee.tar.bz2 |
adopt same ownership relationship of scriptengine agents as in old back-end
The engine owns its agents, and also knows when they are deleted.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qscriptengine/tst_qscriptengine.cpp | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index eb24616..cf6ebd8 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -3649,13 +3649,35 @@ public: void tst_QScriptEngine::getSetAgent() { - QScriptEngine eng; - QCOMPARE(eng.agent(), (QScriptEngineAgent*)0); - TestAgent agent(&eng); - eng.setAgent(&agent); - QCOMPARE(eng.agent(), (QScriptEngineAgent*)&agent); - eng.setAgent(0); - QCOMPARE(eng.agent(), (QScriptEngineAgent*)0); + // case 1: engine deleted before agent --> agent deleted too + { + QScriptEngine *eng = new QScriptEngine; + QCOMPARE(eng->agent(), (QScriptEngineAgent*)0); + TestAgent *agent = new TestAgent(eng); + eng->setAgent(agent); + QCOMPARE(eng->agent(), (QScriptEngineAgent*)agent); + eng->setAgent(0); // the engine maintains ownership of the old agent + QCOMPARE(eng->agent(), (QScriptEngineAgent*)0); + delete eng; + } + // case 2: agent deleted before engine --> engine's agent should become 0 + { + QScriptEngine *eng = new QScriptEngine; + TestAgent *agent = new TestAgent(eng); + eng->setAgent(agent); + QCOMPARE(eng->agent(), (QScriptEngineAgent*)agent); + delete agent; + QCOMPARE(eng->agent(), (QScriptEngineAgent*)0); + eng->evaluate("(function(){ return 123; })()"); + delete eng; + } + { + QScriptEngine eng; + QScriptEngine eng2; + TestAgent *agent = new TestAgent(&eng); + QTest::ignoreMessage(QtWarningMsg, "QScriptEngine::setAgent(): cannot set agent belonging to different engine"); + eng2.setAgent(agent); + } } void tst_QScriptEngine::reentrancy() |