diff options
Diffstat (limited to 'tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp')
-rw-r--r-- | tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp index efb343cf85..50c5b938e9 100644 --- a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp +++ b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp @@ -56,6 +56,7 @@ class tst_qstandardpaths : public QObject Q_OBJECT private slots: + void initTestCase(); void dump(); void testDefaultLocations(); void testCustomLocations(); @@ -128,6 +129,14 @@ static const char * const enumNames[MaxStandardLocation + 1 - int(QStandardPaths "AppConfigLocation" }; +void tst_qstandardpaths::initTestCase() +{ + QVERIFY2(m_localConfigTempDir.isValid(), qPrintable(m_localConfigTempDir.errorString())); + QVERIFY2(m_globalConfigTempDir.isValid(), qPrintable(m_globalConfigTempDir.errorString())); + QVERIFY2(m_localAppTempDir.isValid(), qPrintable(m_localAppTempDir.errorString())); + QVERIFY2(m_globalAppTempDir.isValid(), qPrintable(m_globalAppTempDir.errorString())); +} + void tst_qstandardpaths::dump() { #ifdef Q_XDG_PLATFORM @@ -455,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 @@ -465,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 } |