summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qsettings/tst_qsettings.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2015-10-23 14:01:35 +0200
committerOswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>2015-10-23 14:45:03 +0200
commit790aef362fd195adf97d8c780a7cbbbade27d51f (patch)
tree8be464687ab21806cfe9f7ada27098b563aa41b2 /tests/auto/corelib/io/qsettings/tst_qsettings.cpp
parent9720efbd1035c2e939b0581163e6d804c713dd96 (diff)
parent07475c662eb73c833da2d461b8ef2702ca1e2cfb (diff)
Merge remote-tracking branch 'origin/5.6' into dev
Conflicts: .qmake.conf configure src/corelib/global/qglobal.h src/tools/qdoc/node.cpp src/tools/qdoc/qdocdatabase.cpp tests/auto/corelib/io/qsettings/tst_qsettings.cpp tools/configure/configureapp.cpp Change-Id: I66028ae5e441a06b73ee85ba72a03a3af3e8593f
Diffstat (limited to 'tests/auto/corelib/io/qsettings/tst_qsettings.cpp')
-rw-r--r--tests/auto/corelib/io/qsettings/tst_qsettings.cpp93
1 files changed, 29 insertions, 64 deletions
diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp
index 30812700c5..b0cb59a012 100644
--- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp
+++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp
@@ -89,12 +89,11 @@ class tst_QSettings : public QObject
Q_OBJECT
public:
- tst_QSettings() : m_canWriteNativeSystemSettings(canWriteNativeSystemSettings()) {}
+ tst_QSettings();
public slots:
void initTestCase();
- void init();
- void cleanup();
+ void cleanup() { cleanupTestFiles(); }
private slots:
void getSetCheck();
void ctor_data();
@@ -166,6 +165,8 @@ private slots:
void bom();
private:
+ void cleanupTestFiles();
+
const bool m_canWriteNativeSystemSettings;
};
@@ -181,39 +182,16 @@ void tst_QSettings::getSetCheck()
QCOMPARE(true, obj1.fallbacksEnabled());
}
-#if defined(Q_OS_WINCE) || defined(Q_OS_WINRT)
-static void removePath(const QString& _path)
-{
- QString path = _path;
- QDir dir(path);
- if (!dir.exists())
- return;
- QStringList entries = dir.entryList(QDir::AllEntries | QDir::NoDotAndDotDot);
- foreach(QString name, entries) {
- QString absolute = path + name;
- if (QFileInfo(absolute).isDir())
- removePath(absolute+"\\");
- else
- QFile::remove(absolute);
- }
- dir.cdUp();
- if (path[path.size()-1] == '\\')
- path = path.left(path.size()-1);
- dir.rmdir(path.mid(path.lastIndexOf('\\')+1));
-}
-#endif
-
-static QString settingsPath(const char *path = "")
+static QString settingsPath(const char *path = Q_NULLPTR)
{
// Temporary path for files that are specified explicitly in the constructor.
#ifndef Q_OS_WINRT
- QString tempPath = QDir::tempPath();
+ static const QString tempPath = QDir::tempPath() + QLatin1String("/tst_QSettings");
#else
- QString tempPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
+ static const QString tempPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)
+ + QLatin1String("/tst_QSettings");
#endif
- if (tempPath.endsWith(QLatin1Char('/')))
- tempPath.truncate(tempPath.size() - 1);
- return QDir::toNativeSeparators(tempPath + "/tst_QSettings/" + QLatin1String(path));
+ return path && *path ? tempPath + QLatin1Char('/') + QLatin1String(path) : tempPath;
}
static bool readCustom1File(QIODevice &device, QSettings::SettingsMap &map)
@@ -283,6 +261,12 @@ static void populateWithFormats()
QTest::newRow("custom2") << QSettings::CustomFormat2;
}
+tst_QSettings::tst_QSettings()
+ : m_canWriteNativeSystemSettings(canWriteNativeSystemSettings())
+{
+ QStandardPaths::setTestModeEnabled(true);
+}
+
void tst_QSettings::initTestCase()
{
if (!m_canWriteNativeSystemSettings)
@@ -295,13 +279,19 @@ void tst_QSettings::initTestCase()
);
QCOMPARE(custom1, QSettings::CustomFormat1);
QCOMPARE(custom2, QSettings::CustomFormat2);
+
+ cleanupTestFiles();
}
-void tst_QSettings::init()
+void tst_QSettings::cleanupTestFiles()
{
QSettings::setSystemIniPath(settingsPath("__system__"));
QSettings::setUserIniPath(settingsPath("__user__"));
+ QDir settingsDir(settingsPath());
+ if (settingsDir.exists())
+ QVERIFY(settingsDir.removeRecursively());
+
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
QSettings("HKEY_CURRENT_USER\\Software\\software.org", QSettings::NativeFormat).clear();
QSettings("HKEY_CURRENT_USER\\Software\\other.software.org", QSettings::NativeFormat).clear();
@@ -317,17 +307,7 @@ void tst_QSettings::init()
QSettings("HKEY_LOCAL_MACHINE\\Software\\bat", QSettings::NativeFormat).clear();
QSettings("HKEY_LOCAL_MACHINE\\Software\\baz", QSettings::NativeFormat).clear();
}
- if (QDir(settingsPath()).exists()) {
-#if defined(Q_OS_WINCE)
- removePath(settingsPath());
-#else
- if (QSysInfo::windowsVersion() & QSysInfo::WV_NT_based)
- system(QString("rmdir /Q /S %1").arg(settingsPath()).toLatin1());
- else
- system(QString("deltree /Y %1").arg(settingsPath()).toLatin1());
-#endif
- }
-#elif defined(Q_OS_DARWIN)
+#elif defined(Q_OS_DARWIN) || defined(Q_OS_WINRT)
QSettings(QSettings::UserScope, "software.org", "KillerAPP").clear();
QSettings(QSettings::SystemScope, "software.org", "KillerAPP").clear();
QSettings(QSettings::UserScope, "other.software.org", "KillerAPP").clear();
@@ -338,31 +318,16 @@ void tst_QSettings::init()
QSettings(QSettings::SystemScope, "other.software.org").clear();
#endif
-#if !defined(Q_OS_WIN)
- system(QString("chmod -R u+rw %1 2> /dev/null").arg(settingsPath()).toLatin1());
- system(QString("rm -fr %1 2> /dev/null").arg(settingsPath()).toLatin1());
-#endif
+ const QString foo(QLatin1String("foo"));
#if defined(Q_OS_WINRT)
- QSettings(QSettings::UserScope, "software.org", "KillerAPP").clear();
- QSettings(QSettings::SystemScope, "software.org", "KillerAPP").clear();
- QSettings(QSettings::UserScope, "other.software.org", "KillerAPP").clear();
- QSettings(QSettings::SystemScope, "other.software.org", "KillerAPP").clear();
- QSettings(QSettings::UserScope, "software.org").clear();
- QSettings(QSettings::SystemScope, "software.org").clear();
- QSettings(QSettings::UserScope, "other.software.org").clear();
- QSettings(QSettings::SystemScope, "other.software.org").clear();
- QSettings("foo", QSettings::NativeFormat).clear();
- removePath(settingsPath());
- QFile::remove(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/foo");
+ QSettings(foo, QSettings::NativeFormat).clear();
+ QFile fooFile(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + QLatin1Char('/') + foo);
#else
- QFile::remove("foo");
+ QFile fooFile(foo);
#endif
-}
-
-void tst_QSettings::cleanup()
-{
- init();
+ if (fooFile.exists())
+ QVERIFY2(fooFile.remove(), qPrintable(fooFile.errorString()));
}
/*