From fa08b143f3deb1db11984a88aa34d541c19c9fc5 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 3 Aug 2012 12:46:15 +0200 Subject: QtGlobal: (new) qEnvironmentVariableIs{Set,Empty}() These functions are a faster version of {,!}qgetenv().is{Null,Empty}(), a common pattern in Qt code. Their main advantage is that they don't need to allocate memory, so they can be used in noexcept functions, or dynamic initialisation of namespace-scope statics, because throwing in these contexts invokes std::terminate(). Change-Id: I651c5bd72f450b5d7df76590f8791572fe992af5 Reviewed-by: Thiago Macieira --- tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp') diff --git a/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp b/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp index e074aeb3e9..d7733bad02 100644 --- a/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp +++ b/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp @@ -53,12 +53,27 @@ private slots: void tst_QGetPutEnv::getSetCheck() { - const char* varName = "should_not_exist"; + const char varName[] = "should_not_exist"; + + QVERIFY(!qEnvironmentVariableIsSet(varName)); + QVERIFY(qEnvironmentVariableIsEmpty(varName)); QByteArray result = qgetenv(varName); QCOMPARE(result, QByteArray()); + +#ifndef Q_OS_WIN + QVERIFY(qputenv(varName, "")); // deletes varName instead of making it empty, on Windows + + QVERIFY(qEnvironmentVariableIsSet(varName)); + QVERIFY(qEnvironmentVariableIsEmpty(varName)); +#endif + QVERIFY(qputenv(varName, QByteArray("supervalue"))); + + QVERIFY(qEnvironmentVariableIsSet(varName)); + QVERIFY(!qEnvironmentVariableIsEmpty(varName)); result = qgetenv(varName); QVERIFY(result == "supervalue"); + qputenv(varName,QByteArray()); } -- cgit v1.2.3