File indexing completed on 2024-03-24 15:18:36
0001 /* KStars UI tests 0002 Copyright (C) 2020 0003 Eric Dejouhanet <eric.dejouhanet@gmail.com> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef TestEkosFilterWheel_H 0009 #define TestEkosFilterWheel_H 0010 0011 #include "config-kstars.h" 0012 0013 #if defined(HAVE_INDI) 0014 0015 #include <QObject> 0016 #include <QPushButton> 0017 #include <QComboBox> 0018 #include <QDoubleSpinBox> 0019 #include <QSpinBox> 0020 #include <QCheckBox> 0021 #include <QTest> 0022 0023 /** @brief Helper to show the Capture tab 0024 */ 0025 #define KTRY_CAPTURE_SHOW() do { \ 0026 QTRY_VERIFY_WITH_TIMEOUT(Ekos::Manager::Instance()->captureModule() != nullptr, 5000); \ 0027 KTRY_EKOS_GADGET(QTabWidget, toolsWidget); \ 0028 toolsWidget->setCurrentWidget(Ekos::Manager::Instance()->captureModule()); \ 0029 QTRY_COMPARE_WITH_TIMEOUT(toolsWidget->currentWidget(), Ekos::Manager::Instance()->captureModule(), 5000); \ 0030 QTRY_VERIFY_WITH_TIMEOUT(!Ekos::Manager::Instance()->captureModule()->camera().isEmpty(), 5000); } while (false) 0031 0032 /** @brief Helper to retrieve a gadget in the Capture tab specifically. 0033 * @param klass is the class of the gadget to look for. 0034 * @param name is the gadget name to look for in the UI configuration. 0035 * @warning Fails the test if the gadget "name" of class "klass" does not exist in the Capture module 0036 */ 0037 #define KTRY_CAPTURE_GADGET(klass, name) klass * const name = Ekos::Manager::Instance()->captureModule()->findChild<klass*>(#name); \ 0038 QVERIFY2(name != nullptr, QString(#klass " '%1' does not exist and cannot be used").arg(#name).toStdString().c_str()) 0039 0040 /** @brief Helper to click a button in the Capture tab specifically. 0041 * @param button is the gadget name of the button to look for in the UI configuration. 0042 * @warning Fails the test if the button is not currently enabled. 0043 */ 0044 #define KTRY_CAPTURE_CLICK(button) do { \ 0045 QTimer::singleShot(100, Ekos::Manager::Instance(), []() { \ 0046 KTRY_CAPTURE_GADGET(QPushButton, button); \ 0047 QVERIFY2(button->isEnabled(), QString("QPushButton '%1' is disabled and cannot be clicked").arg(#button).toStdString().c_str()); \ 0048 QTest::mouseClick(button, Qt::LeftButton); }); \ 0049 QTest::qWait(200); } while(false) 0050 0051 /** @brief Helper to set a string text into a QComboBox in the Capture module. 0052 * @param combobox is the gadget name of the QComboBox to look for in the UI configuration. 0053 * @param text is the string text to set in the gadget. 0054 * @note This is a contrived method to set a text into a QComboBox programmatically *and* emit the "activated" message. 0055 * @warning Fails the test if the name does not exist in the Capture UI or if the text cannot be set in the gadget. 0056 */ 0057 #define KTRY_CAPTURE_COMBO_SET(combobox, text) { \ 0058 int __ktry_combo_iter__=0; \ 0059 do { \ 0060 KTRY_CAPTURE_GADGET(QComboBox, combobox); \ 0061 int const cbIndex = combobox->findText(text); \ 0062 if (cbIndex >= 0) { \ 0063 combobox->setCurrentIndex(cbIndex); \ 0064 combobox->activated(cbIndex); \ 0065 QCOMPARE(combobox->currentText(), QString(text)); \ 0066 break; \ 0067 } else { \ 0068 QVERIFY(__ktry_combo_iter__++ < 3); \ 0069 QTest::qWait(2000); \ 0070 } \ 0071 } while(true);} 0072 0073 /** @brief Helper to add a Light frame to a Capture job. 0074 * @param exposure is the exposure duration. 0075 * @param count is the number of exposures to execute. 0076 * @param delay is the delay after exposure. 0077 * @param filter is the filter name to set. 0078 * @param destination is the folder to store fames to. 0079 */ 0080 #define KTRY_CAPTURE_ADD_LIGHT(exposure, count, delay, filter, destination) do { \ 0081 KTRY_CAPTURE_GADGET(QTableWidget, queueTable); \ 0082 int const jcount = queueTable->rowCount(); \ 0083 KTRY_CAPTURE_GADGET(QDoubleSpinBox, captureExposureN); \ 0084 captureExposureN->setValue((double)(exposure)); \ 0085 KTRY_CAPTURE_GADGET(QSpinBox, captureCountN); \ 0086 captureCountN->setValue((int)(count)); \ 0087 KTRY_CAPTURE_GADGET(QSpinBox, captureDelayN); \ 0088 captureDelayN->setValue((int)(delay)); \ 0089 KTRY_CAPTURE_GADGET(QComboBox, captureTypeS); \ 0090 KTRY_CAPTURE_COMBO_SET(captureTypeS, "Light"); \ 0091 KTRY_CAPTURE_GADGET(QComboBox, captureEncodingS); \ 0092 KTRY_CAPTURE_COMBO_SET(captureEncodingS, "FITS"); \ 0093 KTRY_CAPTURE_GADGET(QComboBox, FilterPosCombo); \ 0094 KTRY_CAPTURE_COMBO_SET(FilterPosCombo, (filter)); \ 0095 KTRY_CAPTURE_GADGET(QLineEdit, fileDirectoryT); \ 0096 fileDirectoryT->setText(destination); \ 0097 KTRY_CAPTURE_CLICK(addToQueueB); \ 0098 QTRY_VERIFY_WITH_TIMEOUT(queueTable->rowCount() == (jcount+1), 1000); } while(false); 0099 0100 class TestEkosFilterWheel : public QObject 0101 { 0102 Q_OBJECT 0103 0104 public: 0105 explicit TestEkosFilterWheel(QObject *parent = nullptr); 0106 0107 protected: 0108 QString testProfileName { "filter_sync_test_profile" }; 0109 private: 0110 QFileInfoList searchFITS(QDir const &dir) const; 0111 0112 private slots: 0113 void initTestCase(); 0114 void cleanupTestCase(); 0115 0116 void init(); 0117 void cleanup(); 0118 0119 /** @brief Test the filter wheel is set in ACTIVE_DEVICE and generated FITS header contains the matching filter. */ 0120 void testFilterWheelSync(); 0121 0122 }; 0123 0124 #endif // HAVE_INDI 0125 #endif // TestEkosFilterWheel_H