File indexing completed on 2024-05-12 15:34:04
0001 /* 0002 SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de> 0003 0004 SPDX-License-Identifier: MIT 0005 */ 0006 0007 #include "test_state_config.h" 0008 #include <QTest> 0009 0010 class TestStateConfig : public QObject 0011 { 0012 Q_OBJECT 0013 0014 private Q_SLOTS: 0015 void testStateConfig() 0016 { 0017 auto stateConfig = KSharedConfig::openStateConfig(QStringLiteral("test_statedatarc")); 0018 0019 // Clean the group at every start 0020 stateConfig->deleteGroup("General"); 0021 stateConfig->sync(); 0022 0023 // It should have the default value 0024 QCOMPARE(MyStateConfig().someStateData(), 0); 0025 0026 // the updated value should be read from the generated config class 0027 stateConfig->group("General").writeEntry("SomeStateData", 1); 0028 QCOMPARE(MyStateConfig().someStateData(), 1); 0029 0030 // Make sure writing the value works as expected 0031 MyStateConfig cfg; 0032 cfg.setSomeStateData(2); 0033 QVERIFY(cfg.isSaveNeeded()); 0034 cfg.save(); 0035 stateConfig->reparseConfiguration(); 0036 QCOMPARE(stateConfig->group("General").readEntry("SomeStateData", -1), 2); 0037 } 0038 }; 0039 QTEST_MAIN(TestStateConfig) 0040 0041 #include "test_state_config_main.moc"