diff options
author | Maurice Kalinowski <maurice.kalinowski@digia.com> | 2014-08-19 08:08:04 +0200 |
---|---|---|
committer | Maurice Kalinowski <maurice.kalinowski@digia.com> | 2014-08-19 08:58:01 +0200 |
commit | 2ffcf3a42385a92a329b56d62b336cfeb5a974e2 (patch) | |
tree | 7016f07265f9ed2949dd1ec2ea486190464fa721 /tests/auto | |
parent | 3be048826f85675dfc51f2f1f8414d58ae499d32 (diff) |
WinRT: Fix QSettings auto-tests
WinRT is a sanboxed environment, hence files can only be created in
some writable location.
For some tests we reset the current directory to minimize the required
changes. We cannot do this for the application lifetime as the test
also has cases where it reads files relative to the executable inside
the sandbox.
Change-Id: Ib9d37c8cffd191f0d1055f835c11d10887923378
Reviewed-by: Andrew Knight <andrew.knight@digia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/corelib/io/qsettings/tst_qsettings.cpp | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp index 7f1c31044b..6c1d3d9aa7 100644 --- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp +++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp @@ -191,7 +191,7 @@ static void removePath(const QString& _path) QDir dir(path); if (!dir.exists()) return; - QStringList entries = dir.entryList(QDir::NoDotAndDotDot); + QStringList entries = dir.entryList(QDir::AllEntries | QDir::NoDotAndDotDot); foreach(QString name, entries) { QString absolute = path + name; if (QFileInfo(absolute).isDir()) @@ -209,7 +209,11 @@ static void removePath(const QString& _path) static QString settingsPath(const char *path = "") { // Temporary path for files that are specified explicitly in the constructor. +#ifndef Q_OS_WINRT QString tempPath = QDir::tempPath(); +#else + QString tempPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation); +#endif if (tempPath.endsWith("/")) tempPath.truncate(tempPath.size() - 1); return QDir::toNativeSeparators(tempPath + "/tst_QSettings/" + QLatin1String(path)); @@ -351,9 +355,12 @@ void tst_QSettings::init() 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()); -#endif + QFile::remove(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/foo"); +#else QFile::remove("foo"); +#endif } void tst_QSettings::cleanup() @@ -1804,6 +1811,11 @@ void tst_QSettings::testChildKeysAndGroups() void tst_QSettings::testUpdateRequestEvent() { +#ifdef Q_OS_WINRT + const QString oldCur = QDir::currentPath(); + QDir::setCurrent(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)); +#endif + QFile::remove("foo"); QVERIFY(!QFile::exists("foo")); @@ -1829,6 +1841,10 @@ void tst_QSettings::testUpdateRequestEvent() QVERIFY(QFileInfo("foo").size() > 0); QTRY_VERIFY(QFileInfo("foo").size() == 0); + +#ifdef Q_OS_WINRT + QDir::setCurrent(oldCur); +#endif } const int NumIterations = 5; @@ -1941,7 +1957,7 @@ void tst_QSettings::testNormalizedKey() void tst_QSettings::testEmptyData() { - QString filename(QDir::tempPath() + "/empty.ini"); + QString filename(settingsPath("empty.ini")); QFile::remove(filename); QVERIFY(!QFile::exists(filename)); @@ -2054,6 +2070,14 @@ void tst_QSettings::fromFile() { QFETCH(QSettings::Format, format); + // Sandboxed WinRT applications cannot write into the + // application directory. Hence reset the current + // directory +#ifdef Q_OS_WINRT + const QString oldCur = QDir::currentPath(); + QDir::setCurrent(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)); +#endif + QFile::remove("foo"); QVERIFY(!QFile::exists("foo")); @@ -2078,7 +2102,7 @@ void tst_QSettings::fromFile() QCOMPARE(settings2.value("alpha").toInt(), 2); settings1.sync(); -#if !defined(Q_OS_WIN) || defined(Q_OS_WINRT) +#if !defined(Q_OS_WIN) QVERIFY(QFile::exists("foo")); #endif QCOMPARE(settings1.value("alpha").toInt(), 2); @@ -2101,6 +2125,9 @@ void tst_QSettings::fromFile() QCOMPARE(settings1.value("gamma/foo.bar").toInt(), 4); QCOMPARE(settings1.allKeys().size(), 3); } +#ifdef Q_OS_WINRT + QDir::setCurrent(oldCur); +#endif } #ifdef QT_BUILD_INTERNAL |