aboutsummaryrefslogtreecommitdiff
path: root/autotests
diff options
context:
space:
mode:
authorAlexander Lohnau <alexander.lohnau@gmx.de>2021-09-19 20:02:50 +0200
committerAlexander Lohnau <alexander.lohnau@gmx.de>2021-10-11 18:11:27 +0200
commitf7754f2bb3db666e4bfb2b82af079828e0086b84 (patch)
treedb1120cab3fb234b0c4d9f55f626a93968ac3fa1 /autotests
parent13b79463dd80c84c7cf1c817c363e7747e4da034 (diff)
downloadkconfig-f7754f2bb3db666e4bfb2b82af079828e0086b84.tar.gz
kconfig-f7754f2bb3db666e4bfb2b82af079828e0086b84.tar.bz2
Create utility method for moving entries from one group to another
This will become especially useful when moving state data from the config file to a dedicated state data file. Task: https://phabricator.kde.org/T12549
Diffstat (limited to 'autotests')
-rw-r--r--autotests/kconfigtest.cpp41
-rw-r--r--autotests/kconfigtest.h2
2 files changed, 43 insertions, 0 deletions
diff --git a/autotests/kconfigtest.cpp b/autotests/kconfigtest.cpp
index c3a68e42..00e7bbf0 100644
--- a/autotests/kconfigtest.cpp
+++ b/autotests/kconfigtest.cpp
@@ -1898,6 +1898,47 @@ void KConfigTest::testNewlines()
#endif
}
+void KConfigTest::testMoveValuesTo()
+{
+ QTemporaryFile file;
+ QVERIFY(file.open());
+ // Prepare kdeglobals
+ {
+ KConfig glob(QStringLiteral("kdeglobals"));
+ KConfigGroup general(&glob, "TestGroup");
+ general.writeEntry("GlobalKey", "PlsDeleteMe");
+ QVERIFY(glob.sync());
+ }
+
+ KConfigGroup grp = KSharedConfig::openConfig(file.fileName())->group("TestGroup");
+
+ grp.writeEntry("test1", "first_value");
+ grp.writeEntry("test_empty", "");
+ grp.writeEntry("other", "other_value");
+ grp.writePathEntry("my_path", QStringLiteral("~/somepath"));
+ // because this key is from the global file it should be explicitly deleted
+ grp.deleteEntry("GlobalKey");
+
+ QTemporaryFile targetFile;
+ QVERIFY(targetFile.open());
+ targetFile.close();
+ KConfigGroup targetGroup = KSharedConfig::openConfig(targetFile.fileName(), KConfig::SimpleConfig)->group("MoveToGroup");
+
+ grp.moveValuesTo({"test1", "test_empty", "does_not_exist", "my_path", "GlobalKey"}, targetGroup);
+ QVERIFY(grp.config()->isDirty());
+ QVERIFY(targetGroup.config()->isDirty());
+
+ QCOMPARE(grp.keyList(), QStringList{QStringLiteral("other")});
+ QStringList expectedKeyList{QStringLiteral("my_path"), QStringLiteral("test1"), QStringLiteral("test_empty")};
+ QCOMPARE(targetGroup.keyList(), expectedKeyList);
+ QCOMPARE(targetGroup.readEntry("test1"), QStringLiteral("first_value"));
+
+ targetGroup.sync();
+ QFile targetReadFile(targetFile.fileName());
+ targetReadFile.open(QFile::ReadOnly);
+ QVERIFY(targetReadFile.readAll().contains(QByteArray("my_path[$e]=~/somepath")));
+}
+
void KConfigTest::testXdgListEntry()
{
QTemporaryFile file;
diff --git a/autotests/kconfigtest.h b/autotests/kconfigtest.h
index 9d519eda..f716bd70 100644
--- a/autotests/kconfigtest.h
+++ b/autotests/kconfigtest.h
@@ -64,6 +64,8 @@ private Q_SLOTS:
void testQStringUtf8_data();
void testQStringUtf8();
+ void testMoveValuesTo();
+
void testSubGroup();
void testAddConfigSources();
void testWriteOnSync();