diff options
author | Jedrzej Nowacki <jedrzej.nowacki@nokia.com> | 2009-08-12 12:20:55 (GMT) |
---|---|---|
committer | Jedrzej Nowacki <jedrzej.nowacki@nokia.com> | 2009-08-12 12:25:41 (GMT) |
commit | e806a4e887b6584f1115ced3cb489bb0e9a2de36 (patch) | |
tree | 22bfdf27172da30a31e1efa200547ec862fde0be /tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp | |
parent | 2c3f19a646da948f2f40a79e4a5df8f234398bee (diff) | |
download | Qt-e806a4e887b6584f1115ced3cb489bb0e9a2de36.zip Qt-e806a4e887b6584f1115ced3cb489bb0e9a2de36.tar.gz Qt-e806a4e887b6584f1115ced3cb489bb0e9a2de36.tar.bz2 |
Autotests refactoring
Many tests were divided into smaller pieces. Some XFAIL added. Small
improvements.
Diffstat (limited to 'tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp')
-rw-r--r-- | tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp | 423 |
1 files changed, 329 insertions, 94 deletions
diff --git a/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp b/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp index 7475cb8..8806e77 100644 --- a/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp +++ b/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp @@ -44,6 +44,7 @@ #include <QtScript/qscriptengineagent.h> #include <QtScript/qscriptengine.h> +#include <qscriptvalueiterator.h> //TESTED_CLASS= //TESTED_FILES= @@ -67,11 +68,14 @@ signals: void testSignal(double arg); private slots: + void scriptLoadAndUnload_statement(); void scriptLoadAndUnload(); + void scriptLoadAndUnload_eval(); void contextPushAndPop(); void functionEntryAndExit_semicolon(); void functionEntryAndExit_expression(); void functionEntryAndExit_functionCall(); + void functionEntryAndExit_functionCallWithoutReturn(); void functionEntryAndExit_functionDefinition(); void functionEntryAndExit_native(); void functionEntryAndExit_native2(); @@ -79,16 +83,25 @@ private slots: void functionEntryAndExit_builtin(); void functionEntryAndExit_objects(); void functionEntryAndExit_slots(); - void functionEntryAndExit_property(); + void functionEntryAndExit_property_set(); + void functionEntryAndExit_property_get(); void functionEntryAndExit_call(); - void functionEntryAndExit_functionReturn(); + void functionEntryAndExit_functionReturn_construct(); + void functionEntryAndExit_functionReturn_call(); void functionEntryAndExit_objectCall(); void positionChange(); void exceptionThrowAndCatch(); - void eventOrder(); + void eventOrder_assigment(); + void eventOrder_functionDefinition(); + void eventOrder_throwError(); + void eventOrder_throwAndCatch(); + void eventOrder_functions(); + void eventOrder_throwCatchFinally(); + void eventOrder_signalsHandling(); void recursiveObserve(); void multipleAgents(); void syntaxError(); + void extension_invoctaion(); void extension(); private: @@ -107,13 +120,13 @@ struct ScriptEngineEvent { enum Type { ScriptLoad, - ScriptUnload, + ScriptUnload,//1 ContextPush, - ContextPop, - FunctionEntry, - FunctionExit, + ContextPop, //3 + FunctionEntry, //4 + FunctionExit, //5 PositionChange, - ExceptionThrow, + ExceptionThrow,//7 ExceptionCatch, DebuggerInvocationRequest }; @@ -301,7 +314,7 @@ QVariant ScriptEngineSpy::extension(Extension ext, const QVariant &arg) return QVariant(); } -void tst_QScriptEngineAgent::scriptLoadAndUnload() +void tst_QScriptEngineAgent::scriptLoadAndUnload_statement() { QScriptEngine eng; ScriptEngineSpy *spy = new ScriptEngineSpy(&eng, ~(ScriptEngineSpy::IgnoreScriptLoad @@ -344,7 +357,15 @@ void tst_QScriptEngineAgent::scriptLoadAndUnload() QCOMPARE(spy->at(1).type, ScriptEngineEvent::ScriptUnload); QCOMPARE(spy->at(1).scriptId, spy->at(0).scriptId); } + delete spy; +} +void tst_QScriptEngineAgent::scriptLoadAndUnload() +{ + QScriptEngine eng; + ScriptEngineSpy *spy = new ScriptEngineSpy(&eng, ~(ScriptEngineSpy::IgnoreScriptLoad + | ScriptEngineSpy::IgnoreScriptUnload)); + QCOMPARE(eng.agent(), (QScriptEngineAgent*)spy); { spy->clear(); QString code = "function foo() { print('ciao'); }"; @@ -416,7 +437,14 @@ void tst_QScriptEngineAgent::scriptLoadAndUnload() eng.collectGarbage(); // foo() is GC'ed QCOMPARE(spy->count(), 6); } + delete spy; +} +void tst_QScriptEngineAgent::scriptLoadAndUnload_eval() +{ + QScriptEngine eng; + ScriptEngineSpy *spy = new ScriptEngineSpy(&eng, ~(ScriptEngineSpy::IgnoreScriptLoad + | ScriptEngineSpy::IgnoreScriptUnload)); { spy->clear(); eng.evaluate("eval('function foo() { print(123); }')"); @@ -433,7 +461,7 @@ void tst_QScriptEngineAgent::scriptLoadAndUnload() QCOMPARE(spy->at(2).type, ScriptEngineEvent::ScriptUnload); QCOMPARE(spy->at(2).scriptId, spy->at(0).scriptId); } - + delete spy; } void tst_QScriptEngineAgent::contextPushAndPop() @@ -523,7 +551,7 @@ void tst_QScriptEngineAgent::functionEntryAndExit_functionCall() | ScriptEngineSpy::IgnoreFunctionExit)); { spy->clear(); - eng.evaluate("(function() { return 123; } )()"); + QVERIFY(eng.evaluate("(function() { return 123; } )()").toNumber()==123); QCOMPARE(spy->count(), 4); @@ -550,6 +578,37 @@ void tst_QScriptEngineAgent::functionEntryAndExit_functionCall() delete spy; } +/** check behaiviour of standard function call */ +void tst_QScriptEngineAgent::functionEntryAndExit_functionCallWithoutReturn() +{ + QScriptEngine eng; + ScriptEngineSpy *spy = new ScriptEngineSpy(&eng, ~(ScriptEngineSpy::IgnoreFunctionEntry + | ScriptEngineSpy::IgnoreFunctionExit)); + { + spy->clear(); + eng.evaluate("(function() { var a = 123; } )()"); + + QCOMPARE(spy->count(), 4); + + // evaluate() entry + QCOMPARE(spy->at(0).type, ScriptEngineEvent::FunctionEntry); + QVERIFY(spy->at(0).scriptId != -1); + + // anonymous function entry + QCOMPARE(spy->at(1).type, ScriptEngineEvent::FunctionEntry); + QCOMPARE(spy->at(1).scriptId, spy->at(0).scriptId); + + // anonymous function exit + QCOMPARE(spy->at(2).type, ScriptEngineEvent::FunctionExit); + QCOMPARE(spy->at(2).scriptId, spy->at(0).scriptId); + + // evaluate() exit + QCOMPARE(spy->at(3).type, ScriptEngineEvent::FunctionExit); + QCOMPARE(spy->at(3).scriptId, spy->at(0).scriptId); + } + delete spy; +} + /** check behaiviour of function definition */ void tst_QScriptEngineAgent::functionEntryAndExit_functionDefinition() { @@ -609,6 +668,7 @@ void tst_QScriptEngineAgent::functionEntryAndExit_native() spy->clear(); eng.evaluate("nativeFunctionReturningArg(123)"); + QCOMPARE(spy->count(), 4); // evaluate() entry @@ -680,6 +740,9 @@ void tst_QScriptEngineAgent::functionEntryAndExit_native2() /** check behaiviour of native function throwing error*/ void tst_QScriptEngineAgent::functionEntryAndExit_nativeThrowing() { + /* This function was changed from old backend. JSC return more Entrys / Exits, (exactly +1) + in exception creation time */ + QScriptEngine eng; ScriptEngineSpy *spy = new ScriptEngineSpy(&eng, ~(ScriptEngineSpy::IgnoreFunctionEntry | ScriptEngineSpy::IgnoreFunctionExit)); @@ -689,7 +752,7 @@ void tst_QScriptEngineAgent::functionEntryAndExit_nativeThrowing() spy->clear(); eng.evaluate("nativeFunctionThrowingError('ciao')"); - QCOMPARE(spy->count(), 4); + QCOMPARE(spy->count(), 6); // evaluate() entry QCOMPARE(spy->at(0).type, ScriptEngineEvent::FunctionEntry); @@ -698,15 +761,24 @@ void tst_QScriptEngineAgent::functionEntryAndExit_nativeThrowing() QCOMPARE(spy->at(1).type, ScriptEngineEvent::FunctionEntry); QCOMPARE(spy->at(1).scriptId, qint64(-1)); - // native function exit - QCOMPARE(spy->at(2).type, ScriptEngineEvent::FunctionExit); + // Exception constructor entry + QCOMPARE(spy->at(2).type, ScriptEngineEvent::FunctionEntry); QCOMPARE(spy->at(2).scriptId, qint64(-1)); - QVERIFY(spy->at(2).value.isError()); - // evaluate() exit + // Exception constructor exit QCOMPARE(spy->at(3).type, ScriptEngineEvent::FunctionExit); - QCOMPARE(spy->at(3).scriptId, spy->at(0).scriptId); + QCOMPARE(spy->at(3).scriptId, qint64(-1)); QVERIFY(spy->at(3).value.isError()); + + // native function exit + QCOMPARE(spy->at(4).type, ScriptEngineEvent::FunctionExit); + QCOMPARE(spy->at(4).scriptId, qint64(-1)); + QVERIFY(spy->at(4).value.isError()); + + // evaluate() exit + QCOMPARE(spy->at(5).type, ScriptEngineEvent::FunctionExit); + QCOMPARE(spy->at(5).scriptId, spy->at(0).scriptId); + QVERIFY(spy->at(5).value.isError()); } delete spy; } @@ -720,6 +792,7 @@ void tst_QScriptEngineAgent::functionEntryAndExit_builtin() { spy->clear(); eng.evaluate("'ciao'.toString()"); + QCOMPARE(spy->count(), 4); // evaluate() entry @@ -753,7 +826,7 @@ void tst_QScriptEngineAgent::functionEntryAndExit_objects() { spy->clear(); eng.evaluate("Array(); Boolean(); Date(); Function(); Number(); Object(); RegExp(); String()"); - QCOMPARE(spy->count(), 20); + QCOMPARE(spy->count(), 18); // evaluate() entry QCOMPARE(spy->at(0).type, ScriptEngineEvent::FunctionEntry); @@ -789,61 +862,52 @@ void tst_QScriptEngineAgent::functionEntryAndExit_objects() QCOMPARE(spy->at(7).type, ScriptEngineEvent::FunctionEntry); QCOMPARE(spy->at(7).scriptId, qint64(-1)); - // evaluate() entry - QCOMPARE(spy->at(8).type, ScriptEngineEvent::FunctionEntry); - QVERIFY(spy->at(8).scriptId != -1); + // Function constructor exit + QCOMPARE(spy->at(8).type, ScriptEngineEvent::FunctionExit); + QCOMPARE(spy->at(8).scriptId, qint64(-1)); + QVERIFY(spy->at(8).value.isFunction()); - // evaluate() exit - QCOMPARE(spy->at(9).type, ScriptEngineEvent::FunctionExit); - QCOMPARE(spy->at(9).scriptId, spy->at(8).scriptId); - QVERIFY(spy->at(9).value.isFunction()); + // Number constructor entry + QCOMPARE(spy->at(9).type, ScriptEngineEvent::FunctionEntry); + QCOMPARE(spy->at(9).scriptId, qint64(-1)); - // Function constructor exit + // Number constructor exit QCOMPARE(spy->at(10).type, ScriptEngineEvent::FunctionExit); QCOMPARE(spy->at(10).scriptId, qint64(-1)); - QVERIFY(spy->at(10).value.isFunction()); + QVERIFY(spy->at(10).value.isNumber()); - // Number constructor entry + // Object constructor entry QCOMPARE(spy->at(11).type, ScriptEngineEvent::FunctionEntry); QCOMPARE(spy->at(11).scriptId, qint64(-1)); - // Number constructor exit + // Object constructor exit QCOMPARE(spy->at(12).type, ScriptEngineEvent::FunctionExit); QCOMPARE(spy->at(12).scriptId, qint64(-1)); - QVERIFY(spy->at(12).value.isNumber()); + QVERIFY(spy->at(12).value.isObject()); - // Object constructor entry + // RegExp constructor entry QCOMPARE(spy->at(13).type, ScriptEngineEvent::FunctionEntry); QCOMPARE(spy->at(13).scriptId, qint64(-1)); - // Object constructor exit + // RegExp constructor exit QCOMPARE(spy->at(14).type, ScriptEngineEvent::FunctionExit); QCOMPARE(spy->at(14).scriptId, qint64(-1)); - QVERIFY(spy->at(14).value.isObject()); + QVERIFY(spy->at(14).value.isRegExp()); - // RegExp constructor entry + // String constructor entry QCOMPARE(spy->at(15).type, ScriptEngineEvent::FunctionEntry); QCOMPARE(spy->at(15).scriptId, qint64(-1)); - // RegExp constructor exit + // String constructor exit QCOMPARE(spy->at(16).type, ScriptEngineEvent::FunctionExit); QCOMPARE(spy->at(16).scriptId, qint64(-1)); - QVERIFY(spy->at(16).value.isRegExp()); - - // String constructor entry - QCOMPARE(spy->at(17).type, ScriptEngineEvent::FunctionEntry); - QCOMPARE(spy->at(17).scriptId, qint64(-1)); - - // String constructor exit - QCOMPARE(spy->at(18).type, ScriptEngineEvent::FunctionExit); - QCOMPARE(spy->at(18).scriptId, qint64(-1)); - QVERIFY(spy->at(18).value.isString()); + QVERIFY(spy->at(16).value.isString()); // evaluate() exit - QCOMPARE(spy->at(19).type, ScriptEngineEvent::FunctionExit); - QCOMPARE(spy->at(19).scriptId, spy->at(0).scriptId); - QVERIFY(spy->at(19).value.isString()); - QCOMPARE(spy->at(19).value.toString(), QString()); + QCOMPARE(spy->at(17).type, ScriptEngineEvent::FunctionExit); + QCOMPARE(spy->at(17).scriptId, spy->at(0).scriptId); + QVERIFY(spy->at(17).value.isString()); + QCOMPARE(spy->at(17).value.toString(), QString()); } delete spy; } @@ -877,7 +941,7 @@ void tst_QScriptEngineAgent::functionEntryAndExit_slots() } /** check behaiviour of property accessors*/ -void tst_QScriptEngineAgent::functionEntryAndExit_property() +void tst_QScriptEngineAgent::functionEntryAndExit_property_set() { QScriptEngine eng; ScriptEngineSpy *spy = new ScriptEngineSpy(&eng, ~(ScriptEngineSpy::IgnoreFunctionEntry @@ -902,7 +966,21 @@ void tst_QScriptEngineAgent::functionEntryAndExit_property() // evaluate() exit QCOMPARE(spy->at(3).type, ScriptEngineEvent::FunctionExit); QVERIFY(spy->at(3).value.strictlyEquals(spy->at(2).value)); + } + delete spy; +} +/** check behaiviour of property accessors*/ +void tst_QScriptEngineAgent::functionEntryAndExit_property_get() +{ + QScriptEngine eng; + ScriptEngineSpy *spy = new ScriptEngineSpy(&eng, ~(ScriptEngineSpy::IgnoreFunctionEntry + | ScriptEngineSpy::IgnoreFunctionExit)); + // property accessors + { + eng.globalObject().setProperty("qobj", eng.newQObject(this)); + // set + eng.evaluate("qobj.testProperty = 456"); // get spy->clear(); eng.evaluate("qobj.testProperty"); @@ -924,6 +1002,7 @@ void tst_QScriptEngineAgent::functionEntryAndExit_property() delete spy; } + /** check behaiviour of calling script functions from c++*/ void tst_QScriptEngineAgent::functionEntryAndExit_call() { @@ -954,22 +1033,49 @@ void tst_QScriptEngineAgent::functionEntryAndExit_call() } /** check behaiviour of native function returnning arg*/ -void tst_QScriptEngineAgent::functionEntryAndExit_functionReturn() +void tst_QScriptEngineAgent::functionEntryAndExit_functionReturn_call() { QScriptEngine eng; ScriptEngineSpy *spy = new ScriptEngineSpy(&eng, ~(ScriptEngineSpy::IgnoreFunctionEntry | ScriptEngineSpy::IgnoreFunctionExit)); + { + QScriptValue fun = eng.newFunction(nativeFunctionReturningArg); - for (int x = 0; x < 2; ++x) { + spy->clear(); + QScriptValueList args; + args << QScriptValue(&eng, 123); + fun.call(QScriptValue(), args); + QCOMPARE(spy->count(), 2); + + // entry + QCOMPARE(spy->at(0).type, ScriptEngineEvent::FunctionEntry); + QVERIFY(spy->at(0).scriptId == -1); + + // exit + QCOMPARE(spy->at(1).type, ScriptEngineEvent::FunctionExit); + QCOMPARE(spy->at(1).scriptId, spy->at(0).scriptId); + QVERIFY(spy->at(1).value.strictlyEquals(args.at(0))); + } + delete spy; +} + +void tst_QScriptEngineAgent::functionEntryAndExit_functionReturn_construct() +{ + QScriptEngine eng; + ScriptEngineSpy *spy = new ScriptEngineSpy(&eng, ~(ScriptEngineSpy::IgnoreFunctionEntry + | ScriptEngineSpy::IgnoreFunctionExit)); + { QScriptValue fun = eng.newFunction(nativeFunctionReturningArg); spy->clear(); QScriptValueList args; args << QScriptValue(&eng, 123); - if (x) - fun.construct(args); - else - fun.call(QScriptValue(), args); + QScriptValue obj = fun.construct(args); + + QVERIFY(args.at(0).isValid()); + QVERIFY(args.at(0).isNumber()); + QVERIFY(args.at(0).toNumber() == 123); + QCOMPARE(spy->count(), 2); // entry @@ -979,8 +1085,10 @@ void tst_QScriptEngineAgent::functionEntryAndExit_functionReturn() // exit QCOMPARE(spy->at(1).type, ScriptEngineEvent::FunctionExit); QCOMPARE(spy->at(1).scriptId, spy->at(0).scriptId); + QVERIFY(spy->at(1).value.strictlyEquals(args.at(0))); } + delete spy; } @@ -993,6 +1101,8 @@ void tst_QScriptEngineAgent::functionEntryAndExit_objectCall() for (int x = 0; x < 2; ++x) { QScriptValue fun = eng.evaluate("Boolean"); + QVERIFY(!fun.isError()); + spy->clear(); QScriptValueList args; args << QScriptValue(&eng, true); @@ -1470,11 +1580,10 @@ void tst_QScriptEngineAgent::exceptionThrowAndCatch() } } -void tst_QScriptEngineAgent::eventOrder() +void tst_QScriptEngineAgent::eventOrder_assigment() { QScriptEngine eng; ScriptEngineSpy *spy = new ScriptEngineSpy(&eng); - { spy->clear(); eng.evaluate("i = 3; i = 5"); @@ -1497,7 +1606,13 @@ void tst_QScriptEngineAgent::eventOrder() QCOMPARE(spy->at(5).type, ScriptEngineEvent::ScriptUnload); QCOMPARE(spy->at(5).scriptId, spy->at(0).scriptId); } + delete spy; +} +void tst_QScriptEngineAgent::eventOrder_functionDefinition() +{ + QScriptEngine eng; + ScriptEngineSpy *spy = new ScriptEngineSpy(&eng); { spy->clear(); eng.evaluate("function foo(arg) { void(arg); }"); @@ -1540,7 +1655,13 @@ void tst_QScriptEngineAgent::eventOrder() eng.evaluate("foo = null"); eng.collectGarbage(); } + delete spy; +} +void tst_QScriptEngineAgent::eventOrder_throwError() +{ + QScriptEngine eng; + ScriptEngineSpy *spy = new ScriptEngineSpy(&eng); { spy->clear(); eng.evaluate("throw new Error('ciao')"); @@ -1567,7 +1688,13 @@ void tst_QScriptEngineAgent::eventOrder() // unload QCOMPARE(spy->at(9).type, ScriptEngineEvent::ScriptUnload); } + delete spy; +} +void tst_QScriptEngineAgent::eventOrder_throwAndCatch() +{ + QScriptEngine eng; + ScriptEngineSpy *spy = new ScriptEngineSpy(&eng); { spy->clear(); eng.evaluate("try { throw new Error('ciao') } catch (e) { void(e); }"); @@ -1601,7 +1728,13 @@ void tst_QScriptEngineAgent::eventOrder() // unload QCOMPARE(spy->at(11).type, ScriptEngineEvent::ScriptUnload); } + delete spy; +} +void tst_QScriptEngineAgent::eventOrder_functions() +{ + QScriptEngine eng; + ScriptEngineSpy *spy = new ScriptEngineSpy(&eng); { spy->clear(); eng.evaluate("function foo(arg) { return bar(arg); }"); @@ -1655,6 +1788,7 @@ void tst_QScriptEngineAgent::eventOrder() // redefine bar() eng.evaluate("function bar(arg) { throw new Error(arg); }"); + eng.collectGarbage(); QCOMPARE(spy->count(), 25); QCOMPARE(spy->at(21).type, ScriptEngineEvent::ScriptLoad); QCOMPARE(spy->at(22).type, ScriptEngineEvent::FunctionEntry); @@ -1663,7 +1797,47 @@ void tst_QScriptEngineAgent::eventOrder() QCOMPARE(spy->at(24).scriptId, spy->at(3).scriptId); eng.evaluate("foo('ciao')"); - QCOMPARE(spy->count(), 45); + + +//////////////////////////////////////////////////////////////////////////////////////////// +/* QList<ScriptEngineEvent::Type> supposed; + supposed << ScriptEngineEvent::ScriptLoad; + supposed << ScriptEngineEvent::FunctionEntry; + supposed << ScriptEngineEvent::PositionChange; + supposed << ScriptEngineEvent::ContextPush; + supposed << ScriptEngineEvent::FunctionEntry; + supposed << ScriptEngineEvent::PositionChange; + supposed << ScriptEngineEvent::ContextPush; + supposed << ScriptEngineEvent::FunctionEntry; + supposed << ScriptEngineEvent::PositionChange; + supposed << ScriptEngineEvent::ContextPush; + supposed << ScriptEngineEvent::FunctionEntry; + supposed << ScriptEngineEvent::FunctionExit; + supposed << ScriptEngineEvent::ContextPop; + supposed << ScriptEngineEvent::ExceptionThrow; + supposed << ScriptEngineEvent::FunctionExit; + supposed << ScriptEngineEvent::ContextPop; + supposed << ScriptEngineEvent::FunctionExit; + supposed << ScriptEngineEvent::ContextPop; + supposed << ScriptEngineEvent::FunctionExit; + supposed << ScriptEngineEvent::ScriptUnload; + + + + for (int j=25;j<std::max(spy->count(),supposed.count()+25);j++) { + QString deb = "j: "+QString::number(j); + if (j<spy->count()) + deb+=" recived type:"+QString::number(spy->at(j).type); + else + deb+=" recived type: ---"; + if (j<supposed.count()+25) + deb+=" supposed type:"+QString::number(supposed[j-25]); + else + deb+=" supposed type: ---"; + qDebug()<<deb; + } +*//////////////////////////////////////////////////////////////////////////////////////////// + //QCOMPARE(spy->count(), 45); // load QCOMPARE(spy->at(25).type, ScriptEngineEvent::ScriptLoad); @@ -1721,7 +1895,13 @@ void tst_QScriptEngineAgent::eventOrder() QCOMPARE(spy->at(44).type, ScriptEngineEvent::ScriptUnload); QCOMPARE(spy->at(44).scriptId, spy->at(25).scriptId); } + delete spy; +} +void tst_QScriptEngineAgent::eventOrder_throwCatchFinally() +{ + QScriptEngine eng; + ScriptEngineSpy *spy = new ScriptEngineSpy(&eng); { spy->clear(); eng.evaluate("try { throw 1; } catch(e) { i = e; } finally { i = 2; }"); @@ -1746,11 +1926,17 @@ void tst_QScriptEngineAgent::eventOrder() // unload QCOMPARE(spy->at(8).type, ScriptEngineEvent::ScriptUnload); } + delete spy; +} +void tst_QScriptEngineAgent::eventOrder_signalsHandling() +{ + QScriptEngine eng; + ScriptEngineSpy *spy = new ScriptEngineSpy(&eng); // signal handling { spy->clear(); - QScriptValue fun = eng.evaluate("function(arg) { throw Error(arg); }"); + QScriptValue fun = eng.evaluate("(function(arg) { throw Error(arg); })"); QVERIFY(fun.isFunction()); QCOMPARE(spy->count(), 4); QCOMPARE(spy->at(0).type, ScriptEngineEvent::ScriptLoad); @@ -1769,7 +1955,7 @@ void tst_QScriptEngineAgent::eventOrder() // anonymous function entry QCOMPARE(spy->at(5).type, ScriptEngineEvent::FunctionEntry); QCOMPARE(spy->at(5).scriptId, spy->at(0).scriptId); - // throw + // throw statement QCOMPARE(spy->at(6).type, ScriptEngineEvent::PositionChange); QCOMPARE(spy->at(6).scriptId, spy->at(0).scriptId); // new context @@ -1794,6 +1980,7 @@ void tst_QScriptEngineAgent::eventOrder() // restore context QCOMPARE(spy->at(13).type, ScriptEngineEvent::ContextPop); } + delete spy; } class DoubleAgent : public ScriptEngineSpy @@ -1818,32 +2005,45 @@ void tst_QScriptEngineAgent::recursiveObserve() eng.evaluate("3 + 4", "foo.qs", 123); QCOMPARE(spy->count(), 10); - // load "3 + 4" - QCOMPARE(spy->at(0).type, ScriptEngineEvent::ScriptLoad); + + int i = 0; + // load "3 + 4" + QCOMPARE(spy->at(i).type, ScriptEngineEvent::ScriptLoad); + i++; // evaluate() entry - QCOMPARE(spy->at(1).type, ScriptEngineEvent::FunctionEntry); + QCOMPARE(spy->at(i).type, ScriptEngineEvent::FunctionEntry); + i++; // load "1 + 2" - QCOMPARE(spy->at(2).type, ScriptEngineEvent::ScriptLoad); + QCOMPARE(spy->at(i).type, ScriptEngineEvent::ScriptLoad); + i++; // evaluate() entry - QCOMPARE(spy->at(3).type, ScriptEngineEvent::FunctionEntry); + QCOMPARE(spy->at(i).type, ScriptEngineEvent::FunctionEntry); + i++; // 1 + 2 - QCOMPARE(spy->at(4).type, ScriptEngineEvent::PositionChange); - QCOMPARE(spy->at(4).scriptId, spy->at(2).scriptId); + QCOMPARE(spy->at(i).type, ScriptEngineEvent::PositionChange); + QCOMPARE(spy->at(i).scriptId, spy->at(2).scriptId); + i++; // evaluate() exit - QCOMPARE(spy->at(5).type, ScriptEngineEvent::FunctionExit); + QCOMPARE(spy->at(i).type, ScriptEngineEvent::FunctionExit); + i++; // unload "1 + 2" - QCOMPARE(spy->at(6).type, ScriptEngineEvent::ScriptUnload); - QCOMPARE(spy->at(6).scriptId, spy->at(2).scriptId); + QCOMPARE(spy->at(i).type, ScriptEngineEvent::ScriptUnload); + QCOMPARE(spy->at(i).scriptId, spy->at(2).scriptId); + i++; // 3 + 4 - QCOMPARE(spy->at(7).type, ScriptEngineEvent::PositionChange); - QCOMPARE(spy->at(7).scriptId, spy->at(0).scriptId); + QCOMPARE(spy->at(i).type, ScriptEngineEvent::PositionChange); + QCOMPARE(spy->at(i).scriptId, spy->at(0).scriptId); + i++; // evaluate() exit - QCOMPARE(spy->at(8).type, ScriptEngineEvent::FunctionExit); + QCOMPARE(spy->at(i).type, ScriptEngineEvent::FunctionExit); + i++; // unload "3 + 4" - QCOMPARE(spy->at(9).type, ScriptEngineEvent::ScriptUnload); - QCOMPARE(spy->at(9).scriptId, spy->at(0).scriptId); + QCOMPARE(spy->at(i).type, ScriptEngineEvent::ScriptUnload); + QCOMPARE(spy->at(i).scriptId, spy->at(0).scriptId); } + +/** When second agent is attached to Engine the first one should be deatached */ void tst_QScriptEngineAgent::multipleAgents() { QScriptEngine eng; @@ -1866,31 +2066,56 @@ void tst_QScriptEngineAgent::multipleAgents() void tst_QScriptEngineAgent::syntaxError() { + /* This test was changed. Old backend didn't generate events in exception objects creation time + JSC does */ QScriptEngine eng; ScriptEngineSpy *spy = new ScriptEngineSpy(&eng); { + int i = 0; spy->clear(); eng.evaluate("{"); - QCOMPARE(spy->count(), 5); - - QCOMPARE(spy->at(0).type, ScriptEngineEvent::ScriptLoad); - QVERIFY(spy->at(0).scriptId != -1); - QCOMPARE(spy->at(1).type, ScriptEngineEvent::FunctionEntry); - QCOMPARE(spy->at(1).scriptId, spy->at(0).scriptId); - QCOMPARE(spy->at(2).type, ScriptEngineEvent::ExceptionThrow); - QCOMPARE(spy->at(2).scriptId, spy->at(0).scriptId); - QVERIFY(!spy->at(2).hasExceptionHandler); - QVERIFY(spy->at(2).value.isError()); - QCOMPARE(spy->at(2).value.toString(), QString("SyntaxError: Expected `}'")); - QCOMPARE(spy->at(2).scriptId, spy->at(0).scriptId); - QCOMPARE(spy->at(3).type, ScriptEngineEvent::FunctionExit); - QCOMPARE(spy->at(3).scriptId, spy->at(0).scriptId); - QCOMPARE(spy->at(4).type, ScriptEngineEvent::ScriptUnload); - QCOMPARE(spy->at(4).scriptId, spy->at(0).scriptId); + + //QCOMPARE(spy->count(), 9); + + QCOMPARE(spy->at(i).type, ScriptEngineEvent::ScriptLoad); + QVERIFY(spy->at(i).scriptId != -1); + i = 1; + QCOMPARE(spy->at(i).type, ScriptEngineEvent::FunctionEntry); + QCOMPARE(spy->at(i).scriptId, spy->at(0).scriptId); + + //create exception + + i = 2; + QCOMPARE(spy->at(i).type, ScriptEngineEvent::ContextPush); + QVERIFY(spy->at(i).scriptId == -1); + i = 3; + QCOMPARE(spy->at(i).type, ScriptEngineEvent::FunctionEntry); + QVERIFY(spy->at(i).scriptId == -1); + i = 4; + QCOMPARE(spy->at(i).type, ScriptEngineEvent::FunctionExit); + QVERIFY(spy->at(i).scriptId == -1); + i = 5; + QCOMPARE(spy->at(i).type, ScriptEngineEvent::ContextPop); + QVERIFY(spy->at(i).scriptId == -1); + i = 6; + QCOMPARE(spy->at(i).type, ScriptEngineEvent::ExceptionThrow); + QCOMPARE(spy->at(i).scriptId, spy->at(0).scriptId); + QVERIFY(!spy->at(i).hasExceptionHandler); + QVERIFY(spy->at(i).value.isError()); + QEXPECT_FAIL("","There are other messages in JSC",Continue); + QCOMPARE(spy->at(i).value.toString(), QString("SyntaxError: Expected `}'")); + QCOMPARE(spy->at(i).scriptId, spy->at(0).scriptId); + i = 7; + //exit script + QCOMPARE(spy->at(i).type, ScriptEngineEvent::FunctionExit); + QCOMPARE(spy->at(i).scriptId, spy->at(0).scriptId); + i = 8; + QCOMPARE(spy->at(i).type, ScriptEngineEvent::ScriptUnload); + QCOMPARE(spy->at(i).scriptId, spy->at(0).scriptId); } } -void tst_QScriptEngineAgent::extension() +void tst_QScriptEngineAgent::extension_invoctaion() { QScriptEngine eng; ScriptEngineSpy *spy = new ScriptEngineSpy(&eng, ~(ScriptEngineSpy::IgnoreDebuggerInvocationRequest @@ -1910,9 +2135,19 @@ void tst_QScriptEngineAgent::extension() QCOMPARE(spy->at(1).lineNumber, lineNumber); QCOMPARE(spy->at(1).columnNumber, 1); + QEXPECT_FAIL("","In JSC Eval('debugger') returns undefined",Abort); QVERIFY(ret.isString()); QCOMPARE(ret.toString(), QString::fromLatin1("extension(DebuggerInvocationRequest)")); } + delete spy; +} + +void tst_QScriptEngineAgent::extension() +{ + QScriptEngine eng; + ScriptEngineSpy *spy = new ScriptEngineSpy(&eng, ~(ScriptEngineSpy::IgnoreDebuggerInvocationRequest + | ScriptEngineSpy::IgnoreScriptLoad)); + { spy->clear(); spy->enableIgnoreFlags(ScriptEngineSpy::IgnoreDebuggerInvocationRequest); @@ -1921,9 +2156,9 @@ void tst_QScriptEngineAgent::extension() QCOMPARE(spy->count(), 1); QCOMPARE(spy->at(0).type, ScriptEngineEvent::ScriptLoad); - QVERIFY(ret.isUndefined()); } + delete spy; } QTEST_MAIN(tst_QScriptEngineAgent) |