diff options
author | Rohan McGovern <rohan.mcgovern@nokia.com> | 2009-07-27 04:50:10 (GMT) |
---|---|---|
committer | Rohan McGovern <rohan.mcgovern@nokia.com> | 2009-07-27 06:16:21 (GMT) |
commit | 5a7d29039917d9f0faf373045e8dbb274837c11d (patch) | |
tree | e03a9c2d0d0f331631e4a7c4981dec588d18b6de | |
parent | ba5b630fd58127a4bcfe2baf92603a7bc8899824 (diff) | |
download | Qt-5a7d29039917d9f0faf373045e8dbb274837c11d.zip Qt-5a7d29039917d9f0faf373045e8dbb274837c11d.tar.gz Qt-5a7d29039917d9f0faf373045e8dbb274837c11d.tar.bz2 |
Fixed failure of tst_qlocale if run when LC_ALL is set.
This test tried to be unaffected by the locale environment variables
set by the user by explicitly overwriting them and spawning a new
process. However this was only done for LANG and not the other
variables which can affect the locale. Do it for all the locale
variables.
Also, the previous approach (store the current value with qgetenv, then
put it back with qputenv later) doesn't really work because that
effectively takes variables which weren't set and sets them to an empty
string, which is not the same thing. Use QProcess::setEnvironment
instead.
Reviewed-by: Andy Shaw
-rw-r--r-- | tests/auto/qlocale/tst_qlocale.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/tests/auto/qlocale/tst_qlocale.cpp b/tests/auto/qlocale/tst_qlocale.cpp index 8ac6ef0..82bd864 100644 --- a/tests/auto/qlocale/tst_qlocale.cpp +++ b/tests/auto/qlocale/tst_qlocale.cpp @@ -327,9 +327,8 @@ void tst_QLocale::emptyCtor() { \ /* Test constructor without arguments. Needs separate process */ \ /* because of caching of the system locale. */ \ - QString oldEnv = QString::fromLocal8Bit(qgetenv("LANG")); \ - qputenv("LANG", QString(req_lc).toLocal8Bit()); \ QProcess process; \ + process.setEnvironment(QStringList(env) << QString("LANG=%1").arg(req_lc)); \ process.start("syslocaleapp/syslocaleapp"); \ process.waitForReadyRead(); \ QString ret = QString(process.readAll()); \ @@ -337,18 +336,23 @@ void tst_QLocale::emptyCtor() QVERIFY2(!ret.isEmpty(), "Cannot launch external process"); \ QVERIFY2(QString(exp_str) == ret, QString("Expected: " + QString(exp_str) + ", got: " \ + ret + ". Requested: " + QString(req_lc)).toLatin1().constData()); \ - qputenv("LANG", oldEnv.toLocal8Bit()); \ + } + + // Get an environment free of any locale-related variables + QStringList env; + foreach (QString const& entry, QProcess::systemEnvironment()) { + if (entry.startsWith("LANG=") || entry.startsWith("LC_")) + continue; + env << entry; } // Get default locale. - QString old = QString::fromLocal8Bit(qgetenv("LANG")); - qputenv("LANG", ""); QProcess p; + p.setEnvironment(env); p.start("syslocaleapp/syslocaleapp"); p.waitForReadyRead(); QString defaultLoc = QString(p.readAll()); p.waitForFinished(); - qputenv("LANG", old.toLocal8Bit()); TEST_CTOR("C", "C") TEST_CTOR("bla", "C") |