File indexing completed on 2024-12-22 04:14:01
0001 /* 0002 * SPDX-FileCopyrightText: 2019 Boudewijn Rempt <boud@kde.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "KisDialogStateSaverTest.h" 0008 #include <simpletest.h> 0009 #include <KisDialogStateSaver.h> 0010 #include <QWidget> 0011 #include <ksharedconfig.h> 0012 #include <kconfiggroup.h> 0013 0014 0015 void KisDialogStateSaverTest::testSave() 0016 { 0017 QWidget w; 0018 Ui::DialogSaverTestWidget page; 0019 page.setupUi(&w); 0020 0021 page.lineEdit->setText("test"); 0022 page.spinBox->setValue(5); 0023 page.doubleSpinBox->setValue(3.0); 0024 page.verticalSlider->setValue(10); 0025 page.checkBox->setChecked(true); 0026 KisDialogStateSaver::saveState(&w, "StateSaverTest"); 0027 KConfigGroup group(KSharedConfig::openConfig(), "StateSaverTest"); 0028 QCOMPARE(group.readEntry("lineEdit", QString()), QString("test")); 0029 QCOMPARE(group.readEntry("spinBox", 0), 5); 0030 QCOMPARE(group.readEntry("doubleSpinBox", 0.0), 3.0); 0031 QCOMPARE(group.readEntry("verticalSlider", 0), 10); 0032 QCOMPARE(group.readEntry("checkBox", false), true); 0033 } 0034 0035 void KisDialogStateSaverTest::testRestore() 0036 { 0037 QWidget w; 0038 Ui::DialogSaverTestWidget page; 0039 page.setupUi(&w); 0040 QMap<QString, QVariant> overrideMap; 0041 0042 overrideMap["spinBox"] = QVariant::fromValue<int>(10); 0043 0044 KisDialogStateSaver::restoreState(&w, "StateSaverTest", overrideMap); 0045 0046 QCOMPARE(page.lineEdit->text(), QString("test")); 0047 QCOMPARE(page.spinBox->value(), 10); 0048 QCOMPARE(page.doubleSpinBox->value(), 3.0); 0049 QCOMPARE(page.verticalSlider->value(), 10); 0050 QCOMPARE(page.checkBox->isChecked(), true); 0051 0052 } 0053 0054 0055 SIMPLE_TEST_MAIN(KisDialogStateSaverTest)