summaryrefslogtreecommitdiffstats
path: root/tests/auto/qscriptengine
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-06-25 14:27:30 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-06-25 14:29:06 (GMT)
commit9d8f5dcb46f64ee2f5e205100b603f6d01f1381b (patch)
tree4ced780e329149d1cb50d7fa2dea604beab31330 /tests/auto/qscriptengine
parente6647776249e0e3ac9bac38d72965aa87b607859 (diff)
downloadQt-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
Diffstat (limited to 'tests/auto/qscriptengine')
-rw-r--r--tests/auto/qscriptengine/tst_qscriptengine.cpp28
1 files changed, 28 insertions, 0 deletions
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;