summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io
diff options
context:
space:
mode:
authorDavid Faure <david.faure@kdab.com>2015-11-30 13:49:33 +0100
committerDavid Faure <david.faure@kdab.com>2015-12-22 09:56:23 +0000
commit5f03b48cb38936e2e86143bec71d030876b84c8b (patch)
treef13fcde62d6f187c26744db342af9adf0ccad6bb /tests/auto/corelib/io
parent4d9e06fa5346858bed41880917a850964acae225 (diff)
QStandardPaths: warn if $XDG_RUNTIME_DIR doesn't exist
If the environment variable is set, but points to a non-existing directory, the user would get a warning about chmod failing. Better be clear and warn about the fact that the directory itself doesn't exist. Also warn if $XDG_RUNTIME_DIR points to a file rather than a directory. Task-number: QTBUG-48771 Change-Id: If84e72d768528ea4b80260afbbc18709b7b738a8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Diffstat (limited to 'tests/auto/corelib/io')
-rw-r--r--tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp
index 24ff2f237f..50c5b938e9 100644
--- a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp
+++ b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp
@@ -464,6 +464,15 @@ void tst_qstandardpaths::testCustomRuntimeDirectory()
#endif
#ifdef Q_XDG_PLATFORM
+ struct EnvVarRestorer
+ {
+ EnvVarRestorer() : origRuntimeDir(qgetenv("XDG_RUNTIME_DIR")) {}
+ ~EnvVarRestorer() { qputenv("XDG_RUNTIME_DIR", origRuntimeDir.constData()); }
+ const QByteArray origRuntimeDir;
+ };
+ EnvVarRestorer restorer;
+
+ // When $XDG_RUNTIME_DIR points to a directory with wrong ownership, QStandardPaths should warn
qputenv("XDG_RUNTIME_DIR", QFile::encodeName("/tmp"));
// It's very unlikely that /tmp is 0600 or that we can chmod it
// The call below outputs
@@ -474,6 +483,20 @@ void tst_qstandardpaths::testCustomRuntimeDirectory()
qPrintable(QString::fromLatin1("QStandardPaths: wrong ownership on runtime directory /tmp, 0 instead of %1").arg(uid)));
const QString runtimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
QVERIFY2(runtimeDir.isEmpty(), qPrintable(runtimeDir));
+
+ // When $XDG_RUNTIME_DIR points to a non-existing directory, QStandardPaths should warn (QTBUG-48771)
+ qputenv("XDG_RUNTIME_DIR", "does_not_exist");
+ QTest::ignoreMessage(QtWarningMsg, "QStandardPaths: XDG_RUNTIME_DIR points to non-existing path 'does_not_exist', please create it with 0700 permissions.");
+ const QString nonExistingRuntimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
+ QVERIFY2(nonExistingRuntimeDir.isEmpty(), qPrintable(nonExistingRuntimeDir));
+
+ // When $XDG_RUNTIME_DIR points to a file, QStandardPaths should warn
+ const QString file = QFINDTESTDATA("tst_qstandardpaths.cpp");
+ QVERIFY(!file.isEmpty());
+ qputenv("XDG_RUNTIME_DIR", QFile::encodeName(file));
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(QString::fromLatin1("QStandardPaths: XDG_RUNTIME_DIR points to '%1' which is not a directory").arg(file)));
+ const QString noRuntimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
+ QVERIFY2(noRuntimeDir.isEmpty(), qPrintable(file));
#endif
}