File indexing completed on 2024-04-14 14:12:03
0001 /* Artificial Horizon UI test 0002 SPDX-FileCopyrightText: 2021 Hy Murveit <hy@murveit.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef TestArtificialHorizon_H 0008 #define TestArtificialHorizon_H 0009 0010 #include "config-kstars.h" 0011 0012 #if defined(HAVE_INDI) 0013 0014 #include <QObject> 0015 #include <QPushButton> 0016 #include <QCheckBox> 0017 #include <QTest> 0018 0019 #include "skypoint.h" 0020 #include "typedef.h" 0021 0022 class QStandardItemModel; 0023 class QStandardItem; 0024 0025 /** @brief Helper to retrieve a gadget in the artificial horizon menu. 0026 * @param klass is the class of the gadget to look for. 0027 * @param name is the gadget name to look for in the UI configuration. 0028 * @warning Fails the test if the gadget "name" of class "klass" does not exist in the artificial horizon module 0029 */ 0030 #define KTRY_AH_GADGET(klass, name) klass * const name = KStars::Instance()->m_HorizonManager->findChild<klass*>(#name); \ 0031 QVERIFY2(name != nullptr, QString(#klass " '%1' does not exist and cannot be used").arg(#name).toStdString().c_str()) 0032 0033 /** @brief Helper to click a button in the artificial horizon menu. 0034 * @param button is the gadget name of the button to look for in the UI configuration. 0035 * @warning Fails the test if the button is not currently enabled. 0036 */ 0037 #define KTRY_AH_CLICK(button) do { \ 0038 bool clicked = false; \ 0039 QTimer::singleShot(100, KStars::Instance(), [&]() { \ 0040 KTRY_AH_GADGET(QPushButton, button); \ 0041 QVERIFY2(button->isEnabled(), QString("QPushButton '%1' is disabled and cannot be clicked").arg(#button).toStdString().c_str()); \ 0042 QTest::mouseClick(button, Qt::LeftButton); \ 0043 clicked = true; }); \ 0044 QTRY_VERIFY_WITH_TIMEOUT(clicked, 150); } while(false) 0045 0046 class TestArtificialHorizon : public QObject 0047 { 0048 Q_OBJECT 0049 0050 public: 0051 explicit TestArtificialHorizon(QObject *parent = nullptr); 0052 0053 private slots: 0054 void initTestCase(); 0055 void cleanupTestCase(); 0056 0057 void init(); 0058 void cleanup(); 0059 0060 void testArtificialHorizon_data(); 0061 void testArtificialHorizon(); 0062 private: 0063 QStandardItem *getRegion(int region); 0064 QList<SkyPoint> getRegionPoints(int region); 0065 bool compareLivePreview(int region, SkyList *previewPoints); 0066 bool checkForRepeatedAzAlt(int region); 0067 0068 QStandardItemModel *m_Model {nullptr}; 0069 }; 0070 0071 #endif // HAVE_INDI 0072 #endif // TestArtificialHorizon_H