diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-10-23 12:57:30 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-10-23 12:57:30 (GMT) |
commit | 4ff3e1ca7ce8afab49e5c52a1ae0141abfc8a841 (patch) | |
tree | 592d015d93478525504f8e09154b633fa2abdae2 /tests/auto/qscriptengineagent | |
parent | c21d3a0094b0692f2f888b04e258229234200e3c (diff) | |
parent | 05aaab72d69a7fa9c23811c1d3ee7d91a9174e46 (diff) | |
download | Qt-4ff3e1ca7ce8afab49e5c52a1ae0141abfc8a841.zip Qt-4ff3e1ca7ce8afab49e5c52a1ae0141abfc8a841.tar.gz Qt-4ff3e1ca7ce8afab49e5c52a1ae0141abfc8a841.tar.bz2 |
Merge branch '4.6' of scm.dev.nokia.troll.no:qt/qt into qscriptprogram
Conflicts:
src/script/api/qscriptengine.cpp
tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp
Diffstat (limited to 'tests/auto/qscriptengineagent')
-rw-r--r-- | tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp b/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp index bdb0414..81f0ee5 100644 --- a/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp +++ b/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp @@ -113,6 +113,7 @@ private slots: void evaluateProgram(); void evaluateProgram_SyntaxError(); void evaluateNullProgram(); + void hasUncaughtException(); private: double m_testProperty; @@ -2269,5 +2270,41 @@ void tst_QScriptEngineAgent::evaluateNullProgram() QCOMPARE(spy->count(), 0); } +class NewSpy :public QScriptEngineAgent +{ + bool m_result; +public: + NewSpy(QScriptEngine* eng) : QScriptEngineAgent(eng), m_result(false) {} + void functionExit (qint64, const QScriptValue &scriptValue) + { + if (engine()->hasUncaughtException()) m_result = true; + } + + bool isPass() { return m_result; } + void reset() { m_result = false; } +}; + +void tst_QScriptEngineAgent::hasUncaughtException() +{ + QScriptEngine eng; + NewSpy* spy = new NewSpy(&eng); + eng.setAgent(spy); + QScriptValue scriptValue; + + // Check unhandled exception. + eng.evaluate("function init () {Unknown.doSth ();}"); + scriptValue = QScriptValue(eng.globalObject().property("init")).call(); + QVERIFY(eng.hasUncaughtException()); + QVERIFY2(spy->isPass(), "At least one of a functionExit event should set hasUncaughtException flag."); + spy->reset(); + + // Check catched exception. + eng.evaluate("function innerFoo() { throw new Error('ciao') }"); + eng.evaluate("function foo() {try { innerFoo() } catch (e) {} }"); + scriptValue = QScriptValue(eng.globalObject().property("foo")).call(); + QVERIFY(!eng.hasUncaughtException()); + QVERIFY2(spy->isPass(), "At least one of a functionExit event should set hasUncaughtException flag."); +} + QTEST_MAIN(tst_QScriptEngineAgent) #include "tst_qscriptengineagent.moc" |