summaryrefslogtreecommitdiffstats
path: root/tests/auto/qscriptcontext
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2010-11-04 13:10:53 +0100
committerKent Hansen <kent.hansen@nokia.com>2010-11-08 15:44:45 +0100
commitd48a324d6670b14348d546db6a739ee138dab1e2 (patch)
tree865a0a552cf890d3eee7955634825ca33d0ca518 /tests/auto/qscriptcontext
parent7b79a508bb16fd104ddf7d9a485d566ee2e051ba (diff)
Add autotest that checks return value of QScriptContext::throwXXX()
The documentation says that they should return the error/value that was thrown. When throwError() is called from a native function call, the return value of the function will be ignored, so we need a test that calls throwError() outside of a function context. Reviewed-by: Jedrzej Nowacki
Diffstat (limited to 'tests/auto/qscriptcontext')
-rw-r--r--tests/auto/qscriptcontext/tst_qscriptcontext.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
index cbcd16a194..5e7ede848d 100644
--- a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
+++ b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
@@ -50,6 +50,7 @@
//TESTED_FILES=
Q_DECLARE_METATYPE(QScriptValueList)
+Q_DECLARE_METATYPE(QScriptContext::Error)
QT_BEGIN_NAMESPACE
extern bool qt_script_isJITEnabled();
@@ -91,6 +92,10 @@ private slots:
void qobjectAsActivationObject();
void parentContextCallee_QT2270();
void popNativeContextScope();
+ void throwErrorInGlobalContext();
+ void throwErrorWithTypeInGlobalContext_data();
+ void throwErrorWithTypeInGlobalContext();
+ void throwValueInGlobalContext();
};
tst_QScriptContext::tst_QScriptContext()
@@ -1323,5 +1328,49 @@ void tst_QScriptContext::parentContextCallee_QT2270()
QVERIFY(callee.equals(fun));
}
+void tst_QScriptContext::throwErrorInGlobalContext()
+{
+ QScriptEngine eng;
+ QScriptValue ret = eng.currentContext()->throwError("foo");
+ QVERIFY(ret.isError());
+ QVERIFY(eng.hasUncaughtException());
+ QVERIFY(eng.uncaughtException().strictlyEquals(ret));
+ QCOMPARE(ret.toString(), QString::fromLatin1("Error: foo"));
+}
+
+void tst_QScriptContext::throwErrorWithTypeInGlobalContext_data()
+{
+ QTest::addColumn<QScriptContext::Error>("error");
+ QTest::addColumn<QString>("stringRepresentation");
+ QTest::newRow("ReferenceError") << QScriptContext::ReferenceError << QString::fromLatin1("ReferenceError: foo");
+ QTest::newRow("SyntaxError") << QScriptContext::SyntaxError << QString::fromLatin1("SyntaxError: foo");
+ QTest::newRow("TypeError") << QScriptContext::TypeError << QString::fromLatin1("TypeError: foo");
+ QTest::newRow("RangeError") << QScriptContext::RangeError << QString::fromLatin1("RangeError: foo");
+ QTest::newRow("URIError") << QScriptContext::URIError << QString::fromLatin1("URIError: foo");
+ QTest::newRow("UnknownError") << QScriptContext::UnknownError << QString::fromLatin1("Error: foo");
+}
+
+void tst_QScriptContext::throwErrorWithTypeInGlobalContext()
+{
+ QFETCH(QScriptContext::Error, error);
+ QFETCH(QString, stringRepresentation);
+ QScriptEngine eng;
+ QScriptValue ret = eng.currentContext()->throwError(error, "foo");
+ QVERIFY(ret.isError());
+ QVERIFY(eng.hasUncaughtException());
+ QVERIFY(eng.uncaughtException().strictlyEquals(ret));
+ QCOMPARE(ret.toString(), stringRepresentation);
+}
+
+void tst_QScriptContext::throwValueInGlobalContext()
+{
+ QScriptEngine eng;
+ QScriptValue val(&eng, 123);
+ QScriptValue ret = eng.currentContext()->throwValue(val);
+ QVERIFY(ret.strictlyEquals(val));
+ QVERIFY(eng.hasUncaughtException());
+ QVERIFY(eng.uncaughtException().strictlyEquals(val));
+}
+
QTEST_MAIN(tst_QScriptContext)
#include "tst_qscriptcontext.moc"