diff options
author | David Faure <faure@kde.org> | 2012-03-25 13:10:48 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-28 11:22:11 +0200 |
commit | a5a80da2238030b5ecbc7c5fba7ecd8cb5f2da1c (patch) | |
tree | 4b27a2112ecc4415a222f96807f462bb077bdf0c /src/corelib/io/qstandardpaths_mac.cpp | |
parent | 99e7ad660f23dce51ccd68438adae7528013d23c (diff) |
Allow auto tests to stay away from the user's configuration.
QStandardPaths now knows a "test mode" which changes writable locations
to point to test directories, in order to prevent auto tests from reading from
or writing to the current user's configuration.
This affects the locations into which test programs might write files:
GenericDataLocation, DataLocation, ConfigLocation,
GenericCacheLocation, CacheLocation.
Other locations are not affected.
Change-Id: I29606c2e74714360edd871a8c387a5c1ef7d1f54
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Jason McDonald <jason.mcdonald@nokia.com>
Diffstat (limited to 'src/corelib/io/qstandardpaths_mac.cpp')
-rw-r--r-- | src/corelib/io/qstandardpaths_mac.cpp | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/src/corelib/io/qstandardpaths_mac.cpp b/src/corelib/io/qstandardpaths_mac.cpp index 2890ead48a..53dfdaa392 100644 --- a/src/corelib/io/qstandardpaths_mac.cpp +++ b/src/corelib/io/qstandardpaths_mac.cpp @@ -90,6 +90,13 @@ OSType translateLocation(QStandardPaths::StandardLocation type) } } +static bool qsp_testMode = false; + +void QStandardPaths::enableTestMode(bool testMode) +{ + qsp_testMode = testMode; +} + /* Constructs a full unicode path from a FSRef. */ @@ -101,6 +108,16 @@ static QString getFullPath(const FSRef &ref) return QString(); } +static void appendOrganizationAndApp(QString &path) +{ + const QString org = QCoreApplication::organizationName(); + if (!org.isEmpty()) + path += QLatin1Char('/') + org; + const QString appName = QCoreApplication::applicationName(); + if (!appName.isEmpty()) + path += QLatin1Char('/') + appName; +} + static QString macLocation(QStandardPaths::StandardLocation type, short domain) { // http://developer.apple.com/documentation/Carbon/Reference/Folder_Manager/Reference/reference.html @@ -111,17 +128,36 @@ static QString macLocation(QStandardPaths::StandardLocation type, short domain) QString path = getFullPath(ref); - if (type == QStandardPaths::DataLocation || type == QStandardPaths::CacheLocation) { - if (!QCoreApplication::organizationName().isEmpty()) - path += QLatin1Char('/') + QCoreApplication::organizationName(); - if (!QCoreApplication::applicationName().isEmpty()) - path += QLatin1Char('/') + QCoreApplication::applicationName(); - } - return path; + if (type == QStandardPaths::DataLocation || type == QStandardPaths::CacheLocation) + appendOrganizationAndApp(path); + return path; } QString QStandardPaths::writableLocation(StandardLocation type) { + if (qsp_testMode) { + const QString qttestDir = QDir::homePath() + QLatin1String("/.qttest"); + QString path; + switch (type) { + case GenericDataLocation: + case DataLocation: + path = qttestDir + QLatin1String("/Application Support"); + if (type == DataLocation) + appendOrganizationAndApp(path); + return path; + case GenericCacheLocation: + case CacheLocation: + path = qttestDir + QLatin1String("/Cache"); + if (type == CacheLocation) + appendOrganizationAndApp(path); + return path; + case ConfigLocation: + return qttestDir + QLatin1String("/Preferences"); + default: + break; + } + } + switch (type) { case HomeLocation: return QDir::homePath(); |