summaryrefslogtreecommitdiffstats
path: root/tests/auto/qscriptengine
diff options
context:
space:
mode:
authorRohan McGovern <rohan.mcgovern@nokia.com>2010-10-04 04:21:32 (GMT)
committerRohan McGovern <rohan.mcgovern@nokia.com>2010-10-04 04:21:32 (GMT)
commit5171bb1613ecc537f3f0d0962532e3ee059b8870 (patch)
tree02d0e565d8fc397573a2d35845c11ba74b912c8d /tests/auto/qscriptengine
parentc372896c5293633d75674a320a9b715a0501a42d (diff)
parent33b76a659b2f44fa7038e375bbfb4cfd449ae617 (diff)
downloadQt-5171bb1613ecc537f3f0d0962532e3ee059b8870.zip
Qt-5171bb1613ecc537f3f0d0962532e3ee059b8870.tar.gz
Qt-5171bb1613ecc537f3f0d0962532e3ee059b8870.tar.bz2
Merge remote branch 'origin/4.7' into master-from-4.7
Conflicts: doc/src/snippets/code/doc_src_qmake-manual.qdoc src/corelib/arch/symbian/arch.pri src/declarative/graphicsitems/qdeclarativeflickable.cpp src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h tests/auto/qfontmetrics/tst_qfontmetrics.cpp
Diffstat (limited to 'tests/auto/qscriptengine')
-rw-r--r--tests/auto/qscriptengine/tst_qscriptengine.cpp60
1 files changed, 57 insertions, 3 deletions
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp
index b035492..7133a6c 100644
--- a/tests/auto/qscriptengine/tst_qscriptengine.cpp
+++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp
@@ -134,6 +134,7 @@ private slots:
void numberParsing();
void automaticSemicolonInsertion();
void abortEvaluation();
+ void abortEvaluation_QTBUG9433();
void isEvaluating();
void printFunctionWithCustomHandler();
void printThrowsException();
@@ -3037,7 +3038,8 @@ public:
enum AbortionResult {
None = 0,
String = 1,
- Error = 2
+ Error = 2,
+ Number = 3
};
EventReceiver3(QScriptEngine *eng) {
@@ -3057,6 +3059,8 @@ public:
case Error:
engine->abortEvaluation(engine->currentContext()->throwError("AbortedWithError"));
break;
+ case Number:
+ engine->abortEvaluation(QScriptValue(1234));
}
}
return QObject::event(e);
@@ -3089,7 +3093,7 @@ void tst_QScriptEngine::abortEvaluation()
EventReceiver3 receiver(&eng);
eng.setProcessEventsInterval(100);
- for (int x = 0; x < 3; ++x) {
+ for (int x = 0; x < 4; ++x) {
QCoreApplication::postEvent(&receiver, new QEvent(QEvent::Type(QEvent::User+1)));
receiver.resultType = EventReceiver3::AbortionResult(x);
QScriptValue ret = eng.evaluate(QString::fromLatin1("while (1) { }"));
@@ -3098,6 +3102,11 @@ void tst_QScriptEngine::abortEvaluation()
QVERIFY(!eng.hasUncaughtException());
QVERIFY(!ret.isValid());
break;
+ case EventReceiver3::Number:
+ QVERIFY(!eng.hasUncaughtException());
+ QVERIFY(ret.isNumber());
+ QCOMPARE(ret.toInt32(), 1234);
+ break;
case EventReceiver3::String:
QVERIFY(!eng.hasUncaughtException());
QVERIFY(ret.isString());
@@ -3112,7 +3121,7 @@ void tst_QScriptEngine::abortEvaluation()
}
// scripts cannot intercept the abortion with try/catch
- for (int y = 0; y < 3; ++y) {
+ for (int y = 0; y < 4; ++y) {
QCoreApplication::postEvent(&receiver, new QEvent(QEvent::Type(QEvent::User+1)));
receiver.resultType = EventReceiver3::AbortionResult(y);
QScriptValue ret = eng.evaluate(QString::fromLatin1(
@@ -3128,6 +3137,11 @@ void tst_QScriptEngine::abortEvaluation()
QVERIFY(!eng.hasUncaughtException());
QVERIFY(!ret.isValid());
break;
+ case EventReceiver3::Number:
+ QVERIFY(!eng.hasUncaughtException());
+ QVERIFY(ret.isNumber());
+ QCOMPARE(ret.toInt32(), 1234);
+ break;
case EventReceiver3::String:
QVERIFY(!eng.hasUncaughtException());
QVERIFY(ret.isString());
@@ -3148,6 +3162,46 @@ void tst_QScriptEngine::abortEvaluation()
}
}
+class ThreadedEngine : public QThread {
+ Q_OBJECT;
+
+private:
+ QScriptEngine* m_engine;
+protected:
+ void run() {
+ m_engine = new QScriptEngine();
+ m_engine->setGlobalObject(m_engine->newQObject(this));
+ m_engine->evaluate("while(1) { sleep(); }");
+ delete m_engine;
+ }
+
+public slots:
+ void sleep()
+ {
+ QTest::qSleep(25);
+ m_engine->abortEvaluation();
+ }
+};
+
+void tst_QScriptEngine::abortEvaluation_QTBUG9433()
+{
+ ThreadedEngine engine;
+ engine.start();
+ QVERIFY(engine.isRunning());
+ QTest::qSleep(50);
+ for (uint i = 0; i < 50; ++i) { // up to ~2500 ms
+ if (engine.isFinished())
+ return;
+ QTest::qSleep(50);
+ }
+ if (!engine.isFinished()) {
+ engine.terminate();
+ engine.wait(7000);
+ QFAIL("abortEvaluation doesn't work");
+ }
+
+}
+
static QScriptValue myFunctionReturningIsEvaluating(QScriptContext *, QScriptEngine *eng)
{
return QScriptValue(eng, eng->isEvaluating());