diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2008-11-25 15:44:11 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2009-08-21 13:03:05 (GMT) |
commit | 02ef8fab7e511f50e901676eac15229eb456b01c (patch) | |
tree | 107d58effefa02942f3a715b8b60894852aee83d /tests/auto/qprocess/tst_qprocess.cpp | |
parent | f13908359f08d856c2825988e65651dbf744c0e4 (diff) | |
download | Qt-02ef8fab7e511f50e901676eac15229eb456b01c.zip Qt-02ef8fab7e511f50e901676eac15229eb456b01c.tar.gz Qt-02ef8fab7e511f50e901676eac15229eb456b01c.tar.bz2 |
Add a new class for handling a process's environment variables.
First of all, make it a lot easier to access individual variables by
having them in an associative container (a QHash). This fixes task
232427, albeit one release later than I had originally planned.
On Windows, the variable names in the environment are
case-insensitive, so a direct QHash isn't a good solution. Implement
code that does the uppercasing on Windows and leaves untransformed on
other platforms.
Since we're doing this anyways, use QByteArray on Unix systems, since,
in theory, the environment could contain any random binary data, which
is not representable in QString.
Task-number: 232427
Diffstat (limited to 'tests/auto/qprocess/tst_qprocess.cpp')
-rw-r--r-- | tests/auto/qprocess/tst_qprocess.cpp | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/tests/auto/qprocess/tst_qprocess.cpp b/tests/auto/qprocess/tst_qprocess.cpp index b57139b..d2af86a 100644 --- a/tests/auto/qprocess/tst_qprocess.cpp +++ b/tests/auto/qprocess/tst_qprocess.cpp @@ -130,6 +130,8 @@ private slots: void exitCodeTest(); void setEnvironment_data(); void setEnvironment(); + void setProcessEnvironment_data(); + void setProcessEnvironment(); void systemEnvironment(); void spaceInName(); void lockupsInStartDetached(); @@ -1697,16 +1699,39 @@ void tst_QProcess::setEnvironment() QCOMPARE(process.readAll(), value.toLocal8Bit()); } +#endif +} + +//----------------------------------------------------------------------------- +void tst_QProcess::setProcessEnvironment_data() +{ + setEnvironment_data(); +} + +void tst_QProcess::setProcessEnvironment() +{ +#if !defined (Q_OS_WINCE) + // there is no concept of system variables on Windows CE as there is no console + + // make sure our environment variables are correct + QVERIFY(qgetenv("tst_QProcess").isEmpty()); + QVERIFY(!qgetenv("PATH").isEmpty()); +#ifdef Q_OS_WIN + QVERIFY(!qgetenv("PROMPT").isEmpty()); +#endif + + QFETCH(QString, name); + QFETCH(QString, value); + QString executable = QDir::currentPath() + "/testProcessEnvironment/testProcessEnvironment"; - // use the hash variant now { QProcess process; - QHash<QString, QString> environment = QProcess::systemEnvironmentHash(); + QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); if (value.isNull()) environment.remove(name); else environment.insert(name, value); - process.setEnvironmentHash(environment); + process.setProcessEnvironment(environment); process.start(executable, QStringList() << name); QVERIFY(process.waitForFinished()); @@ -1725,12 +1750,12 @@ void tst_QProcess::systemEnvironment() #if defined (Q_OS_WINCE) // there is no concept of system variables on Windows CE as there is no console QVERIFY(QProcess::systemEnvironment().isEmpty()); - QVERIFY(QProcess::systemEnvironmentHash().isEmpty()); + QVERIFY(QProcessEnvironment::systemEnvironment().isEmpty()); #else QVERIFY(!QProcess::systemEnvironment().isEmpty()); - QVERIFY(!QProcess::systemEnvironmentHash().isEmpty()); + QVERIFY(!QProcessEnvironment::systemEnvironment().isEmpty()); - QVERIFY(QProcess::systemEnvironmentHash().contains("PATH")); + QVERIFY(QProcessEnvironment::systemEnvironment().contains("PATH")); QVERIFY(!QProcess::systemEnvironment().filter(QRegExp("^PATH=", Qt::CaseInsensitive)).isEmpty()); #endif } |