forked from qt-creator/qt-creator
SettingsAccessor: Do not change data on invalid upgrade attempts
Make sure that the input data is returned unchanged if an invalid update attempt is attempted. Update tests accordingly. Change-Id: If5c410bf1a757f984593bda871763af64d8dd972 Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
@@ -353,8 +353,7 @@ bool SettingsAccessor::isValidVersionAndId(const int version, const QByteArray &
|
||||
QVariantMap SettingsAccessor::upgradeSettings(const QVariantMap &data) const
|
||||
{
|
||||
const int version = versionFromMap(data);
|
||||
|
||||
if (data.isEmpty())
|
||||
if (!isValidVersionAndId(version, settingsIdFromMap(data)))
|
||||
return data;
|
||||
|
||||
QVariantMap result;
|
||||
@@ -363,11 +362,7 @@ QVariantMap SettingsAccessor::upgradeSettings(const QVariantMap &data) const
|
||||
else
|
||||
result = data;
|
||||
|
||||
const int toVersion = currentVersion();
|
||||
if (version >= toVersion || version < d->firstVersion())
|
||||
return result;
|
||||
|
||||
for (int i = version; i < toVersion; ++i) {
|
||||
for (int i = version; i < currentVersion(); ++i) {
|
||||
VersionUpgrader *upgrader = d->upgrader(i);
|
||||
QTC_CHECK(upgrader && upgrader->version() == i);
|
||||
result = upgrader->upgrade(result);
|
||||
|
@@ -331,16 +331,8 @@ void tst_SettingsAccessor::upgradeSettings_invalidId()
|
||||
|
||||
const QVariantMap result = accessor.upgradeSettings(input);
|
||||
|
||||
// "OriginalVersion" was added.
|
||||
for (auto it = result.cbegin(); it != result.cend(); ++it) {
|
||||
if (it.key() == "OriginalVersion")
|
||||
QCOMPARE(it.value().toInt(), startVersion);
|
||||
else if (input.contains(it.key())) // extra settings pass through unchanged!
|
||||
QCOMPARE(it.value(), input.value(it.key()));
|
||||
else
|
||||
QVERIFY2(false, "Unexpected value found in upgraded result!");
|
||||
}
|
||||
QCOMPARE(result.size(), input.size() + 1); // OriginalVersion was added
|
||||
// Data is unchanged
|
||||
QCOMPARE(result, input);
|
||||
}
|
||||
|
||||
void tst_SettingsAccessor::upgradeSettings_tooOld()
|
||||
@@ -351,16 +343,8 @@ void tst_SettingsAccessor::upgradeSettings_tooOld()
|
||||
|
||||
const QVariantMap result = accessor.upgradeSettings(input);
|
||||
|
||||
// "OriginalVersion" was added.
|
||||
for (auto it = result.cbegin(); it != result.cend(); ++it) {
|
||||
if (it.key() == "OriginalVersion")
|
||||
QCOMPARE(it.value().toInt(), startVersion);
|
||||
else if (input.contains(it.key())) // extra settings pass through unchanged!
|
||||
QCOMPARE(it.value(), input.value(it.key()));
|
||||
else
|
||||
QVERIFY2(false, "Unexpected value found in upgraded result!");
|
||||
}
|
||||
QCOMPARE(result.size(), input.size() + 1); // OriginalVersion was added
|
||||
// Data is unchanged
|
||||
QCOMPARE(result, input);
|
||||
}
|
||||
|
||||
void tst_SettingsAccessor::upgradeSettings_tooNew()
|
||||
@@ -371,16 +355,8 @@ void tst_SettingsAccessor::upgradeSettings_tooNew()
|
||||
|
||||
const QVariantMap result = accessor.upgradeSettings(input);
|
||||
|
||||
// "OriginalVersion" was added.
|
||||
for (auto it = result.cbegin(); it != result.cend(); ++it) {
|
||||
if (it.key() == "OriginalVersion")
|
||||
QCOMPARE(it.value().toInt(), startVersion);
|
||||
else if (input.contains(it.key())) // extra settings pass through unchanged!
|
||||
QCOMPARE(it.value(), input.value(it.key()));
|
||||
else
|
||||
QVERIFY2(false, "Unexpected value found in upgraded result!");
|
||||
}
|
||||
QCOMPARE(result.size(), input.size() + 1); // OriginalVersion was added
|
||||
// Data is unchanged
|
||||
QCOMPARE(result, input);
|
||||
}
|
||||
|
||||
void tst_SettingsAccessor::upgradeSettings_oneStep()
|
||||
|
Reference in New Issue
Block a user