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/qscriptengine/tst_qscriptengine.cpp | |
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/qscriptengine/tst_qscriptengine.cpp')
-rw-r--r-- | tests/auto/qscriptengine/tst_qscriptengine.cpp | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index 062cbfa..804534f 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -53,6 +53,7 @@ Q_DECLARE_METATYPE(QList<int>) Q_DECLARE_METATYPE(QObjectList) +Q_DECLARE_METATYPE(QScriptProgram) //TESTED_CLASS= //TESTED_FILES= @@ -4291,6 +4292,13 @@ void tst_QScriptEngine::nativeFunctionScopes() } } +static QScriptValue createProgram(QScriptContext *ctx, QScriptEngine *eng) +{ + QString code = ctx->argument(0).toString(); + QScriptProgram result(code); + return qScriptValueFromValue(eng, result); +} + void tst_QScriptEngine::evaluateProgram() { QScriptEngine eng; @@ -4303,13 +4311,27 @@ void tst_QScriptEngine::evaluateProgram() QVERIFY(!program.isNull()); QCOMPARE(program.sourceCode(), code); QCOMPARE(program.fileName(), fileName); - QCOMPARE(program.lineNumber(), lineNumber); + QCOMPARE(program.firstLineNumber(), lineNumber); QScriptValue expected = eng.evaluate(code); for (int x = 0; x < 10; ++x) { QScriptValue ret = eng.evaluate(program); QVERIFY(ret.equals(expected)); } + + // operator= + QScriptProgram sameProgram = program; + QVERIFY(sameProgram == program); + QVERIFY(eng.evaluate(sameProgram).equals(expected)); + + // copy constructor + QScriptProgram sameProgram2(program); + QVERIFY(sameProgram2 == program); + QVERIFY(eng.evaluate(sameProgram2).equals(expected)); + + QScriptProgram differentProgram("2 + 3"); + QVERIFY(differentProgram != program); + QVERIFY(!eng.evaluate(differentProgram).equals(expected)); } // Program that accesses variable in the scope @@ -4371,6 +4393,27 @@ void tst_QScriptEngine::evaluateProgram() } } + // Program created in a function call, then executed later + { + QScriptValue fun = eng.newFunction(createProgram); + QScriptProgram program = qscriptvalue_cast<QScriptProgram>( + fun.call(QScriptValue(), QScriptValueList() << "a + 1")); + QVERIFY(!program.isNull()); + eng.globalObject().setProperty("a", QScriptValue()); + { + QScriptValue ret = eng.evaluate(program); + QVERIFY(ret.isError()); + QCOMPARE(ret.toString(), QString::fromLatin1("ReferenceError: Can't find variable: a")); + } + eng.globalObject().setProperty("a", 122); + { + QScriptValue ret = eng.evaluate(program); + QVERIFY(!ret.isError()); + QVERIFY(ret.isNumber()); + QCOMPARE(ret.toInt32(), 123); + } + } + // Same program run in different engines { QString code("1 + 2"); |