1 /* Artificial Horizon UI test 2 SPDX-FileCopyrightText: 2021 Hy Murveit <hy@murveit.com> 3 4 SPDX-License-Identifier: GPL-2.0-or-later 5 */ 6 7 #ifndef TestArtificialHorizon_H 8 #define TestArtificialHorizon_H 9 10 #include "config-kstars.h" 11 12 #if defined(HAVE_INDI) 13 14 #include <QObject> 15 #include <QPushButton> 16 #include <QCheckBox> 17 #include <QtTest> 18 19 #include "skypoint.h" 20 #include "typedef.h" 21 22 class QStandardItemModel; 23 class QStandardItem; 24 25 /** @brief Helper to retrieve a gadget in the artificial horizon menu. 26 * @param klass is the class of the gadget to look for. 27 * @param name is the gadget name to look for in the UI configuration. 28 * @warning Fails the test if the gadget "name" of class "klass" does not exist in the artificial horizon module 29 */ 30 #define KTRY_AH_GADGET(klass, name) klass * const name = KStars::Instance()->m_HorizonManager->findChild<klass*>(#name); \ 31 QVERIFY2(name != nullptr, QString(#klass " '%1' does not exist and cannot be used").arg(#name).toStdString().c_str()) 32 33 /** @brief Helper to click a button in the artificial horizon menu. 34 * @param button is the gadget name of the button to look for in the UI configuration. 35 * @warning Fails the test if the button is not currently enabled. 36 */ 37 #define KTRY_AH_CLICK(button) do { \ 38 bool clicked = false; \ 39 QTimer::singleShot(100, KStars::Instance(), [&]() { \ 40 KTRY_AH_GADGET(QPushButton, button); \ 41 QVERIFY2(button->isEnabled(), QString("QPushButton '%1' is disabled and cannot be clicked").arg(#button).toStdString().c_str()); \ 42 QTest::mouseClick(button, Qt::LeftButton); \ 43 clicked = true; }); \ 44 QTRY_VERIFY_WITH_TIMEOUT(clicked, 150); } while(false) 45 46 class TestArtificialHorizon : public QObject 47 { 48 Q_OBJECT 49 50 public: 51 explicit TestArtificialHorizon(QObject *parent = nullptr); 52 53 private slots: 54 void initTestCase(); 55 void cleanupTestCase(); 56 57 void init(); 58 void cleanup(); 59 60 void testArtificialHorizon_data(); 61 void testArtificialHorizon(); 62 private: 63 QStandardItem *getRegion(int region); 64 QList<SkyPoint> getRegionPoints(int region); 65 bool compareLivePreview(int region, SkyList *previewPoints); 66 bool checkForRepeatedAzAlt(int region); 67 68 QStandardItemModel *m_Model {nullptr}; 69 }; 70 71 #endif // HAVE_INDI 72 #endif // TestArtificialHorizon_H 73