diff options
Diffstat (limited to 'tests/auto/installer/scriptengine/tst_scriptengine.cpp')
-rw-r--r-- | tests/auto/installer/scriptengine/tst_scriptengine.cpp | 124 |
1 files changed, 53 insertions, 71 deletions
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())); |