File indexing completed on 2024-05-19 05:29:55
0001 /* 0002 SPDX-FileCopyrightText: 2023 Nicolas Fella <nicolas.fella@gmx.de> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include <QTest> 0008 0009 #include "globalshortcutsregistry.h" 0010 0011 class MigrateConfigTest : public QObject 0012 { 0013 Q_OBJECT 0014 0015 private Q_SLOTS: 0016 0017 void compareGroups(const KConfigGroup &a, const KConfigGroup &b) 0018 { 0019 for (auto [key, value] : a.entryMap().asKeyValueRange()) { 0020 QCOMPARE(value, b.readEntry(key)); 0021 } 0022 0023 for (auto [key, value] : b.entryMap().asKeyValueRange()) { 0024 QCOMPARE(value, a.readEntry(key)); 0025 } 0026 } 0027 0028 void compareGroupList(const KConfigBase &a, const KConfigBase &b) 0029 { 0030 QCOMPARE(a.groupList(), b.groupList()); 0031 0032 const QStringList groups = a.groupList(); 0033 for (const QString &group : groups) { 0034 compareGroups(a.group(group), b.group(group)); 0035 } 0036 } 0037 0038 void testMigrate() 0039 { 0040 QStandardPaths::setTestModeEnabled(true); 0041 qunsetenv("XDG_DATA_DIRS"); 0042 0043 QDir configDir(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)); 0044 configDir.mkpath(QStringLiteral(".")); 0045 configDir.remove(QStringLiteral("kglobalshortcutsrc")); 0046 0047 QDir dataDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)); 0048 dataDir.mkpath(QStringLiteral("kglobalaccel")); 0049 0050 QFile::copy(QFINDTESTDATA("kglobalshortcutsrc"), 0051 QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1String("/kglobalshortcutsrc")); 0052 0053 QFile::copy(QFINDTESTDATA("org.kde.test.desktop"), 0054 QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kglobalaccel/org.kde.test.desktop")); 0055 0056 // Creating the registry will migrate the shortcut config 0057 GlobalShortcutsRegistry registry; 0058 0059 // Compare actual with expected config 0060 KConfig actual(QStringLiteral("kglobalshortcutsrc")); 0061 KConfig expected(QFINDTESTDATA("kglobalshortcutsrc.expected")); 0062 0063 compareGroupList(actual, expected); 0064 compareGroupList(actual.group(QStringLiteral("services")), expected.group(QStringLiteral("services"))); 0065 } 0066 }; 0067 0068 QTEST_MAIN(MigrateConfigTest) 0069 0070 #include "migrateconfigtest.moc"