diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-10-29 03:54:47 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-10-29 03:54:47 (GMT) |
commit | bfbded95056d43a65b2c9ef1fa90bfd40adc6472 (patch) | |
tree | c20ababb5a2e124e9c7ac796ace1d52380470bd3 /tests/auto/qscriptengineagent | |
parent | e8bc4cebe9963a8a4534a5febbd606a6e4d6a332 (diff) | |
parent | f425c08d4f2e7f061a0ee8e4a1eee2b17fa64962 (diff) | |
download | Qt-bfbded95056d43a65b2c9ef1fa90bfd40adc6472.zip Qt-bfbded95056d43a65b2c9ef1fa90bfd40adc6472.tar.gz Qt-bfbded95056d43a65b2c9ef1fa90bfd40adc6472.tar.bz2 |
Merge branch '4.6' of ../qt into kinetic-declarativeui
Conflicts:
src/script/api/qscriptengine.cpp
src/script/api/qscriptprogram.cpp
src/script/api/qscriptprogram.h
src/script/api/qscriptprogram_p.h
tests/auto/qscriptengine/tst_qscriptengine.cpp
tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp
tools/qdoc3/test/qt-inc.qdocconf
Diffstat (limited to 'tests/auto/qscriptengineagent')
-rw-r--r-- | tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp | 85 |
1 files changed, 84 insertions, 1 deletions
diff --git a/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp b/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp index 81f0ee5..a761aac 100644 --- a/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp +++ b/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp @@ -110,10 +110,10 @@ private slots: void extension_invoctaion(); void extension(); void isEvaluatingInExtension(); + void hasUncaughtException(); void evaluateProgram(); void evaluateProgram_SyntaxError(); void evaluateNullProgram(); - void hasUncaughtException(); private: double m_testProperty; @@ -2306,5 +2306,88 @@ void tst_QScriptEngineAgent::hasUncaughtException() QVERIFY2(spy->isPass(), "At least one of a functionExit event should set hasUncaughtException flag."); } +void tst_QScriptEngineAgent::evaluateProgram() +{ + QScriptEngine eng; + QScriptProgram program("1 + 2", "foo.js", 123); + ScriptEngineSpy *spy = new ScriptEngineSpy(&eng); + qint64 scriptId = -1; + for (int x = 0; x < 10; ++x) { + spy->clear(); + (void)eng.evaluate(program); + QCOMPARE(spy->count(), (x == 0) ? 4 : 3); + + if (x == 0) { + // script is only loaded on first execution + QCOMPARE(spy->at(0).type, ScriptEngineEvent::ScriptLoad); + scriptId = spy->at(0).scriptId; + QVERIFY(scriptId != -1); + QCOMPARE(spy->at(0).script, program.sourceCode()); + QCOMPARE(spy->at(0).fileName, program.fileName()); + QCOMPARE(spy->at(0).lineNumber, program.firstLineNumber()); + spy->removeFirst(); + } + + QCOMPARE(spy->at(0).type, ScriptEngineEvent::FunctionEntry); // evaluate() + QCOMPARE(spy->at(0).scriptId, scriptId); + + QCOMPARE(spy->at(1).type, ScriptEngineEvent::PositionChange); + QCOMPARE(spy->at(1).scriptId, scriptId); + QCOMPARE(spy->at(1).lineNumber, program.firstLineNumber()); + + QCOMPARE(spy->at(2).type, ScriptEngineEvent::FunctionExit); // evaluate() + QCOMPARE(spy->at(2).scriptId, scriptId); + QVERIFY(spy->at(2).value.isNumber()); + QCOMPARE(spy->at(2).value.toNumber(), qsreal(3)); + } +} + +void tst_QScriptEngineAgent::evaluateProgram_SyntaxError() +{ + QScriptEngine eng; + QScriptProgram program("this is not valid syntax", "foo.js", 123); + ScriptEngineSpy *spy = new ScriptEngineSpy(&eng); + qint64 scriptId = -1; + for (int x = 0; x < 10; ++x) { + spy->clear(); + (void)eng.evaluate(program); + QCOMPARE(spy->count(), (x == 0) ? 8 : 7); + + if (x == 0) { + // script is only loaded on first execution + QCOMPARE(spy->at(0).type, ScriptEngineEvent::ScriptLoad); + scriptId = spy->at(0).scriptId; + QVERIFY(scriptId != -1); + QCOMPARE(spy->at(0).script, program.sourceCode()); + QCOMPARE(spy->at(0).fileName, program.fileName()); + QCOMPARE(spy->at(0).lineNumber, program.firstLineNumber()); + spy->removeFirst(); + } + + QCOMPARE(spy->at(0).type, ScriptEngineEvent::FunctionEntry); // evaluate() + QCOMPARE(spy->at(0).scriptId, scriptId); + + QCOMPARE(spy->at(1).type, ScriptEngineEvent::ContextPush); // SyntaxError constructor + QCOMPARE(spy->at(2).type, ScriptEngineEvent::FunctionEntry); // SyntaxError constructor + QCOMPARE(spy->at(3).type, ScriptEngineEvent::FunctionExit); // SyntaxError constructor + QCOMPARE(spy->at(4).type, ScriptEngineEvent::ContextPop); // SyntaxError constructor + + QCOMPARE(spy->at(5).type, ScriptEngineEvent::ExceptionThrow); + QVERIFY(spy->at(5).value.isError()); + QCOMPARE(spy->at(5).value.toString(), QString::fromLatin1("SyntaxError: Parse error")); + + QCOMPARE(spy->at(6).type, ScriptEngineEvent::FunctionExit); // evaluate() + QCOMPARE(spy->at(6).scriptId, scriptId); + } +} + +void tst_QScriptEngineAgent::evaluateNullProgram() +{ + QScriptEngine eng; + ScriptEngineSpy *spy = new ScriptEngineSpy(&eng); + (void)eng.evaluate(QScriptProgram()); + QCOMPARE(spy->count(), 0); +} + QTEST_MAIN(tst_QScriptEngineAgent) #include "tst_qscriptengineagent.moc" |