aboutsummaryrefslogtreecommitdiff
path: root/autotests/kconfig_compiler/test_state_config_main.cpp
diff options
context:
space:
mode:
authorAlexander Lohnau <alexander.lohnau@gmx.de>2021-09-14 07:30:32 +0200
committerAlexander Lohnau <alexander.lohnau@gmx.de>2021-09-19 07:50:10 +0200
commit0b0a4464fb3d1145eb612b1ab7edacfa9581c8c9 (patch)
treedb94f2c4daba14f23e13aa65d55a05257f86ab41 /autotests/kconfig_compiler/test_state_config_main.cpp
parent782750149a0819053d47960fb144f17b7c719d13 (diff)
downloadkconfig-0b0a4464fb3d1145eb612b1ab7edacfa9581c8c9.tar.gz
kconfig-0b0a4464fb3d1145eb612b1ab7edacfa9581c8c9.tar.bz2
Allow KConfigXT to use KSharedConfig::openStateConfig
Otherwise we force consumers to use the config location for state data, which is what we are trying to avoid. Task: https://phabricator.kde.org/T12549
Diffstat (limited to 'autotests/kconfig_compiler/test_state_config_main.cpp')
-rw-r--r--autotests/kconfig_compiler/test_state_config_main.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/autotests/kconfig_compiler/test_state_config_main.cpp b/autotests/kconfig_compiler/test_state_config_main.cpp
new file mode 100644
index 00000000..07044bb5
--- /dev/null
+++ b/autotests/kconfig_compiler/test_state_config_main.cpp
@@ -0,0 +1,41 @@
+/*
+ SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de>
+
+ SPDX-License-Identifier: MIT
+*/
+
+#include "test_state_config.h"
+#include <QTest>
+
+class TestStateConfig : public QObject
+{
+ Q_OBJECT
+
+private Q_SLOTS:
+ void testStateConfig()
+ {
+ auto stateConfig = KSharedConfig::openStateConfig(QStringLiteral("test_statedatarc"));
+
+ // Clean the group at every start
+ stateConfig->deleteGroup("General");
+ stateConfig->sync();
+
+ // It should have the default value
+ QCOMPARE(MyStateConfig().someStateData(), 0);
+
+ // the updated value should be read from the generated config class
+ stateConfig->group("General").writeEntry("SomeStateData", 1);
+ QCOMPARE(MyStateConfig().someStateData(), 1);
+
+ // Make sure writing the value works as expected
+ MyStateConfig cfg;
+ cfg.setSomeStateData(2);
+ QVERIFY(cfg.isSaveNeeded());
+ cfg.save();
+ stateConfig->reparseConfiguration();
+ QCOMPARE(stateConfig->group("General").readEntry("SomeStateData", -1), 2);
+ }
+};
+QTEST_MAIN(TestStateConfig)
+
+#include "test_state_config_main.moc"