diff options
Diffstat (limited to 'autotests')
-rw-r--r-- | autotests/kconfigtest.cpp | 41 | ||||
-rw-r--r-- | autotests/kconfigtest.h | 2 |
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(); |