diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-06-25 14:27:30 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-06-25 14:29:06 (GMT) |
commit | 9d8f5dcb46f64ee2f5e205100b603f6d01f1381b (patch) | |
tree | 4ced780e329149d1cb50d7fa2dea604beab31330 | |
parent | e6647776249e0e3ac9bac38d72965aa87b607859 (diff) | |
download | Qt-9d8f5dcb46f64ee2f5e205100b603f6d01f1381b.zip Qt-9d8f5dcb46f64ee2f5e205100b603f6d01f1381b.tar.gz Qt-9d8f5dcb46f64ee2f5e205100b603f6d01f1381b.tar.bz2 |
have the QtScript print() function use qDebug()
Makes it work with custom message handlers (qInstallMsgHandler()).
Task-number: 233005
-rw-r--r-- | src/script/qscriptecmaglobal.cpp | 3 | ||||
-rw-r--r-- | tests/auto/qscriptengine/tst_qscriptengine.cpp | 28 |
2 files changed, 29 insertions, 2 deletions
diff --git a/src/script/qscriptecmaglobal.cpp b/src/script/qscriptecmaglobal.cpp index a7cb115..b756a27 100644 --- a/src/script/qscriptecmaglobal.cpp +++ b/src/script/qscriptecmaglobal.cpp @@ -305,8 +305,7 @@ public: } if (context->state() != QScriptContext::ExceptionState) { - QTextStream qout(stdout, QIODevice::WriteOnly); - qout << result << endl; + qDebug(qPrintable(result)); context->setReturnValue(eng->undefinedValue()); } #ifndef Q_SCRIPT_NO_EVENT_NOTIFY diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index b63236e..68df392 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -101,6 +101,7 @@ private slots: void automaticSemicolonInsertion(); void abortEvaluation(); void isEvaluating(); + void printFunctionWithCustomHandler(); void printThrowsException(); void errorConstructors(); void argumentsProperty(); @@ -2473,6 +2474,33 @@ void tst_QScriptEngine::isEvaluating() } } +static QtMsgType theMessageType; +static QString theMessage; + +static void myMsgHandler(QtMsgType type, const char *msg) +{ + theMessageType = type; + theMessage = QString::fromLatin1(msg); +} + +void tst_QScriptEngine::printFunctionWithCustomHandler() +{ + QScriptEngine eng; + QtMsgHandler oldHandler = qInstallMsgHandler(myMsgHandler); + QVERIFY(eng.globalObject().property("print").isFunction()); + theMessageType = QtSystemMsg; + QVERIFY(theMessage.isEmpty()); + QVERIFY(eng.evaluate("print('test')").isUndefined()); + QCOMPARE(theMessageType, QtDebugMsg); + QCOMPARE(theMessage, QString::fromLatin1("test")); + theMessageType = QtSystemMsg; + theMessage.clear(); + QVERIFY(eng.evaluate("print(3, true, 'little pigs')").isUndefined()); + QCOMPARE(theMessageType, QtDebugMsg); + QCOMPARE(theMessage, QString::fromLatin1("3 true little pigs")); + qInstallMsgHandler(oldHandler); +} + void tst_QScriptEngine::printThrowsException() { QScriptEngine eng; |