File indexing completed on 2024-05-05 07:53:50
0001 /* 0002 SPDX-FileCopyrightText: 2022 Nicolas Fella <nicolas.fella@gmx.de> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include <KCMultiDialog> 0008 0009 #include <QObject> 0010 #include <QTest> 0011 #include <QTimer> 0012 0013 class KCMultiDialogTest : public QObject 0014 { 0015 Q_OBJECT 0016 const KPluginMetaData fakekcm{QStringLiteral("plasma/kcms/systemsettings_qwidgets/fakekcm")}; 0017 void sleep(int ms) 0018 { 0019 QEventLoop l; 0020 QTimer::singleShot(ms, this, [&l]() { 0021 l.quit(); 0022 }); 0023 l.exec(); 0024 } 0025 private Q_SLOTS: 0026 void testClear() 0027 { 0028 KCMultiDialog dialog; 0029 dialog.addModule(fakekcm); 0030 // Just verify that it doesn't crash 0031 dialog.clear(); 0032 } 0033 void testLoadKcm() 0034 { 0035 KCMultiDialog dialog; 0036 // Simple property to check how often the load method was called 0037 QCOMPARE(dialog.property("loadcalled").toInt(), 0); 0038 0039 // For the first KCM, it should be called once 0040 auto page1 = dialog.addModule(fakekcm); 0041 sleep(1); 0042 0043 // For the newly instantiated KCM, load should be called after we change the page 0044 // Because it does not have a higher weight, it is not shown initially 0045 auto page2 = dialog.addModule(fakekcm); 0046 dialog.setCurrentPage(page2); 0047 sleep(1); 0048 QCOMPARE(dialog.property("loadcalled").toInt(), 2); 0049 0050 // Go back to page 1, load should not be called again 0051 dialog.setCurrentPage(page1); 0052 sleep(1); 0053 QCOMPARE(dialog.property("loadcalled").toInt(), 2); 0054 } 0055 }; 0056 0057 QTEST_MAIN(KCMultiDialogTest) 0058 #include "kcmultidialogtest.moc"