aboutsummaryrefslogtreecommitdiff
path: root/autotests/kconfig_compiler
diff options
context:
space:
mode:
Diffstat (limited to 'autotests/kconfig_compiler')
-rw-r--r--autotests/kconfig_compiler/CMakeLists.txt9
-rw-r--r--autotests/kconfig_compiler/test_state_config.kcfg14
-rw-r--r--autotests/kconfig_compiler/test_state_config.kcfgc6
-rw-r--r--autotests/kconfig_compiler/test_state_config_main.cpp41
4 files changed, 70 insertions, 0 deletions
diff --git a/autotests/kconfig_compiler/CMakeLists.txt b/autotests/kconfig_compiler/CMakeLists.txt
index 2a4b343b..4641c0e0 100644
--- a/autotests/kconfig_compiler/CMakeLists.txt
+++ b/autotests/kconfig_compiler/CMakeLists.txt
@@ -172,6 +172,15 @@ target_link_libraries(test13 KF5::ConfigGui)
########### next target ###############
+set(test_state_config_SRCS test_state_config_main.cpp)
+
+gen_kcfg_test_source(test_state_config test_state_config_SRCS GENERATE_MOC)
+
+ecm_add_test(TEST_NAME test_state_config ${test_state_config_SRCS})
+target_link_libraries(test_state_config KF5::ConfigGui Qt5::Test)
+
+########### next target ###############
+
set(test_emptyentries_SRCS test_emptyentries_main.cpp )
gen_kcfg_test_source(test_emptyentries test_emptyentries_SRCS GENERATE_MOC)
diff --git a/autotests/kconfig_compiler/test_state_config.kcfg b/autotests/kconfig_compiler/test_state_config.kcfg
new file mode 100644
index 00000000..9c9e96c3
--- /dev/null
+++ b/autotests/kconfig_compiler/test_state_config.kcfg
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
+ http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
+ <kcfgfile name="test_statedatarc" stateConfig="true"/>
+
+ <group name="General">
+ <entry type="Int" key="SomeStateData">
+ <default>0</default>
+ </entry>
+ </group>
+
+</kcfg>
diff --git a/autotests/kconfig_compiler/test_state_config.kcfgc b/autotests/kconfig_compiler/test_state_config.kcfgc
new file mode 100644
index 00000000..35e2de7d
--- /dev/null
+++ b/autotests/kconfig_compiler/test_state_config.kcfgc
@@ -0,0 +1,6 @@
+# Code generation options for kconfig_compiler_kf5
+File=test_state_config.kcfg
+ClassName=MyStateConfig
+Singleton=false
+Mutators=true
+ItemAccessors=true
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"