File indexing completed on 2024-04-14 14:12:09
0001 /* KStars UI tests 0002 SPDX-FileCopyrightText: 2020 Eric Dejouhanet <eric.dejouhanet@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef TESTEKOSSCHEDULER_H 0008 #define TESTEKOSSCHEDULER_H 0009 0010 #include "config-kstars.h" 0011 0012 #if defined(HAVE_INDI) 0013 0014 #include <QObject> 0015 #include <QPushButton> 0016 #include <QComboBox> 0017 #include <QDoubleSpinBox> 0018 #include <QSpinBox> 0019 #include <QCheckBox> 0020 #include <QTest> 0021 0022 /** @brief Helper to retrieve a gadget in the Scheduler tab specifically. 0023 * @param klass is the class of the gadget to look for. 0024 * @param name is the gadget name to look for in the UI configuration. 0025 * @warning Fails the test if the gadget "name" of class "klass" does not exist in the Scheduler module 0026 */ 0027 #define KTRY_SCHEDULER_GADGET(klass, name) klass * const name = Ekos::Manager::Instance()->schedulerModule()->findChild<klass*>(#name); \ 0028 QVERIFY2(name != nullptr, QString(#klass " '%1' does not exist and cannot be used").arg(#name).toStdString().c_str()) 0029 0030 /** @brief Helper to click a button in the Scheduler tab specifically. 0031 * @param button is the gadget name of the button to look for in the UI configuration. 0032 * @warning Fails the test if the button is not currently enabled. 0033 */ 0034 #define KTRY_SCHEDULER_CLICK(button) do { \ 0035 bool clicked = false; \ 0036 QTimer::singleShot(100, Ekos::Manager::Instance(), [&]() { \ 0037 KTRY_SCHEDULER_GADGET(QPushButton, button); \ 0038 QVERIFY2(button->isEnabled(), QString("QPushButton '%1' is disabled and cannot be clicked").arg(#button).toStdString().c_str()); \ 0039 QTest::mouseClick(button, Qt::LeftButton); \ 0040 clicked = true; }); \ 0041 QTRY_VERIFY_WITH_TIMEOUT(clicked, 150); } while(false) 0042 0043 /** @brief Helper to set a string text into a QComboBox in the Scheduler module. 0044 * @param combobox is the gadget name of the QComboBox to look for in the UI configuration. 0045 * @param text is the string text to set in the gadget. 0046 * @note This is a contrived method to set a text into a QComboBox programmatically *and* emit the "activated" message. 0047 * @warning Fails the test if the name does not exist in the Scheduler UI or if the text cannot be set in the gadget. 0048 */ 0049 #define KTRY_SCHEDULER_COMBO_SET(combobox, text) do { \ 0050 KTRY_SCHEDULER_GADGET(QComboBox, combobox); \ 0051 int const cbIndex = combobox->findText(text); \ 0052 QVERIFY(0 <= cbIndex); \ 0053 combobox->setCurrentIndex(cbIndex); \ 0054 combobox->activated(cbIndex); \ 0055 QCOMPARE(combobox->currentText(), QString(text)); } while(false); 0056 0057 class TestEkosScheduler : public QObject 0058 { 0059 Q_OBJECT 0060 0061 public: 0062 explicit TestEkosScheduler(QObject *parent = nullptr); 0063 0064 private slots: 0065 void initTestCase(); 0066 void cleanupTestCase(); 0067 0068 void init(); 0069 void cleanup(); 0070 0071 void testScheduleManipulation_data(); 0072 void testScheduleManipulation(); 0073 }; 0074 0075 #endif // HAVE_INDI 0076 #endif // TESTEKOSSCHEDULER_H