diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-06-25 16:27:30 +0200 |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-06-25 16:29:06 +0200 |
commit | 9d8f5dcb46f64ee2f5e205100b603f6d01f1381b (patch) | |
tree | 4ced780e329149d1cb50d7fa2dea604beab31330 /tests/auto/qscriptengine | |
parent | e6647776249e0e3ac9bac38d72965aa87b607859 (diff) | |
download | qt4-tools-9d8f5dcb46f64ee2f5e205100b603f6d01f1381b.tar.gz |
have the QtScript print() function use qDebug()
Makes it work with custom message handlers (qInstallMsgHandler()).
Task-number: 233005
Diffstat (limited to 'tests/auto/qscriptengine')
-rw-r--r-- | tests/auto/qscriptengine/tst_qscriptengine.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index b63236e277..68df392677 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; |