diff options
author | Keith Isdale <keith.isdale@nokia.com> | 2010-07-23 10:53:35 +1000 |
---|---|---|
committer | Keith Isdale <keith.isdale@nokia.com> | 2010-07-23 10:53:35 +1000 |
commit | 9e03da7e9404752219ba96a88576a0ea01d5a675 (patch) | |
tree | bb8cbb43e78e25bfa45a3ba8c2c39400f35bc959 /interpreter/qscriptsystemtest.cpp | |
parent | 95e90557a18e5dc1cb3cd5f9f91554e68bbbc6a5 (diff) | |
parent | dff9fdff49679aaf332ec0bbc219104c2e2eb73d (diff) |
Merge branch 'master' of git://git-nokia.trolltech.com.au/qtsoftware/research/qtuitest
Diffstat (limited to 'interpreter/qscriptsystemtest.cpp')
-rw-r--r-- | interpreter/qscriptsystemtest.cpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/interpreter/qscriptsystemtest.cpp b/interpreter/qscriptsystemtest.cpp index 93b0725..2dbe531 100644 --- a/interpreter/qscriptsystemtest.cpp +++ b/interpreter/qscriptsystemtest.cpp @@ -489,6 +489,89 @@ bool QScriptSystemTest::setQueryError( const QString &errString ) return ret; } +#ifdef QTCREATOR_QTEST +int QScriptSystemTest::runTest(const QString &fname, const QStringList ¶meters, + const QStringList &environment) +{ + m_env = environment; + qDebug() << "Running " << fname; + filename = fname; + + QFile file(filename); + if (!file.open(QFile::ReadOnly)) { + qDebug() << "Can't open " << filename; + return -1; + } + + QTextStream stream(&file); + QString script = stream.readAll(); + + ScriptPreprocessor().preprocess(script); + + setupEnums(&m_engine); + + // include() imports scripts directly into the parent script. + m_engine.globalObject().setProperty + ("include", m_engine.newFunction(includeFunction, 1)); + m_engine.globalObject().setProperty + ("setFlags", m_engine.newFunction(setFlags, 3)); + + + m_engine.globalObject().setProperty("_dateToString", m_engine.newFunction(dateToString)); + m_engine.evaluate("_old_date_toString = Date.prototype.toString;" + "Date.prototype.toString = function() {" + " if (arguments[0] == undefined)" + " return _old_date_toString.apply(this, arguments);" + " return _dateToString.apply(this, arguments);" + "}"); + + m_engine.globalObject().setProperty("ParentTestObject", m_engine.newQObject(this)); + m_engine.globalObject().setProperty("ParentTestMetaObject", m_engine.newQMetaObject(metaObject())); + + loadBuiltins(m_engine); + importIntoGlobalNamespace(m_engine, "ParentTestObject"); + + // Allow shebangs without giving syntax errors. + if (script.startsWith("#!")) script.prepend("//"); + script.prepend("with(ParentTestMetaObject){"); + script.append("\n}"); + + QtScriptTest tc(filename, script, &m_engine); + testObject = &tc; + + qScriptRegisterMetaType(&m_engine, variantToScriptValue, variantFromScriptValue); + qScriptRegisterSequenceMetaType<QList<qint64> >(&m_engine); + + // Only set up the test data path if not explicitly set by user + if (!QCoreApplication::arguments().contains("-data")) { + setupTestDataPath(qPrintable(filename)); + } + + enableQueryWarnings(false); + + // If we get here, the syntax of the script is definitely OK + // (a syntax error causes a qFatal in the QtScriptTest ctor). + if (m_checkOnly) + return 0; + + // If an IDE is connected, set the agent to enable script debugging + if (testIDE() && testIDE()->isConnected()) { + m_engine.setAgent(m_agent); + } + + int retval = QTest::qExec(&tc, parameters); + + testObject = 0; + + // After a full test run, QTestLib sometimes returns 0 or sometimes returns + // the number of test failures, depending on how it was compiled. In both + // cases, a negative number denotes an error. + // We don't want test failures to affect the exit code. + return (retval < 0) ? retval : 0; +} +#endif + +#ifndef QTCREATOR_QTEST int QScriptSystemTest::runTest(int argc, char *argv[]) { if (argc > 1) filename = argv[1]; @@ -574,6 +657,7 @@ int QScriptSystemTest::runTest(int argc, char *argv[]) // We don't want test failures to affect the exit code. return (retval < 0) ? retval : 0; } +#endif /*! \internal @@ -630,6 +714,7 @@ QVariantMap QScriptSystemTest::sendRaw(const QString& event, const QScriptValue& return ret; } +#ifndef QTCREATOR_QTEST /*! \internal Print any special usage information which should be shown when test is launched @@ -644,6 +729,7 @@ void QScriptSystemTest::printUsage(int argc, char *argv[]) const " contains any syntax errors.\n" ); } +#endif /*! \internal |