diff options
author | Thomas Sondergaard <ts@medical-insight.com> | 2011-04-04 09:40:46 (GMT) |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2011-04-04 10:21:50 (GMT) |
commit | 0cf75b4dd1cc25694de8ece4c25ecb97a3969a54 (patch) | |
tree | 0724f3cb6b84f5fcbec493860c084e2d5442bb2d /tests/auto | |
parent | 0c291498c3cf1aa254df41ce99f249e2116da025 (diff) | |
download | Qt-0cf75b4dd1cc25694de8ece4c25ecb97a3969a54.zip Qt-0cf75b4dd1cc25694de8ece4c25ecb97a3969a54.tar.gz Qt-0cf75b4dd1cc25694de8ece4c25ecb97a3969a54.tar.bz2 |
Add methods for traversing and combining QProcessEnvironment.
New methods that make QProcessEnvironment more friendly. With these
two new functions developers no longer have to resort to using
QStringList and use the deprecated QProcess::setEnvironment() method.
New methods:
- QStringList QProcessEnvironment::keys()
- void QProcessEnvironment::insert(const QProcessEnvironment &).
Merge-request: 1152
Reviewed-by: ossi
Reviewed-by: thiago
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qprocessenvironment/tst_qprocessenvironment.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/auto/qprocessenvironment/tst_qprocessenvironment.cpp b/tests/auto/qprocessenvironment/tst_qprocessenvironment.cpp index ea06295..1c26343 100644 --- a/tests/auto/qprocessenvironment/tst_qprocessenvironment.cpp +++ b/tests/auto/qprocessenvironment/tst_qprocessenvironment.cpp @@ -56,6 +56,8 @@ private slots: void insert(); void emptyNull(); void toStringList(); + void keys(); + void insertEnv(); void caseSensitivity(); void systemEnvironment(); @@ -154,6 +156,58 @@ void tst_QProcessEnvironment::toStringList() QVERIFY(result.contains("HELLO=World")); } +void tst_QProcessEnvironment::keys() +{ + QProcessEnvironment e; + QVERIFY(e.isEmpty()); + QVERIFY(e.keys().isEmpty()); + + e.insert("FOO", "bar"); + QStringList result = e.keys(); + QCOMPARE(result.length(), 1); + QCOMPARE(result.at(0), QString("FOO")); + + e.clear(); + e.insert("BAZ", ""); + result = e.keys(); + QCOMPARE(result.at(0), QString("BAZ")); + + e.insert("FOO", "bar"); + e.insert("A", "bc"); + e.insert("HELLO", "World"); + result = e.keys(); + QCOMPARE(result.length(), 4); + + // order is not specified, so use contains() + QVERIFY(result.contains("FOO")); + QVERIFY(result.contains("BAZ")); + QVERIFY(result.contains("A")); + QVERIFY(result.contains("HELLO")); +} + +void tst_QProcessEnvironment::insertEnv() +{ + QProcessEnvironment e; + e.insert("FOO", "bar"); + e.insert("A", "bc"); + e.insert("Hello", "World"); + + QProcessEnvironment e2; + e2.insert("FOO2", "bar2"); + e2.insert("A2", "bc2"); + e2.insert("Hello", "Another World"); + + e.insert(e2); + QStringList keys = e.keys(); + QCOMPARE(keys.length(), 5); + + QCOMPARE(e.value("FOO"), QString("bar")); + QCOMPARE(e.value("A"), QString("bc")); + QCOMPARE(e.value("Hello"), QString("Another World")); + QCOMPARE(e.value("FOO2"), QString("bar2")); + QCOMPARE(e.value("A2"), QString("bc2")); +} + void tst_QProcessEnvironment::caseSensitivity() { QProcessEnvironment e; |