summaryrefslogtreecommitdiffstats
path: root/tests/auto/installer/scriptengine/tst_scriptengine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/installer/scriptengine/tst_scriptengine.cpp')
-rw-r--r--tests/auto/installer/scriptengine/tst_scriptengine.cpp166
1 files changed, 143 insertions, 23 deletions
diff --git a/tests/auto/installer/scriptengine/tst_scriptengine.cpp b/tests/auto/installer/scriptengine/tst_scriptengine.cpp
index 998e91523..0377b8c3a 100644
--- a/tests/auto/installer/scriptengine/tst_scriptengine.cpp
+++ b/tests/auto/installer/scriptengine/tst_scriptengine.cpp
@@ -33,10 +33,14 @@
#include <component.h>
#include <errors.h>
+#include <updateoperation.h>
+#include <updateoperationfactory.h>
#include <packagemanagercore.h>
#include <packagemanagergui.h>
#include <scriptengine.h>
+#include <../unicodeexecutable/stringdata.h>
+
#include <QTest>
#include <QSet>
#include <QFile>
@@ -156,6 +160,29 @@ signals:
void emitted();
};
+class EmptyArgOperation : public KDUpdater::UpdateOperation
+{
+public:
+ explicit EmptyArgOperation(QInstaller::PackageManagerCore *core)
+ : KDUpdater::UpdateOperation(core)
+ {
+ setName("EmptyArg");
+ }
+
+ void backup() {}
+ bool performOperation() {
+ return true;
+ }
+ bool undoOperation() {
+ return true;
+ }
+ bool testOperation() {
+ return true;
+ }
+};
+
+
+// -- tst_ScriptEngine
class tst_ScriptEngine : public QObject
{
@@ -171,6 +198,9 @@ private slots:
m_component->setValue("Default", "Script");
m_component->setValue(scName, "component.test.name");
+ Component *component = new Component(&m_core);
+ component->setValue(scName, "component.test.addOperation");
+ m_core.appendRootComponent(component);
m_scriptEngine = m_core.componentScriptEngine();
}
@@ -250,9 +280,9 @@ private slots:
QCOMPARE(context.isError(), false);
// ignore Output from script
- setExpectedScriptOutput("\"function receive()\"");
+ setExpectedScriptOutput("function receive()");
- QTest::ignoreMessage(QtWarningMsg, ":10: ReferenceError: foo is not defined");
+ QTest::ignoreMessage(QtWarningMsg, ":43: ReferenceError: foo is not defined");
emiter.produceSignal();
const QJSValue value = m_scriptEngine->evaluate("");
@@ -261,7 +291,7 @@ private slots:
void testScriptPrint()
{
- setExpectedScriptOutput("\"test\"");
+ setExpectedScriptOutput("test");
const QJSValue value = m_scriptEngine->evaluate("print(\"test\");");
if (value.isError()) {
QFAIL(qPrintable(QString::fromLatin1("ScriptEngine error:\n %1").arg(
@@ -271,7 +301,7 @@ private slots:
void testExistingInstallerObject()
{
- setExpectedScriptOutput("\"object\"");
+ setExpectedScriptOutput("object");
const QJSValue value = m_scriptEngine->evaluate("print(typeof installer)");
if (value.isError()) {
QFAIL(qPrintable(QString::fromLatin1("ScriptEngine error:\n %1").arg(
@@ -285,7 +315,7 @@ private slots:
"\n"
"print(component.name);").arg(m_component->name());
- setExpectedScriptOutput("\"component.test.name\"");
+ setExpectedScriptOutput("component.test.name");
const QJSValue value = m_scriptEngine->evaluate(script);
if (value.isError()) {
QFAIL(qPrintable(QString::fromLatin1("ScriptEngine error:\n %1").arg(
@@ -309,7 +339,7 @@ private slots:
"\n"
"print(components[0].name);");
- setExpectedScriptOutput("\"component.test.name\"");
+ setExpectedScriptOutput("component.test.name");
const QJSValue value = m_scriptEngine->evaluate(script);
if (value.isError()) {
QFAIL(qPrintable(QString::fromLatin1("ScriptEngine error:\n %1").arg(
@@ -321,28 +351,28 @@ private slots:
{
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("\"isDefault - OK\"");
+ setExpectedScriptOutput("isDefault - OK");
bool returnIsDefault = m_component->isDefault();
QCOMPARE(returnIsDefault, false);
@@ -359,23 +389,22 @@ private slots:
// 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'. (ReferenceError: broken is not defined)\"");
try {
// ignore Output from script
- setExpectedScriptOutput("\"script function: Component\"");
- setExpectedScriptOutput(qPrintable(debugMesssage));
+ setExpectedScriptOutput("script function: Component");
testComponent->loadComponentScript(":///data/component2.qs");
} catch (const Error &error) {
- QVERIFY2(debugMesssage.contains(error.message()), "(ReferenceError: broken is not defined)");
+ const QString debugMessage(
+ QString("create Error-Exception: \"Exception while loading the component script \"%1\": "
+ "ReferenceError: broken is not defined\"").arg(QDir::toNativeSeparators(":///data/component2.qs")));
+ QVERIFY2(debugMessage.contains(error.message()), "(ReferenceError: broken is not defined)");
}
}
void loadComponentUserInterfaces()
{
try {
- setExpectedScriptOutput("\"checked: false\"");
+ setExpectedScriptOutput("checked: false");
m_component->loadUserInterfaces(QDir(":///data"), QStringList() << QLatin1String("form.ui"));
m_component->loadComponentScript(":///data/userinterface.qs");
} catch (const Error &error) {
@@ -397,7 +426,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()));
@@ -444,6 +473,56 @@ private slots:
QCOMPARE(gui.widget()->property("complete").toString(), QString("true"));
}
+ void testInstallerExecuteEncodings_data()
+ {
+ QTest::addColumn<QString>("argumentsToInstallerExecute");
+ QTest::addColumn<QString>("expectedOutput");
+ QTest::addColumn<int>("expectedExitCode");
+
+ QTest::newRow("default_encoding_ascii_output_exit_code_0")
+ << QString::fromLatin1("['ascii', '0']") << QString::fromLatin1(asciiText) << 0;
+ QTest::newRow("default_encoding_ascii_output_exit_code_52")
+ << QString::fromLatin1("['ascii', '52']") << QString::fromLatin1(asciiText) << 52;
+
+ QTest::newRow("latin1_encoding_ascii_output")
+ << QString::fromLatin1("['ascii', '0'], '', 'latin1', 'latin1'") << QString::fromLatin1(asciiText) << 0;
+ QTest::newRow("latin1_encoding_utf8_output")
+ << QString::fromLatin1("['utf8', '0'], '', 'latin1', 'latin1'") << QString::fromLatin1(utf8Text) << 0;
+
+ QTest::newRow("utf8_encoding_ascii_output")
+ << QString::fromLatin1("['ascii', '0'], '', 'utf8', 'utf8'") << QString::fromUtf8(asciiText) << 0;
+ QTest::newRow("utf8_encoding_utf8_output")
+ << QString::fromLatin1("['utf8', '0'], '', 'utf8', 'utf8'") << QString::fromUtf8(utf8Text) << 0;
+ }
+
+ void testInstallerExecuteEncodings()
+ {
+ QString unicodeExecutableName = QLatin1String(BUILDDIR "/../unicodeexecutable/unicodeexecutable");
+#if defined(Q_OS_WIN)
+ unicodeExecutableName += QLatin1String(".exe");
+#endif
+
+ QFileInfo unicodeExecutable(unicodeExecutableName);
+ if (!unicodeExecutable.isExecutable()) {
+ QFAIL(qPrintable(QString::fromLatin1("ScriptEngine error: test program %1 is not executable")
+ .arg(unicodeExecutable.absoluteFilePath())));
+ return;
+ }
+
+ const QString testProgramPath = unicodeExecutable.absoluteFilePath();
+
+ QFETCH(QString, argumentsToInstallerExecute);
+ QFETCH(QString, expectedOutput);
+ QFETCH(int, expectedExitCode);
+
+ QJSValue result = m_scriptEngine->evaluate(QString::fromLatin1("installer.execute('%1', %2);")
+ .arg(testProgramPath)
+ .arg(argumentsToInstallerExecute));
+ QCOMPARE(result.isArray(), true);
+ QCOMPARE(result.property(0).toString(), expectedOutput);
+ QCOMPARE(result.property(1).toString(), QString::number(expectedExitCode));
+ }
+
void checkEnteringCalledBeforePageCallback()
{
EnteringGui gui(&m_core);
@@ -459,6 +538,47 @@ private slots:
QCOMPARE(enteringPage->invocationOrder(), expectedOrder);
}
+ void testAddOperation_AddElevatedOperation()
+ {
+#if QT_VERSION < 0x50600
+ QSKIP("Behavior changed from 5.6.0 onwards.");
+#endif
+ using namespace KDUpdater;
+ UpdateOperationFactory &factory = UpdateOperationFactory::instance();
+ factory.registerUpdateOperation<EmptyArgOperation>(QLatin1String("EmptyArg"));
+
+ try {
+ m_core.setPackageManager();
+ Component *component = m_core.componentByName("component.test.addOperation");
+ component->loadComponentScript(":///data/addOperation.qs");
+
+ setExpectedScriptOutput("Component::createOperations()");
+ component->createOperations();
+
+ const OperationList operations = component->operations();
+ QCOMPARE(operations.count(), 8);
+
+ struct {
+ const char* args[3];
+ const char* operator[](int i) const {
+ return args[i];
+ }
+ } expectedArgs[] = {
+ { "Arg", "Arg2", "" }, { "Arg", "", "Arg3" }, { "", "Arg2", "Arg3" }, { "Arg", "Arg2", "" },
+ { "eArg", "eArg2", "" }, { "eArg", "", "eArg3" }, { "", "eArg2", "eArg3" }, { "eArg", "eArg2", "" }
+ };
+
+ for (int i = 0; i < operations.count(); ++i) {
+ const QStringList arguments = operations[i]->arguments();
+ QCOMPARE(arguments.count(), 3);
+ for (int j = 0; j < 3; ++j)
+ QCOMPARE(arguments[j], QString(expectedArgs[i][j]));
+ }
+ } catch (const QInstaller::Error &error) {
+ QFAIL(qPrintable(error.message()));
+ }
+ }
+
private:
void setExpectedScriptOutput(const char *message)
{