File indexing completed on 2024-04-28 11:25:57
0001 /* KStars UI tests 0002 SPDX-FileCopyrightText: 2018, 2020 Csaba Kertesz <csaba.kertesz@gmail.com> 0003 SPDX-FileCopyrightText: Jasem Mutlaq <knro@ikarustech.com> 0004 SPDX-FileCopyrightText: Eric Dejouhanet <eric.dejouhanet@gmail.com> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef TEST_EKOS_H 0010 #define TEST_EKOS_H 0011 0012 #include "config-kstars.h" 0013 0014 #if defined(HAVE_INDI) 0015 0016 #include <KActionCollection> 0017 #include <QTest> 0018 #include "kstars.h" 0019 #include "ekos/manager.h" 0020 #include "test_kstars_startup.h" 0021 0022 #define KVERIFY_EKOS_IS_HIDDEN() do { \ 0023 if (Ekos::Manager::Instance() != nullptr) { \ 0024 QVERIFY(!Ekos::Manager::Instance()->isVisible()); \ 0025 QVERIFY(!Ekos::Manager::Instance()->isActiveWindow()); }} while(false) 0026 0027 #define KVERIFY_EKOS_IS_OPENED() do { \ 0028 QVERIFY(Ekos::Manager::Instance() != nullptr); \ 0029 QVERIFY(Ekos::Manager::Instance()->isVisible()); \ 0030 QVERIFY(Ekos::Manager::Instance()->isActiveWindow()); } while(false) 0031 0032 #define KTRY_OPEN_EKOS() do { \ 0033 if (Ekos::Manager::Instance() == nullptr || !Ekos::Manager::Instance()->isVisible()) { \ 0034 KTRY_ACTION("show_ekos"); \ 0035 QTRY_VERIFY_WITH_TIMEOUT(Ekos::Manager::Instance() != nullptr, 200); \ 0036 QTRY_VERIFY_WITH_TIMEOUT(Ekos::Manager::Instance()->isVisible(), 200); \ 0037 QTRY_VERIFY_WITH_TIMEOUT(Ekos::Manager::Instance()->isActiveWindow(), 1000); }} while(false) 0038 0039 #define KTRY_CLOSE_EKOS() do { \ 0040 if (Ekos::Manager::Instance() != nullptr && Ekos::Manager::Instance()->isVisible()) { \ 0041 KTRY_ACTION("show_ekos"); \ 0042 QTRY_VERIFY_WITH_TIMEOUT(!Ekos::Manager::Instance()->isActiveWindow(), 200); \ 0043 QTRY_VERIFY_WITH_TIMEOUT(!Ekos::Manager::Instance()->isVisible(), 200); }} while(false) 0044 0045 #define KHACK_RESET_EKOS_TIME() do { \ 0046 QWARN("HACK HACK HACK: Reset clock to initial conditions when starting Ekos"); \ 0047 if (KStars::Instance() != nullptr) \ 0048 if (KStars::Instance()->data() != nullptr) \ 0049 KStars::Instance()->data()->clock()->setUTC(KStarsDateTime(TestKStarsStartup::m_InitialConditions.dateTime)); } while(false) 0050 0051 #define KTRY_PROFILEEDITOR_GADGET(klass, name) klass * name = nullptr; \ 0052 do { \ 0053 ProfileEditor* profileEditor = Ekos::Manager::Instance()->findChild<ProfileEditor*>("profileEditorDialog"); \ 0054 QVERIFY2(profileEditor != nullptr && profileEditor->isVisible(), "Profile Editor is not visible."); \ 0055 name = Ekos::Manager::Instance()->findChild<klass*>(#name); \ 0056 QVERIFY2(name != nullptr, QString(#klass "'%1' does not exist and cannot be used").arg(#name).toStdString().c_str()); \ 0057 } while(false) 0058 0059 #define KTRY_PROFILEEDITOR_TREE_COMBOBOX(name, strvalue) \ 0060 KTRY_PROFILEEDITOR_GADGET(QComboBox, name); do { \ 0061 QString lookup(strvalue); \ 0062 QModelIndexList const list = name->model()->match(name->model()->index(0, 0), Qt::DisplayRole, QVariant::fromValue(lookup), 1, Qt::MatchRecursive); \ 0063 QVERIFY(0 < list.count()); \ 0064 QModelIndex const &item = list.first(); \ 0065 QCOMPARE(list.value(0).data().toString(), lookup); \ 0066 QVERIFY(!item.parent().parent().isValid()); \ 0067 name->setRootModelIndex(item.parent()); \ 0068 name->setCurrentText(lookup); \ 0069 QCOMPARE(name->currentText(), lookup); } while(false) 0070 0071 class TestEkos: public QObject 0072 { 0073 Q_OBJECT 0074 public: 0075 explicit TestEkos(QObject *parent = nullptr); 0076 0077 private slots: 0078 void initTestCase(); 0079 void cleanupTestCase(); 0080 0081 void init(); 0082 void cleanup(); 0083 0084 void testOpenClose(); 0085 void testSimulatorProfile(); 0086 void testManipulateProfiles(); 0087 }; 0088 0089 #endif // HAVE_INDI 0090 #endif // TEST_EKOS_H