summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qsettings/tst_qsettings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/io/qsettings/tst_qsettings.cpp')
-rw-r--r--tests/auto/corelib/io/qsettings/tst_qsettings.cpp146
1 files changed, 102 insertions, 44 deletions
diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp
index e7dae32256..77a60997a6 100644
--- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp
+++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp
@@ -1,40 +1,32 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the test suite of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL$
+** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
+** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-**
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -185,14 +177,14 @@ void tst_QSettings::getSetCheck()
QCOMPARE(true, obj1.fallbacksEnabled());
}
-#if defined(Q_OS_WINCE)
+#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();
+ QStringList entries = dir.entryList(QDir::AllEntries | QDir::NoDotAndDotDot);
foreach(QString name, entries) {
QString absolute = path + name;
if (QFileInfo(absolute).isDir())
@@ -210,7 +202,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));
@@ -343,7 +339,21 @@ void tst_QSettings::init()
system(QString("rm -fr %1 2> /dev/null").arg(settingsPath()).toLatin1());
#endif
+#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");
+#else
QFile::remove("foo");
+#endif
}
void tst_QSettings::cleanup()
@@ -553,7 +563,7 @@ void tst_QSettings::ctor()
} else {
caseSensitive = pathconf(QDir::currentPath().toLatin1().constData(), _PC_CASE_SENSITIVE);
}
-#elif defined(Q_OS_WIN32)
+#elif defined(Q_OS_WIN32) || defined(Q_OS_WINRT)
caseSensitive = false;
#endif
if (caseSensitive)
@@ -627,8 +637,8 @@ void tst_QSettings::ctor()
QCoreApplication::instance()->setOrganizationName("");
QCoreApplication::instance()->setApplicationName("");
QSettings settings;
-#ifdef Q_OS_MAC
- QEXPECT_FAIL("native", "Default settings on Mac are valid, despite organization domain, name, and app name being null", Continue);
+#if defined(Q_OS_MAC) || defined(Q_OS_WINRT)
+ QEXPECT_FAIL("native", "Default settings on Mac/WinRT are valid, despite organization domain, name, and app name being null", Continue);
#endif
QCOMPARE(settings.status(), QSettings::AccessError);
QCoreApplication::instance()->setOrganizationName("software.org");
@@ -642,8 +652,8 @@ void tst_QSettings::ctor()
}
QSettings settings(format, QSettings::UserScope, "", "");
-#ifdef Q_OS_MAC
- QEXPECT_FAIL("native", "Default settings on Mac are valid, despite organization domain, name, and app name being null", Continue);
+#if defined(Q_OS_MAC) || defined(Q_OS_WINRT)
+ QEXPECT_FAIL("native", "Default settings on Mac/WinRT are valid, despite organization domain, name, and app name being null", Continue);
#endif
QCOMPARE(settings.status(), QSettings::AccessError);
QSettings settings2(format, QSettings::UserScope, "software.org", "KillerAPP");
@@ -1748,14 +1758,18 @@ void tst_QSettings::testChildKeysAndGroups()
settings1.beginGroup("/alpha");
QCOMPARE(settings1.childKeys(), QStringList());
- QCOMPARE(settings1.childGroups(), QStringList() << "beta" << "gamma");
+ QStringList children = settings1.childGroups();
+ children.sort();
+ QCOMPARE(children, QStringList() << "beta" << "gamma");
settings1.beginGroup("/beta");
QCOMPARE(settings1.childKeys(), QStringList() << "geometry");
QCOMPARE(settings1.childGroups(), QStringList() << "geometry");
settings1.beginGroup("/geometry");
- QCOMPARE(settings1.childKeys(), QStringList() << "height" << "width" << "x" << "y");
+ children = settings1.childKeys();
+ children.sort();
+ QCOMPARE(children, QStringList() << "height" << "width" << "x" << "y");
QCOMPARE(settings1.childGroups(), QStringList());
settings1.beginGroup("/width");
@@ -1790,6 +1804,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"));
@@ -1815,6 +1834,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;
@@ -1927,7 +1950,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));
@@ -2057,12 +2080,20 @@ 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"));
QString path = "foo";
-#ifdef Q_OS_WIN
+#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
if (format == QSettings::NativeFormat)
path = "\\HKEY_CURRENT_USER\\Software\\foo";
#endif
@@ -2081,7 +2112,7 @@ void tst_QSettings::fromFile()
QCOMPARE(settings2.value("alpha").toInt(), 2);
settings1.sync();
-#ifndef Q_OS_WIN
+#if !defined(Q_OS_WIN)
QVERIFY(QFile::exists("foo"));
#endif
QCOMPARE(settings1.value("alpha").toInt(), 2);
@@ -2104,6 +2135,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
@@ -2912,7 +2946,9 @@ void tst_QSettings::childGroups()
}
settings.beginGroup("gamma");
- QCOMPARE(settings.childGroups(), QStringList() << "d" << "f");
+ QStringList childGroups = settings.childGroups();
+ childGroups.sort();
+ QCOMPARE(childGroups, QStringList() << "d" << "f");
settings.beginGroup("d");
QCOMPARE(settings.childGroups(), QStringList());
settings.endGroup();
@@ -2927,14 +2963,20 @@ void tst_QSettings::childGroups()
settings.endGroup();
settings.beginGroup("/omicron///h/i///");
- QCOMPARE(settings.childGroups(), QStringList() << "j" << "k");
+ childGroups = settings.childGroups();
+ childGroups.sort();
+ QCOMPARE(childGroups, QStringList() << "j" << "k");
settings.endGroup();
settings.beginGroup("////");
- QCOMPARE(settings.childGroups(), QStringList() << "alpha" << "gamma" << "omicron" << "zeta");
+ childGroups = settings.childGroups();
+ childGroups.sort();
+ QCOMPARE(childGroups, QStringList() << "alpha" << "gamma" << "omicron" << "zeta");
settings.endGroup();
- QCOMPARE(settings.childGroups(), QStringList() << "alpha" << "gamma" << "omicron" << "zeta");
+ childGroups = settings.childGroups();
+ childGroups.sort();
+ QCOMPARE(childGroups, QStringList() << "alpha" << "gamma" << "omicron" << "zeta");
}
}
#endif
@@ -2987,7 +3029,9 @@ void tst_QSettings::childKeys()
settings.endGroup();
settings.beginGroup("alpha");
- QCOMPARE(settings.childKeys(), QStringList() << "a" << "b" << "c");
+ QStringList childKeys = settings.childKeys();
+ childKeys.sort();
+ QCOMPARE(childKeys, QStringList() << "a" << "b" << "c");
settings.endGroup();
settings.beginGroup("d");
@@ -2999,10 +3043,14 @@ void tst_QSettings::childKeys()
settings.endGroup();
settings.beginGroup("////");
- QCOMPARE(settings.childKeys(), QStringList() << "alpha" << "beta" << "gamma");
+ childKeys = settings.childKeys();
+ childKeys.sort();
+ QCOMPARE(childKeys, QStringList() << "alpha" << "beta" << "gamma");
settings.endGroup();
- QCOMPARE(settings.childKeys(), QStringList() << "alpha" << "beta" << "gamma");
+ childKeys = settings.childKeys();
+ childKeys.sort();
+ QCOMPARE(childKeys, QStringList() << "alpha" << "beta" << "gamma");
}
}
#endif
@@ -3043,14 +3091,18 @@ void tst_QSettings::allKeys()
}
settings.beginGroup("gamma");
- QCOMPARE(settings.allKeys(), QStringList() << "d" << "d/e" << "f/g");
+ QStringList keys = settings.allKeys();
+ keys.sort();
+ QCOMPARE(keys, QStringList() << "d" << "d/e" << "f/g");
settings.beginGroup("d");
QCOMPARE(settings.allKeys(), QStringList() << "e");
settings.endGroup();
settings.endGroup();
settings.beginGroup("alpha");
- QCOMPARE(settings.allKeys(), QStringList() << "a" << "b" << "c");
+ keys = settings.allKeys();
+ keys.sort();
+ QCOMPARE(keys, QStringList() << "a" << "b" << "c");
settings.endGroup();
settings.beginGroup("d");
@@ -3058,14 +3110,20 @@ void tst_QSettings::allKeys()
settings.endGroup();
settings.beginGroup("/omicron///h/i///");
- QCOMPARE(settings.allKeys(), QStringList() << "j/x" << "k/y");
+ keys = settings.allKeys();
+ keys.sort();
+ QCOMPARE(keys, QStringList() << "j/x" << "k/y");
settings.endGroup();
settings.beginGroup("////");
- QCOMPARE(settings.allKeys(), allKeys);
+ keys = settings.allKeys();
+ keys.sort();
+ QCOMPARE(keys, allKeys);
settings.endGroup();
- QCOMPARE(settings.allKeys(), allKeys);
+ keys = settings.allKeys();
+ keys.sort();
+ QCOMPARE(keys, allKeys);
}
}
#endif
@@ -3280,7 +3338,7 @@ void tst_QSettings::rainersSyncBugOnMac()
{
QFETCH(QSettings::Format, format);
-#ifdef Q_OS_OSX
+#if defined(Q_OS_OSX) || defined(Q_OS_WINRT)
if (format == QSettings::NativeFormat)
QSKIP("OSX does not support direct reads from and writes to .plist files, due to caching and background syncing. See QTBUG-34899.");
#endif