File indexing completed on 2024-04-14 14:12:05
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 #include "test_ekos_filterwheel.h" 0009 0010 #if defined(HAVE_INDI) 0011 0012 #include "kstars_ui_tests.h" 0013 #include "test_ekos.h" 0014 #include "test_ekos_simulator.h" 0015 #include "ekos/profileeditor.h" 0016 #include "fitsviewer/fitsdata.h" 0017 #include "ekos/capture/capture.h" 0018 0019 TestEkosFilterWheel::TestEkosFilterWheel(QObject *parent) : QObject(parent) 0020 { 0021 } 0022 0023 void TestEkosFilterWheel::initTestCase() 0024 { 0025 KVERIFY_EKOS_IS_HIDDEN(); 0026 KTRY_OPEN_EKOS(); 0027 KVERIFY_EKOS_IS_OPENED(); 0028 0029 // Update simulator profile to use PHD2 as guider 0030 { 0031 bool isDone = false; 0032 Ekos::Manager * const ekos = Ekos::Manager::Instance(); 0033 QTimer::singleShot(1000, ekos, [&] 0034 { 0035 ProfileEditor* profileEditor = ekos->findChild<ProfileEditor*>("profileEditorDialog"); 0036 0037 // Create a test profile 0038 KTRY_PROFILEEDITOR_GADGET(QLineEdit, profileIN); 0039 profileIN->setText(testProfileName); 0040 QCOMPARE(profileIN->text(), testProfileName); 0041 0042 // Disable Port Selector 0043 KTRY_PROFILEEDITOR_GADGET(QCheckBox, portSelectorCheck); 0044 portSelectorCheck->setChecked(false); 0045 QCOMPARE(portSelectorCheck->isChecked(), false); 0046 0047 // Setting an item programmatically in a treeview combobox... 0048 KTRY_PROFILEEDITOR_TREE_COMBOBOX(mountCombo, "Telescope Simulator"); 0049 KTRY_PROFILEEDITOR_TREE_COMBOBOX(ccdCombo, "Guide Simulator"); 0050 KTRY_PROFILEEDITOR_TREE_COMBOBOX(filterCombo, "Filter Simulator"); 0051 0052 // Save the profile using the "Save" button 0053 QDialogButtonBox* buttons = profileEditor->findChild<QDialogButtonBox*>("dialogButtons"); 0054 QVERIFY(nullptr != buttons); 0055 QTest::mouseClick(buttons->button(QDialogButtonBox::Save), Qt::LeftButton); 0056 0057 isDone = true; 0058 }); 0059 0060 // Cancel the profile editor if test fails 0061 QTimer * closeDialog = new QTimer(this); 0062 closeDialog->setSingleShot(true); 0063 closeDialog->setInterval(5000); 0064 ekos->connect(closeDialog, &QTimer::timeout, [&] 0065 { 0066 ProfileEditor* profileEditor = ekos->findChild<ProfileEditor*>("profileEditorDialog"); 0067 if (profileEditor != nullptr) 0068 profileEditor->reject(); 0069 }); 0070 0071 // Click on "New profile" button, and let the async tests run on the modal dialog 0072 KTRY_EKOS_GADGET(QPushButton, addProfileB); 0073 QTRY_VERIFY_WITH_TIMEOUT(addProfileB->isEnabled(), 1000); 0074 QTest::mouseClick(addProfileB, Qt::LeftButton); 0075 0076 // Click handler returned, stop the timer closing the dialog on failure 0077 closeDialog->stop(); 0078 delete closeDialog; 0079 0080 // Verification of the first test step 0081 QVERIFY(isDone); 0082 } 0083 0084 // HACK: Reset clock to initial conditions 0085 //KHACK_RESET_EKOS_TIME(); 0086 } 0087 0088 void TestEkosFilterWheel::cleanupTestCase() 0089 { 0090 KTRY_EKOS_STOP_SIMULATORS(); 0091 KTRY_CLOSE_EKOS(); 0092 KVERIFY_EKOS_IS_HIDDEN(); 0093 } 0094 0095 void TestEkosFilterWheel::init() 0096 { 0097 // Start Ekos 0098 KTRY_EKOS_START_PROFILE(testProfileName); 0099 // Get manager instance 0100 Ekos::Manager * const ekos = Ekos::Manager::Instance(); 0101 0102 // Wait for Capture to come up, switch to capture tab 0103 QTRY_VERIFY_WITH_TIMEOUT(ekos->captureModule() != nullptr, 5000); 0104 KTRY_EKOS_GADGET(QTabWidget, toolsWidget); 0105 toolsWidget->setCurrentWidget(ekos->captureModule()); 0106 QTRY_COMPARE_WITH_TIMEOUT(toolsWidget->currentWidget(), ekos->captureModule(), 1000); 0107 } 0108 0109 void TestEkosFilterWheel::cleanup() 0110 { 0111 Ekos::Manager::Instance()->captureModule()->clearSequenceQueue(); 0112 KTRY_CAPTURE_GADGET(QTableWidget, queueTable); 0113 QTRY_VERIFY_WITH_TIMEOUT(queueTable->rowCount() == 0, 2000); 0114 } 0115 0116 QFileInfoList TestEkosFilterWheel::searchFITS(QDir const &dir) const 0117 { 0118 QFileInfoList list = dir.entryInfoList(QDir::Files); 0119 for (const auto &d : dir.entryList(QDir::NoDotAndDotDot | QDir::Dirs)) 0120 list.append(searchFITS(QDir(dir.path() + QDir::separator() + d))); 0121 return list; 0122 } 0123 0124 void TestEkosFilterWheel::testFilterWheelSync() 0125 { 0126 QTemporaryDir destination(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/test-XXXXXX"); 0127 QVERIFY(destination.isValid()); 0128 QVERIFY(destination.autoRemove()); 0129 KTRY_CAPTURE_ADD_LIGHT(0.5, 1, 0, "Green", destination.path()); 0130 0131 // Start capturing and wait for procedure to end (visual icon changing) 0132 KTRY_CAPTURE_GADGET(QPushButton, startB); 0133 QCOMPARE(startB->icon().name(), QString("media-playback-start")); 0134 KTRY_CAPTURE_CLICK(startB); 0135 QTRY_COMPARE_WITH_TIMEOUT(startB->icon().name(), QString("media-playback-start"), 30000); 0136 0137 QFileInfoList list = searchFITS(QDir(destination.path())); 0138 QVERIFY(!list.isEmpty()); 0139 0140 QString filepath = list.first().absoluteFilePath(); 0141 QScopedPointer<FITSData> data(new FITSData()); 0142 data->loadFromFile(filepath).waitForFinished(); 0143 0144 QVariant filter; 0145 QVERIFY(data->getRecordValue("FILTER", filter)); 0146 QVERIFY(filter == "Green"); 0147 } 0148 0149 QTEST_KSTARS_MAIN(TestEkosFilterWheel) 0150 0151 #endif // HAVE_INDI