diff options
author | Karsten Heimrich <karsten.heimrich@theqtcompany.com> | 2016-03-30 12:53:31 +0200 |
---|---|---|
committer | Frerich Raabe <raabe@froglogic.com> | 2016-03-30 21:13:03 +0000 |
commit | ba145f6090f481a41e7a476355c83039ed8ff521 (patch) | |
tree | 95de65d51e258c65d2ab5adf9d275cb5717bb229 /tests/auto | |
parent | 6e904b95bd15b542fb7dc846c80ec705c9155d51 (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')
-rw-r--r-- | tests/auto/installer/installer.pro | 2 | ||||
-rw-r--r-- | tests/auto/installer/scriptengine/tst_scriptengine.cpp | 52 | ||||
-rw-r--r-- | tests/auto/installer/unicodeexecutable/main.c | 54 | ||||
-rw-r--r-- | tests/auto/installer/unicodeexecutable/stringdata.h | 41 | ||||
-rw-r--r-- | tests/auto/installer/unicodeexecutable/unicodeexecutable.pro | 8 |
5 files changed, 157 insertions, 0 deletions
diff --git a/tests/auto/installer/installer.pro b/tests/auto/installer/installer.pro index 7f18fa4d1..ba2dd0244 100644 --- a/tests/auto/installer/installer.pro +++ b/tests/auto/installer/installer.pro @@ -8,6 +8,7 @@ SUBDIRS += \ messageboxhandler \ extractarchiveoperationtest \ lib7zfacade \ + unicodeexecutable \ scriptengine \ consumeoutputoperationtest \ mkdiroperationtest \ @@ -23,3 +24,4 @@ SUBDIRS += \ win32 { SUBDIRS += registerfiletypeoperation } +scriptengine.depends += unicodeexecutable 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); diff --git a/tests/auto/installer/unicodeexecutable/main.c b/tests/auto/installer/unicodeexecutable/main.c new file mode 100644 index 000000000..d82e0cb60 --- /dev/null +++ b/tests/auto/installer/unicodeexecutable/main.c @@ -0,0 +1,54 @@ +/************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Installer Framework. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** +** $QT_END_LICENSE$ +** +**************************************************************************/ + +#include "stringdata.h" + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int main(int argc, char **argv) +{ + assert(argc == 3 || !"incorrect number of arguments"); + + if (!strcmp(argv[1], "utf8")) { + printf("%s", utf8Text); + } else { + printf("%s", asciiText); + } + + return atoi(argv[2]); +} + diff --git a/tests/auto/installer/unicodeexecutable/stringdata.h b/tests/auto/installer/unicodeexecutable/stringdata.h new file mode 100644 index 000000000..901fac31a --- /dev/null +++ b/tests/auto/installer/unicodeexecutable/stringdata.h @@ -0,0 +1,41 @@ +/************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Installer Framework. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** +** $QT_END_LICENSE$ +** +**************************************************************************/ + +#ifndef STRINGDATA_H +#define STRINGDATA_H + +const char asciiText[] = "This is some ASCII text."; +const char utf8Text[] = "\x46\x6F\x6F\x20\xC2\xA9\x20\x62\x61\x72\x20\xF0\x9D\x8C\x86\x20\x62\x61\x7A\x20\xE2\x98\x83\x20\x71\x75\x78"; + +#endif // !defined(STRINGDATA_H) diff --git a/tests/auto/installer/unicodeexecutable/unicodeexecutable.pro b/tests/auto/installer/unicodeexecutable/unicodeexecutable.pro new file mode 100644 index 000000000..2da7be243 --- /dev/null +++ b/tests/auto/installer/unicodeexecutable/unicodeexecutable.pro @@ -0,0 +1,8 @@ +SOURCES = main.c + +CONFIG -= qt app_bundle +CONFIG += console + +DESTDIR = ./ + +QT = |