summaryrefslogtreecommitdiffstats
path: root/tests/auto/installer/scriptengine
diff options
context:
space:
mode:
authorKarsten Heimrich <karsten.heimrich@theqtcompany.com>2016-03-30 12:53:31 +0200
committerFrerich Raabe <raabe@froglogic.com>2016-03-30 21:13:03 +0000
commitba145f6090f481a41e7a476355c83039ed8ff521 (patch)
tree95de65d51e258c65d2ab5adf9d275cb5717bb229 /tests/auto/installer/scriptengine
parent6e904b95bd15b542fb7dc846c80ec705c9155d51 (diff)
Make communication via installer.execute() Unicode safe
It was impossible to pass Unicode data safely to a process started via installer.execute(), or to read Unicode data printed by that process safely back in. The reason for this is that the code hardcoded the latin1 codec for converting between strings used in the script interpreter and bytes used by the QProcessWrapper API. Fix this by adding two new optional arguments to installer.execute() which can be used to define the codec to be used for writing to stdin resp. reading from stdout. This defaults to latin1 for backwards compatibility. Change-Id: I290d8d9617b286ef90b2f0a05c6e7a47f6df317f Reviewed-by: Karsten Heimrich <karsten.heimrich@theqtcompany.com> Reviewed-by: Frerich Raabe <raabe@froglogic.com>
Diffstat (limited to 'tests/auto/installer/scriptengine')
-rw-r--r--tests/auto/installer/scriptengine/tst_scriptengine.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/auto/installer/scriptengine/tst_scriptengine.cpp b/tests/auto/installer/scriptengine/tst_scriptengine.cpp
index f02946148..249d42f56 100644
--- a/tests/auto/installer/scriptengine/tst_scriptengine.cpp
+++ b/tests/auto/installer/scriptengine/tst_scriptengine.cpp
@@ -39,6 +39,8 @@
#include <packagemanagergui.h>
#include <scriptengine.h>
+#include <../unicodeexecutable/stringdata.h>
+
#include <QTest>
#include <QSet>
#include <QFile>
@@ -472,6 +474,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("../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);