aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@qt.io>2017-12-12 17:38:23 +0100
committerTobias Hunger <tobias.hunger@qt.io>2018-02-14 13:23:33 +0000
commitb95bbe1d57d5c55d714fae0a094b149faa02432c (patch)
tree280ac9048ddb4035df4c24b29a93237de223f746 /tests/auto
parent9ffd52f9c54a95ad280ee70275ed1e06272add10 (diff)
SettingsAccessor: Extract functionality to merge settings
Move functionality related to merging settings into MergingSettingsAccessor, move code specific to the .user-files into UserFileAccessor. Remove SettingsAccessor class, now that all code has been moved out of it. This patch changes the merge mechanism a bit: It used to upgrade the user and tha shared file to the higher version of these two, merge, and then upgrade the merged result to the newest version. Now it upgrades both the user as well as the shared file to the newest version and only merges afterwards. Change-Id: I2a1605cbe9b9fb1404fcfa9954a9f3410da0abb1 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/utils/settings/tst_settings.cpp33
1 files changed, 26 insertions, 7 deletions
diff --git a/tests/auto/utils/settings/tst_settings.cpp b/tests/auto/utils/settings/tst_settings.cpp
index 43af7714ea6..a0e2870b0bc 100644
--- a/tests/auto/utils/settings/tst_settings.cpp
+++ b/tests/auto/utils/settings/tst_settings.cpp
@@ -67,18 +67,38 @@ public:
// BasicTestSettingsAccessor:
// --------------------------------------------------------------------
-class BasicTestSettingsAccessor : public Utils::SettingsAccessor
+class BasicTestSettingsAccessor : public Utils::MergingSettingsAccessor
{
public:
BasicTestSettingsAccessor(const Utils::FileName &baseName = Utils::FileName::fromString("/foo/bar"),
const QByteArray &id = QByteArray(TESTACCESSOR_DEFAULT_ID)) :
- Utils::SettingsAccessor(std::make_unique<Utils::VersionedBackUpStrategy>(this),
- baseName, "TestData", TESTACCESSOR_DN, TESTACCESSOR_APPLICATION_DN)
+ Utils::MergingSettingsAccessor(std::make_unique<Utils::VersionedBackUpStrategy>(this),
+ "TestData", TESTACCESSOR_DN, TESTACCESSOR_APPLICATION_DN)
{
setSettingsId(id);
+ setBaseFilePath(baseName);
}
- using Utils::SettingsAccessor::addVersionUpgrader;
+ SettingsMergeResult merge(const SettingsMergeData &global,
+ const SettingsMergeData &local) const final
+ {
+ Q_UNUSED(global);
+
+ const QString key = local.key;
+ const QVariant main = local.main.value(key);
+ const QVariant secondary = local.secondary.value(key);
+
+ if (isHouseKeepingKey(key))
+ return qMakePair(key, main);
+
+ if (main.isNull() && secondary.isNull())
+ return nullopt;
+ if (!main.isNull())
+ return qMakePair(key, main);
+ return qMakePair(key, secondary);
+ }
+
+ using Utils::MergingSettingsAccessor::addVersionUpgrader;
};
// --------------------------------------------------------------------
@@ -98,7 +118,7 @@ public:
}
// Make methods public for the tests:
- using Utils::SettingsAccessor::upgradeSettings;
+ using Utils::MergingSettingsAccessor::upgradeSettings;
};
// --------------------------------------------------------------------
@@ -607,7 +627,7 @@ void tst_SettingsAccessor::saveSettings()
QVERIFY(accessor.saveSettings(data, nullptr));
PersistentSettingsReader reader;
- QVERIFY(reader.load(testPath(m_tempDir, "saveSettings.user")));
+ QVERIFY(reader.load(testPath(m_tempDir, "saveSettings")));
const QVariantMap read = reader.restoreValues();
@@ -628,7 +648,6 @@ void tst_SettingsAccessor::loadSettings()
const QVariantMap data = versionedMap(6, "loadSettings", generateExtraData());
const Utils::FileName path = testPath(m_tempDir, "loadSettings");
Utils::FileName fullPath = path;
- fullPath.appendString(".user");
PersistentSettingsWriter writer(fullPath, "TestProfile");
QString errorMessage;