From be28e096c5337b61a5e2f6e048ea297b2cc4b916 Mon Sep 17 00:00:00 2001 From: Benjamin Port Date: Tue, 17 Mar 2020 15:13:11 +0100 Subject: Add force save behavior to KEntryMap Summary: Fix the following bug, if an entry is set on HOME/.config/kdeglobals and on a specific config file like kcmfonts When you hit restore defaults button and apply, value will be not wrote on the specific file, but then the value is the one from kdeglobals This patch ensure we write the key to the specific configuration file on those case with an empty value. KConfig will take default value automatically Test Plan: Added a test to ensure flag is working Tested using some KCM to ensure all is working fine Reviewers: ervin, dfaure, meven, crossi, hchain Reviewed By: ervin, dfaure, meven Subscribers: kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D28128 --- autotests/kconfigtest.cpp | 27 +++++++++++++++++++++++++++ autotests/kconfigtest.h | 2 ++ 2 files changed, 29 insertions(+) (limited to 'autotests') diff --git a/autotests/kconfigtest.cpp b/autotests/kconfigtest.cpp index 736274c6..4d38b150 100644 --- a/autotests/kconfigtest.cpp +++ b/autotests/kconfigtest.cpp @@ -1949,3 +1949,30 @@ void KConfigTest::testNotify() QCOMPARE(otherWatcherSpy[0][0].value().name(), QStringLiteral("TopLevelGroup")); QCOMPARE(otherWatcherSpy[0][1].value(), QByteArrayList({"someGlobalEntry"})); } + +void KConfigTest::testKdeglobalsVsDefault() +{ + // Add testRestore key with global value in kdeglobals + KConfig glob(QStringLiteral("kdeglobals")); + KConfigGroup generalGlob(&glob, "General"); + generalGlob.writeEntry("testRestore", "global"); + QVERIFY(glob.sync()); + + KConfig local(QStringLiteral(TEST_SUBDIR "restorerc")); + KConfigGroup generalLocal(&local, "General"); + // Check if we get global and not the default value from cpp (defaultcpp) when reading data from restorerc + QCOMPARE(generalLocal.readEntry("testRestore", "defaultcpp"), "global"); + + // Add test restore key with restore value in restorerc file + generalLocal.writeEntry("testRestore", "restore"); + QVERIFY(local.sync()); + local.reparseConfiguration(); + // We expect to get the value from restorerc file + QCOMPARE(generalLocal.readEntry("testRestore", "defaultcpp"), "restore"); + + // Revert to default testRestore key and we expect to get default value and not the global one + generalLocal.revertToDefault("testRestore"); + local.sync(); + local.reparseConfiguration(); + QCOMPARE(generalLocal.readEntry("testRestore", "defaultcpp"), "defaultcpp"); +} diff --git a/autotests/kconfigtest.h b/autotests/kconfigtest.h index e97e4a5d..7617d0e7 100644 --- a/autotests/kconfigtest.h +++ b/autotests/kconfigtest.h @@ -73,6 +73,8 @@ private Q_SLOTS: void testThreads(); + void testKdeglobalsVsDefault(); + // should be last void testSyncOnExit(); }; -- cgit v1.2.1