summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qprocess
diff options
context:
space:
mode:
authorThomas Sondergaard <thomas.sondergaard@karoshealth.com>2017-06-11 18:41:57 +0200
committerThomas Sondergaard <thomas@sondergaard.cc>2017-06-13 06:09:40 +0000
commit65a317e6745ee267bef7295f4dfe31d5ec62f7aa (patch)
tree85a937b1a896bdeffd3d0bb602ee9791363e1006 /tests/auto/corelib/io/qprocess
parentb4381100280adbfa4cb6c4d8c84eed8f1dc126b9 (diff)
Use QMap in QProcessEnvironment so variables are sorted
The motivation for this change is to make it simple to pass a correctly sorted environment block to Win32 CreateProcess(). It is also nice in other contexts that the environment variables are sorted. The change is made for all platforms. This keeps it simple and the only ill effect is slightly slower lookups. Concerning the environment block passed to Win32 CreateProcess: The environment block that is passed to CreateProcess() must be sorted case-insensitively and without regard to locale. See https://msdn.microsoft.com/en-us/library/windows/desktop/ms682009(v=vs.85).aspx The need for sorting the environment block is also mentioned in the CreateProcess() documentation, but with less details: https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx Task-number: QTBUG-61315 Change-Id: Ie1edd443301de79cf5f699d45beab01b7c0f9de3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/io/qprocess')
-rw-r--r--tests/auto/corelib/io/qprocess/tst_qprocess.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp
index 0783a65d8b..f4d6d5cb40 100644
--- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp
+++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp
@@ -94,6 +94,7 @@ private slots:
void setEnvironment();
void setProcessEnvironment_data();
void setProcessEnvironment();
+ void environmentIsSorted();
void spaceInName();
void setStandardInputFile();
void setStandardOutputFile_data();
@@ -1733,6 +1734,47 @@ void tst_QProcess::setProcessEnvironment()
}
}
+void tst_QProcess::environmentIsSorted()
+{
+ QProcessEnvironment env;
+ env.insert(QLatin1String("a"), QLatin1String("foo_a"));
+ env.insert(QLatin1String("B"), QLatin1String("foo_B"));
+ env.insert(QLatin1String("c"), QLatin1String("foo_c"));
+ env.insert(QLatin1String("D"), QLatin1String("foo_D"));
+ env.insert(QLatin1String("e"), QLatin1String("foo_e"));
+ env.insert(QLatin1String("F"), QLatin1String("foo_F"));
+ env.insert(QLatin1String("Path"), QLatin1String("foo_Path"));
+ env.insert(QLatin1String("SystemRoot"), QLatin1String("foo_SystemRoot"));
+
+ const QStringList envlist = env.toStringList();
+
+#ifdef Q_OS_WIN32
+ // The environment block passed to CreateProcess "[Requires that] All strings in the
+ // environment block must be sorted alphabetically by name. The sort is case-insensitive,
+ // Unicode order, without regard to locale."
+ // https://msdn.microsoft.com/en-us/library/windows/desktop/ms682009(v=vs.85).aspx
+ // So on Windows we sort that way.
+ const QStringList expected = { QLatin1String("a=foo_a"),
+ QLatin1String("B=foo_B"),
+ QLatin1String("c=foo_c"),
+ QLatin1String("D=foo_D"),
+ QLatin1String("e=foo_e"),
+ QLatin1String("F=foo_F"),
+ QLatin1String("Path=foo_Path"),
+ QLatin1String("SystemRoot=foo_SystemRoot") };
+#else
+ const QStringList expected = { QLatin1String("B=foo_B"),
+ QLatin1String("D=foo_D"),
+ QLatin1String("F=foo_F"),
+ QLatin1String("Path=foo_Path"),
+ QLatin1String("SystemRoot=foo_SystemRoot"),
+ QLatin1String("a=foo_a"),
+ QLatin1String("c=foo_c"),
+ QLatin1String("e=foo_e") };
+#endif
+ QCOMPARE(envlist, expected);
+}
+
void tst_QProcess::systemEnvironment()
{
QVERIFY(!QProcess::systemEnvironment().isEmpty());