File indexing completed on 2024-04-21 14:47:20
0001 #include "test_catalog_download.h" 0002 0003 #include "kstars_ui_tests.h" 0004 #include "test_kstars_startup.h" 0005 0006 #include "Options.h" 0007 #include <KNS3/DownloadWidget> 0008 #include <KNS3/Button> 0009 #include <KMessageBox> 0010 0011 TestCatalogDownload::TestCatalogDownload(QObject *parent): QObject(parent) 0012 { 0013 0014 } 0015 0016 void TestCatalogDownload::initTestCase() 0017 { 0018 KTELL_BEGIN(); 0019 } 0020 0021 void TestCatalogDownload::cleanupTestCase() 0022 { 0023 KTELL_END(); 0024 } 0025 0026 void TestCatalogDownload::init() 0027 { 0028 if (!KStars::Instance()->isStartedWithClockRunning()) 0029 { 0030 QVERIFY(KStarsData::Instance()->clock()); 0031 KStarsData::Instance()->clock()->start(); 0032 } 0033 } 0034 0035 void TestCatalogDownload::cleanup() 0036 { 0037 if (!KStars::Instance()->isStartedWithClockRunning()) 0038 KStarsData::Instance()->clock()->stop(); 0039 } 0040 0041 void TestCatalogDownload::testCatalogDownloadWhileUpdating() 0042 { 0043 KTELL("Zoom in enough so that updates are frequent"); 0044 double const previous_zoom = Options::zoomFactor(); 0045 KStars::Instance()->zoom(previous_zoom * 50); 0046 0047 // This timer looks for message boxes to close until stopped 0048 QTimer close_message_boxes; 0049 close_message_boxes.setInterval(500); 0050 QObject::connect(&close_message_boxes, &QTimer::timeout, &close_message_boxes, [&]() 0051 { 0052 QDialog * const dialog = qobject_cast <QDialog*> (QApplication::activeModalWidget()); 0053 if (dialog) 0054 { 0055 QList<QPushButton*> pb = dialog->findChildren<QPushButton*>(); 0056 QTest::mouseClick(pb[0], Qt::MouseButton::LeftButton); 0057 } 0058 }); 0059 0060 int const count = 6; 0061 for (int i = 0; i < count; i++) 0062 { 0063 QString step = QString("[%1/%2] ").arg(i).arg(count); 0064 KTELL(step + "Open the Download Dialog, wait for plugins to load"); 0065 volatile bool done = false; 0066 QTimer::singleShot(5000, [&]() 0067 { 0068 KTELL(step + "Change the first four catalogs installation state"); 0069 KNS3::DownloadWidget * d = KStars::Instance()->findChild<KNS3::DownloadWidget*>("DownloadWidget"); 0070 QList<QToolButton*> wl = d->findChildren<QToolButton*>(); 0071 if (wl.count() >= 8) 0072 { 0073 wl[1]->setFocus(); 0074 QTest::keyClick(wl[1], Qt::Key_Space); 0075 wl[3]->setFocus(); 0076 QTest::keyClick(wl[3], Qt::Key_Space); 0077 wl[5]->setFocus(); 0078 QTest::keyClick(wl[5], Qt::Key_Space); 0079 wl[7]->setFocus(); 0080 QTest::keyClick(wl[7], Qt::Key_Space); 0081 QTest::qWait(5000); 0082 } 0083 else 0084 { 0085 KTELL(step + "Failed to load XML providers!"); 0086 } 0087 KTELL(step + "Close the Download Dialog, accept all potentiel reinstalls"); 0088 close_message_boxes.start(); 0089 d->parentWidget()->close(); 0090 done = true; 0091 }); 0092 KStars::Instance()->action("get_data")->activate(QAction::Trigger); 0093 QTRY_VERIFY_WITH_TIMEOUT(done, 10000); 0094 close_message_boxes.stop(); 0095 0096 KTELL(step + "Wait a bit for pop-ups to appear"); 0097 QTest::qWait(5000); 0098 } 0099 0100 Options::setZoomFactor(previous_zoom); 0101 } 0102 0103 QTEST_KSTARS_MAIN(TestCatalogDownload)