summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp')
-rw-r--r--tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp35
1 files changed, 31 insertions, 4 deletions
diff --git a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp
index 2c0500eec9..d37651bd7a 100644
--- a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp
+++ b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp
@@ -24,6 +24,8 @@
#define Q_XDG_PLATFORM
#endif
+using namespace Qt::StringLiterals;
+
// Update this when adding new enum values; update enumNames too
static const int MaxStandardLocation = QStandardPaths::AppConfigLocation;
@@ -147,12 +149,12 @@ void tst_qstandardpaths::testDefaultLocations()
QCOMPARE(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation), expectedConfHome);
QCOMPARE(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation), expectedConfHome);
const QStringList confDirs = QStandardPaths::standardLocations(QStandardPaths::ConfigLocation);
- QCOMPARE(confDirs.count(), 2);
+ QCOMPARE(confDirs.size(), 2);
QVERIFY(confDirs.contains(expectedConfHome));
QCOMPARE(QStandardPaths::standardLocations(QStandardPaths::GenericConfigLocation), confDirs);
const QStringList genericDataDirs = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
- QCOMPARE(genericDataDirs.count(), 3);
+ QCOMPARE(genericDataDirs.size(), 3);
const QString expectedDataHome = QDir::homePath() + QString::fromLatin1("/.local/share");
QCOMPARE(genericDataDirs.at(0), expectedDataHome);
QCOMPARE(genericDataDirs.at(1), QString::fromLatin1("/usr/local/share"));
@@ -260,7 +262,7 @@ void tst_qstandardpaths::testLocateAll()
#ifdef Q_XDG_PLATFORM
setCustomLocations();
const QStringList appsDirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "applications", QStandardPaths::LocateDirectory);
- QCOMPARE(appsDirs.count(), 0); // they don't exist yet
+ QCOMPARE(appsDirs.size(), 0); // they don't exist yet
const QStringList expectedAppsDirs = QStringList() << m_localAppDir + QLatin1String("/applications")
<< m_globalAppDir + QLatin1String("/applications");
QDir().mkdir(expectedAppsDirs.at(0));
@@ -301,7 +303,7 @@ void tst_qstandardpaths::testDataLocation()
const QString expectedAppDataDir = QDir::homePath() + QString::fromLatin1("/.local/share/Qt/QtTest");
QCOMPARE(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation), expectedAppDataDir);
const QStringList appDataDirs = QStandardPaths::standardLocations(QStandardPaths::AppLocalDataLocation);
- QCOMPARE(appDataDirs.count(), 3);
+ QCOMPARE(appDataDirs.size(), 3);
QCOMPARE(appDataDirs.at(0), expectedAppDataDir);
QCOMPARE(appDataDirs.at(1), QString::fromLatin1("/usr/local/share/Qt/QtTest"));
QCOMPARE(appDataDirs.at(2), QString::fromLatin1("/usr/share/Qt/QtTest"));
@@ -724,6 +726,31 @@ void tst_qstandardpaths::testXdgPathCleanup()
QVERIFY(!appsDirs.contains("/applications"));
QVERIFY(!appsDirs.contains(uncleanGlobalAppDir + "/applications"));
QVERIFY(!appsDirs.contains("relative/path/applications"));
+
+ const QString uncleanGlobalConfigDir = "/./" + QFile::encodeName(m_globalConfigDir);
+ qputenv("XDG_CONFIG_DIRS", QFile::encodeName(uncleanGlobalConfigDir) + "::relative/path");
+ const QStringList configDirs = QStandardPaths::standardLocations(QStandardPaths::ConfigLocation);
+ QVERIFY(!configDirs.contains("relative/path"_L1));
+ QVERIFY(!configDirs.contains(""_L1));
+
+ // Relative paths in XDG_* env vars are ignored
+ const QString relative("./someRelativeDir");
+
+ qputenv("XDG_CACHE_HOME", relative.toLatin1());
+ const QString cacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
+ QCOMPARE_NE(cacheDir, relative);
+
+ qputenv("XDG_DATA_HOME", relative.toLatin1());
+ const QString localDataDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
+ QCOMPARE_NE(localDataDir, relative);
+
+ qputenv("XDG_CONFIG_HOME", relative.toLatin1());
+ const QString localConfig = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
+ QCOMPARE_NE(localConfig, relative);
+
+ qputenv("XDG_RUNTIME_DIR", relative.toLatin1());
+ const QString runtimeDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
+ QCOMPARE_NE(runtimeDir, relative);
#endif
}