summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorkh1 <karsten.heimrich@digia.com>2014-06-02 15:14:12 +0200
committerKarsten Heimrich <karsten.heimrich@digia.com>2014-06-03 10:51:51 +0200
commit8addcf763bc0644de1f3548a2a65876aed65a7c9 (patch)
tree12f2735f9e757d415f5200000de17b3231b9c053 /tests
parent3aaca15ef8a8dd13ba877821a3683ba86241be9b (diff)
Replace script with js engine.
Change-Id: Ic9c88e27dca1e936ba09a3776df3df7ec166c606 Reviewed-by: Tim Jenssen <tim.jenssen@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/installer/componentmodel/componentmodel.pro2
-rw-r--r--tests/auto/installer/consumeoutputoperationtest/consumeoutputoperationtest.pro2
-rw-r--r--tests/auto/installer/fakestopprocessforupdateoperation/fakestopprocessforupdateoperation.pro2
-rw-r--r--tests/auto/installer/messageboxhandler/messageboxhandler.pro2
-rw-r--r--tests/auto/installer/messageboxhandler/tst_messageboxhandler.cpp44
-rw-r--r--tests/auto/installer/packagemanagercore/packagemanagercore.pro2
-rw-r--r--tests/auto/installer/scriptengine/scriptengine.pro2
-rw-r--r--tests/auto/installer/scriptengine/tst_scriptengine.cpp124
8 files changed, 76 insertions, 104 deletions
diff --git a/tests/auto/installer/componentmodel/componentmodel.pro b/tests/auto/installer/componentmodel/componentmodel.pro
index 7e18ff1ba..431969578 100644
--- a/tests/auto/installer/componentmodel/componentmodel.pro
+++ b/tests/auto/installer/componentmodel/componentmodel.pro
@@ -1,7 +1,7 @@
include(../../qttest.pri)
QT -= gui
-QT += network xml script
+QT += network xml qml
SOURCES += tst_componentmodel.cpp
diff --git a/tests/auto/installer/consumeoutputoperationtest/consumeoutputoperationtest.pro b/tests/auto/installer/consumeoutputoperationtest/consumeoutputoperationtest.pro
index a6fbc60f9..3eacd46ac 100644
--- a/tests/auto/installer/consumeoutputoperationtest/consumeoutputoperationtest.pro
+++ b/tests/auto/installer/consumeoutputoperationtest/consumeoutputoperationtest.pro
@@ -1,7 +1,7 @@
include(../../qttest.pri)
QT -= gui
-QT += testlib
+QT += testlib qml
SOURCES = tst_consumeoutputoperationtest.cpp
diff --git a/tests/auto/installer/fakestopprocessforupdateoperation/fakestopprocessforupdateoperation.pro b/tests/auto/installer/fakestopprocessforupdateoperation/fakestopprocessforupdateoperation.pro
index 871b668b2..0c1e6bdfa 100644
--- a/tests/auto/installer/fakestopprocessforupdateoperation/fakestopprocessforupdateoperation.pro
+++ b/tests/auto/installer/fakestopprocessforupdateoperation/fakestopprocessforupdateoperation.pro
@@ -1,6 +1,6 @@
include(../../qttest.pri)
QT -= gui
-QT += network script
+QT += network qml
SOURCES += tst_fakestopprocessforupdateoperation.cpp
diff --git a/tests/auto/installer/messageboxhandler/messageboxhandler.pro b/tests/auto/installer/messageboxhandler/messageboxhandler.pro
index 619668315..c63b2e35b 100644
--- a/tests/auto/installer/messageboxhandler/messageboxhandler.pro
+++ b/tests/auto/installer/messageboxhandler/messageboxhandler.pro
@@ -1,5 +1,5 @@
include(../../qttest.pri)
-QT += script widgets
+QT += qml widgets
SOURCES += tst_messageboxhandler.cpp
diff --git a/tests/auto/installer/messageboxhandler/tst_messageboxhandler.cpp b/tests/auto/installer/messageboxhandler/tst_messageboxhandler.cpp
index 604b8e0a0..75df29949 100644
--- a/tests/auto/installer/messageboxhandler/tst_messageboxhandler.cpp
+++ b/tests/auto/installer/messageboxhandler/tst_messageboxhandler.cpp
@@ -5,7 +5,6 @@
#include <QTest>
#include <QMetaEnum>
-#include <QScriptEngine>
#include <QDebug>
#include <stdlib.h> /* srand, rand */
@@ -50,50 +49,42 @@ private slots:
void testScriptButtonValues()
{
PackageManagerCore core;
- ScriptEngine scriptEngine(&core);
+ ScriptEngine *scriptEngine = new ScriptEngine(&core);
QMapIterator<QMessageBox::StandardButton, QString> i(m_standardButtonValueMap);
while (i.hasNext()) {
i.next();
- QString scriptString = QString::fromLatin1("QMessageBox.%1").arg(i.value());
- QScriptValue scriptValue(scriptEngine.evaluate(scriptString));
+ const QString scriptString = QString::fromLatin1("QMessageBox.%1").arg(i.value());
+ const QJSValue scriptValue = scriptEngine->evaluate(scriptString);
+ QVERIFY2(!scriptValue.isError(), qPrintable(scriptValue.toString()));
QVERIFY2(!scriptValue.isUndefined(), qPrintable(
QString::fromLatin1("It seems that %1 is undefined.").arg(scriptString)));
-
- qint32 evaluatedValue = scriptValue.toInt32();
- QVERIFY2(!scriptEngine.hasUncaughtException(), qPrintable(
- QInstaller::uncaughtExceptionString(&scriptEngine)));
-
- QCOMPARE(static_cast<QMessageBox::StandardButton>(evaluatedValue), i.key());
+ QCOMPARE(static_cast<QMessageBox::StandardButton>(scriptValue.toInt()), i.key());
}
}
void testDefaultAction()
{
- int standardButtons = QMessageBox::NoButton;
- QList<QMessageBox::Button> orderedButtons = MessageBoxHandler::orderedButtons();
- MessageBoxHandler *messageBoxHandler = MessageBoxHandler::instance();
-
- messageBoxHandler->setDefaultAction(MessageBoxHandler::Reject);
- QString testidentifier(QLatin1String("TestError"));
- QString testTitle(QLatin1String("A test error"));
- QString testMessage(QLatin1String("This is a test error message."));
+ const char ignoreMessage[] = "\"created critical message box TestError: 'A test error', "
+ "This is a test error message.\" ";
+ srand(time(0)); /* initialize random seed: */
- const char *ignoreMessage("\"created critical message box TestError: 'A test error', This is a test error message.\" ");
- /* initialize random seed: */
- srand(time(0));
+ int standardButtons = QMessageBox::NoButton;
+ MessageBoxHandler::instance()->setDefaultAction(MessageBoxHandler::Reject);
+ const QList<QMessageBox::Button> orderedButtons = MessageBoxHandler::orderedButtons();
do {
standardButtons += QMessageBox::FirstButton;
/* generate secret number between 1 and 10: */
- int iSecret = rand() % 10 + 1;
+ const int iSecret = rand() % 10 + 1;
// use only every 5th run to reduce the time which it takes to run this test
if (iSecret > 2)
continue;
+
QTest::ignoreMessage(QtDebugMsg, ignoreMessage);
- const QMessageBox::StandardButton returnButton = static_cast<QMessageBox::StandardButton>(
- messageBoxHandler->critical(testidentifier, testTitle, testMessage,
- static_cast<QMessageBox::StandardButton>(standardButtons)));
+ int returnButton = MessageBoxHandler::instance()->critical(QLatin1String("TestError"),
+ QLatin1String("A test error"), QLatin1String("This is a test error message."),
+ static_cast<QMessageBox::StandardButton>(standardButtons));
QMessageBox::StandardButton wantedButton = QMessageBox::NoButton;
// find the last button which is the wanted reject button in the current
@@ -104,8 +95,7 @@ private slots:
}
QVERIFY2(wantedButton != QMessageBox::NoButton, "Could not find a wantedButton.");
- QCOMPARE(returnButton, wantedButton);
-
+ QCOMPARE(static_cast<QMessageBox::StandardButton>(returnButton), wantedButton);
} while (standardButtons < m_maxStandardButtons);
}
diff --git a/tests/auto/installer/packagemanagercore/packagemanagercore.pro b/tests/auto/installer/packagemanagercore/packagemanagercore.pro
index 34c3bd6ac..6e9e387fa 100644
--- a/tests/auto/installer/packagemanagercore/packagemanagercore.pro
+++ b/tests/auto/installer/packagemanagercore/packagemanagercore.pro
@@ -1,6 +1,6 @@
include(../../qttest.pri)
-QT += script
+QT += qml
SOURCES += tst_packagemanagercore.cpp
diff --git a/tests/auto/installer/scriptengine/scriptengine.pro b/tests/auto/installer/scriptengine/scriptengine.pro
index 72bb7028e..71d8196a1 100644
--- a/tests/auto/installer/scriptengine/scriptengine.pro
+++ b/tests/auto/installer/scriptengine/scriptengine.pro
@@ -1,6 +1,6 @@
include(../../qttest.pri)
-QT += script widgets
+QT += qml widgets
SOURCES += tst_scriptengine.cpp
diff --git a/tests/auto/installer/scriptengine/tst_scriptengine.cpp b/tests/auto/installer/scriptengine/tst_scriptengine.cpp
index 5c67afd0c..cc9f7aab7 100644
--- a/tests/auto/installer/scriptengine/tst_scriptengine.cpp
+++ b/tests/auto/installer/scriptengine/tst_scriptengine.cpp
@@ -70,108 +70,99 @@ private slots:
m_scriptEngine->globalObject().setProperty(QLatin1String("emiter"),
m_scriptEngine->newQObject(&emiter));
- QScriptValue context = m_scriptEngine->loadInConext(QLatin1String("BrokenConnect"),
+ QJSValue context = m_scriptEngine->loadInContext(QLatin1String("BrokenConnect"),
":///data/broken_connect.qs");
- QVERIFY(context.isValid());
-
- if (m_scriptEngine->hasUncaughtException()) {
- QFAIL(qPrintable(QString::fromLatin1("ScriptEngine hasUncaughtException:\n %1").arg(
- uncaughtExceptionString(m_scriptEngine))));
+ if (context.isError()) {
+ QFAIL(qPrintable(QString::fromLatin1("ScriptEngine error:\n %1").arg(
+ context.toString())));
}
+ QCOMPARE(context.isError(), false);
- const QString debugMesssage(
- "create Error-Exception: \"Fatal error while evaluating a script.\n\n"
- "ReferenceError: Can't find variable: foo\n\n"
- "Backtrace:\n"
-#if QT_VERSION < 0x050000
- "\t<anonymous>()@:///data/broken_connect.qs:10\" ");
-#else
- "\treceive() at :///data/broken_connect.qs:10\n"
- "\t<global>() at -1\" ");
-#endif
- try {
- // ignore Output from script
- setExpectedScriptOutput("function receive()");
- setExpectedScriptOutput(qPrintable(debugMesssage));
- emiter.produceSignal();
- } catch (const Error &error) {
- QVERIFY2(debugMesssage.contains(error.message()), "There was some unexpected error.");
- }
+ // ignore Output from script
+ setExpectedScriptOutput("\"function receive()\"");
+
+ emiter.produceSignal();
+
+ const QJSValue value = m_scriptEngine->evaluate("");
+ QCOMPARE(value.isError(), true);
+ QCOMPARE(value.toString(), QLatin1String("ReferenceError: foo is not defined"));
}
void testScriptPrint()
{
- setExpectedScriptOutput("test");
- m_scriptEngine->evaluate("print(\"test\");");
- if (m_scriptEngine->hasUncaughtException()) {
- QFAIL(qPrintable(QString::fromLatin1("ScriptEngine hasUncaughtException:\n %1").arg(
- uncaughtExceptionString(m_scriptEngine))));
+ setExpectedScriptOutput("\"test\"");
+ const QJSValue value = m_scriptEngine->evaluate("print(\"test\");");
+ if (value.isError()) {
+ QFAIL(qPrintable(QString::fromLatin1("ScriptEngine error:\n %1").arg(
+ value.toString())));
}
}
void testExistingInstallerObject()
{
- setExpectedScriptOutput("object");
- m_scriptEngine->evaluate("print(typeof installer)");
- if (m_scriptEngine->hasUncaughtException()) {
- QFAIL(qPrintable(QString::fromLatin1("ScriptEngine hasUncaughtException:\n %1").arg(
- uncaughtExceptionString(m_scriptEngine))));
+ setExpectedScriptOutput("\"object\"");
+ const QJSValue value = m_scriptEngine->evaluate("print(typeof installer)");
+ if (value.isError()) {
+ QFAIL(qPrintable(QString::fromLatin1("ScriptEngine error:\n %1").arg(
+ value.toString())));
}
}
void testComponentByName()
{
- const QString printComponentNameScript = QString::fromLatin1("var correctComponent = "
- "installer.componentByName('%1');\nprint(correctComponent.name);").arg(m_component->name());
-
- setExpectedScriptOutput("component.test.name");
- m_scriptEngine->evaluate(printComponentNameScript);
- if (m_scriptEngine->hasUncaughtException()) {
- QFAIL(qPrintable(QString::fromLatin1("ScriptEngine hasUncaughtException:\n %1").arg(
- uncaughtExceptionString(m_scriptEngine))));
+ const QString script = QString::fromLatin1("var component = installer.componentByName('%1');"
+ "\n"
+ "print(component.name);").arg(m_component->name());
+
+ setExpectedScriptOutput("\"component.test.name\"");
+ const QJSValue value = m_scriptEngine->evaluate(script);
+ if (value.isError()) {
+ QFAIL(qPrintable(QString::fromLatin1("ScriptEngine error:\n %1").arg(
+ value.toString())));
}
}
void testComponentByWrongName()
{
- const QString printComponentNameScript = QString::fromLatin1( "var brokenComponent = "
- "installer.componentByName('%1');\nprint(brokenComponent.name);").arg("MyNotExistingComponentName");
+ const QString script = QString::fromLatin1( "var component = installer.componentByName('%1');"
+ "\n"
+ "print(brokenComponent.name);").arg("NotExistingComponentName");
- m_scriptEngine->evaluate(printComponentNameScript);
- QVERIFY(m_scriptEngine->hasUncaughtException());
+ const QJSValue value = m_scriptEngine->evaluate(script);
+ QCOMPARE(value.isError(), true);
}
void loadSimpleComponentScript()
{
try {
// ignore retranslateUi which is called by loadComponentScript
- setExpectedScriptOutput("Component constructor - OK");
- setExpectedScriptOutput("retranslateUi - OK");
+ setExpectedScriptOutput("\"Component constructor - OK\"");
+ setExpectedScriptOutput("\"retranslateUi - OK\"");
m_component->loadComponentScript(":///data/component1.qs");
- setExpectedScriptOutput("retranslateUi - OK");
+ setExpectedScriptOutput("\"retranslateUi - OK\"");
m_component->languageChanged();
- setExpectedScriptOutput("createOperationsForPath - OK");
+ setExpectedScriptOutput("\"createOperationsForPath - OK\"");
m_component->createOperationsForPath(":///data/");
- setExpectedScriptOutput("createOperationsForArchive - OK");
+ setExpectedScriptOutput("\"createOperationsForArchive - OK\"");
// ignore createOperationsForPath which is called by createOperationsForArchive
- setExpectedScriptOutput("createOperationsForPath - OK");
+ setExpectedScriptOutput("\"createOperationsForPath - OK\"");
m_component->createOperationsForArchive("test.7z");
- setExpectedScriptOutput("beginInstallation - OK");
+ setExpectedScriptOutput("\"beginInstallation - OK\"");
m_component->beginInstallation();
- setExpectedScriptOutput("createOperations - OK");
+ setExpectedScriptOutput("\"createOperations - OK\"");
m_component->createOperations();
- setExpectedScriptOutput("isAutoDependOn - OK");
+ setExpectedScriptOutput("\"isAutoDependOn - OK\"");
bool returnIsAutoDependOn = m_component->isAutoDependOn(QSet<QString>());
QCOMPARE(returnIsAutoDependOn, false);
- setExpectedScriptOutput("isDefault - OK");
+ setExpectedScriptOutput("\"isDefault - OK\"");
bool returnIsDefault = m_component->isDefault();
QCOMPARE(returnIsDefault, false);
@@ -185,28 +176,19 @@ private slots:
Component *testComponent = new Component(&m_core);
testComponent->setValue(scName, "broken.component");
- // now m_core becomes the owner of testComponent
- // so it will delete it then at the destuctor
+ // m_core becomes the owner of testComponent, it will delete it in the destructor
m_core.appendRootComponent(testComponent);
const QString debugMesssage(
- "create Error-Exception: \"Exception while loading the component script: ':///data/component2.qs\n\n"
- "ReferenceError: Can't find variable: broken\n\n"
- "Backtrace:\n"
-#if QT_VERSION < 0x050000
- "\t<anonymous>()@:///data/component2.qs:5'\" ");
-#else
- "\tComponent() at :///data/component2.qs:5\n"
- "\t<anonymous>() at :///data/component2.qs:7\n"
- "\t<global>() at :///data/component2.qs:7'\" ");
-#endif
+ "create Error-Exception: \"Exception while loading the component script '"
+ ":///data/component2.qs'. (ReferenceError: broken is not defined)\"");
try {
// ignore Output from script
- setExpectedScriptOutput("script function: Component");
+ setExpectedScriptOutput("\"script function: Component\"");
setExpectedScriptOutput(qPrintable(debugMesssage));
testComponent->loadComponentScript(":///data/component2.qs");
} catch (const Error &error) {
- QVERIFY2(debugMesssage.contains(error.message()), "There was some unexpected error.");
+ QVERIFY2(debugMesssage.contains(error.message()), "(ReferenceError: broken is not defined)");
}
}
@@ -226,7 +208,7 @@ private slots:
QTest::ignoreMessage(QtWarningMsg, "Button with type: \"unknown button\" not found! ");
testGui.callProtectedDelayedExecuteControlScript(PackageManagerCore::ComponentSelection);
- setExpectedScriptOutput("FinishedPageCallback - OK");
+ setExpectedScriptOutput("\"FinishedPageCallback - OK\"");
testGui.callProtectedDelayedExecuteControlScript(PackageManagerCore::InstallationFinished);
} catch (const Error &error) {
QFAIL(qPrintable(error.message()));