Changeset View
Changeset View
Standalone View
Standalone View
Tests/kstars_ui/test_ekos_focus.h
- This file was added.
1 | /* KStars UI tests | ||||
---|---|---|---|---|---|
2 | Copyright (C) 2020 | ||||
3 | Eric Dejouhanet <eric.dejouhanet@gmail.com> | ||||
4 | | ||||
5 | This application is free software; you can redistribute it and/or | ||||
6 | modify it under the terms of the GNU General Public | ||||
7 | License as published by the Free Software Foundation; either | ||||
8 | version 2 of the License, or (at your option) any later version. | ||||
9 | */ | ||||
10 | | ||||
11 | #ifndef TESTEKOSFOCUS_H | ||||
12 | #define TESTEKOSFOCUS_H | ||||
13 | | ||||
14 | #include "config-kstars.h" | ||||
15 | | ||||
16 | #if defined(HAVE_INDI) | ||||
17 | | ||||
18 | #include <QObject> | ||||
19 | | ||||
20 | /** @brief Helper to retrieve a gadget in the Focus tab specifically. | ||||
21 | * @param klass is the class of the gadget to look for. | ||||
22 | * @param name is the gadget name to look for in the UI configuration. | ||||
23 | * @warning Fails the test if the gadget "name" of class "klass" does not exist in the Focus module | ||||
24 | */ | ||||
25 | #define KTRY_FOCUS_GADGET(klass, name) klass * const name = Ekos::Manager::Instance()->focusModule()->findChild<klass*>(#name); \ | ||||
26 | QVERIFY2(name != nullptr, QString(#klass " '%1' does not exist and cannot be used").arg(#name).toStdString().c_str()) | ||||
27 | | ||||
28 | /** @brief Helper to click a button in the Focus tab specifically. | ||||
29 | * @param button is the gadget name of the button to look for in the UI configuration. | ||||
30 | * @warning Fails the test if the button is not currently enabled. | ||||
31 | */ | ||||
32 | #define KTRY_FOCUS_CLICK(button) do { \ | ||||
33 | QTimer::singleShot(200, Ekos::Manager::Instance(), []() { \ | ||||
34 | KTRY_FOCUS_GADGET(QPushButton, button); \ | ||||
35 | QVERIFY2(button->isEnabled(), QString("QPushButton '%1' is disabled and cannot be clicked").arg(#button).toStdString().c_str()); \ | ||||
36 | QTest::mouseClick(button, Qt::LeftButton); }); } while(false) | ||||
37 | | ||||
38 | /** @brief Helper to set a string text into a QComboBox in the Focus module. | ||||
39 | * @param combobox is the gadget name of the QComboBox to look for in the UI configuration. | ||||
40 | * @param text is the string text to set in the gadget. | ||||
41 | * @note This is a contrived method to set a text into a QComboBox programmatically *and* emit the "activated" message. | ||||
42 | * @warning Fails the test if the name does not exist in the Focus UI or if the text cannot be set in the gadget. | ||||
43 | */ | ||||
44 | #define KTRY_FOCUS_COMBO_SET(combobox, text) do { \ | ||||
45 | KTRY_FOCUS_GADGET(QComboBox, combobox); \ | ||||
46 | int const cbIndex = combobox->findText(text); \ | ||||
47 | QVERIFY(0 <= cbIndex); \ | ||||
48 | combobox->setCurrentIndex(cbIndex); \ | ||||
49 | combobox->activated(cbIndex); \ | ||||
50 | QCOMPARE(combobox->currentText(), QString(text)); } while(false); | ||||
51 | | ||||
52 | /** @brief Helper for exposure. | ||||
53 | * @param exposure is the amount of seconds to expose for. | ||||
54 | * @param averaged is the number of frames the procedure should average before computation. | ||||
55 | * @note The Focus capture button is disabled during exposure. | ||||
56 | * @warning Fails the test if the exposure cannot be entered or if the capture button is | ||||
57 | * disabled or does not toggle during exposure or if the stop button is not the opposite of the capture button. | ||||
58 | */ | ||||
59 | #define KTRY_FOCUS_CAPTURE(exposure, averaged) do { \ | ||||
60 | KTRY_FOCUS_GADGET(QDoubleSpinBox, exposureIN); \ | ||||
61 | exposureIN->setValue(exposure); \ | ||||
62 | KTRY_FOCUS_GADGET(QSpinBox, focusFramesSpin); \ | ||||
63 | focusFramesSpin->setValue(averaged); \ | ||||
64 | KTRY_FOCUS_GADGET(QPushButton, captureB); \ | ||||
65 | KTRY_FOCUS_GADGET(QPushButton, stopFocusB); \ | ||||
66 | QTRY_VERIFY_WITH_TIMEOUT(captureB->isEnabled(), 1000); \ | ||||
67 | QTRY_VERIFY_WITH_TIMEOUT(!stopFocusB->isEnabled(), 1000); \ | ||||
68 | KTRY_FOCUS_CLICK(captureB); \ | ||||
69 | QTRY_VERIFY_WITH_TIMEOUT(!captureB->isEnabled(), 1000); \ | ||||
70 | QTRY_VERIFY_WITH_TIMEOUT(stopFocusB->isEnabled(), 1000); \ | ||||
71 | QTest::qWait(1.2*exposure*averaged); \ | ||||
72 | QTRY_VERIFY_WITH_TIMEOUT(captureB->isEnabled(), 5000); \ | ||||
73 | QTRY_VERIFY_WITH_TIMEOUT(!stopFocusB->isEnabled(), 5000); } while (false) | ||||
74 | | ||||
75 | /** brief Helper to configure main star detection parameters. | ||||
76 | * @param detection is the name of the star detection method to use. | ||||
77 | * @param algorithm is the name of the autofocus algorithm to use. | ||||
78 | * @param fieldin is the lower radius of the annulus filtering stars. | ||||
79 | * @param fieldout is the upper radius of the annulus filtering stars. | ||||
80 | * @warning Fails the test if detection, algorithm, full-field checkbox or annulus fields cannot be used. | ||||
81 | */ | ||||
82 | #define KTRY_FOCUS_CONFIGURE(detection, algorithm, fieldin, fieldout) do { \ | ||||
83 | KTRY_FOCUS_GADGET(QCheckBox, useFullField); \ | ||||
84 | useFullField->setCheckState(Qt::CheckState::Checked); \ | ||||
85 | KTRY_FOCUS_GADGET(QDoubleSpinBox, fullFieldInnerRing); \ | ||||
86 | fullFieldInnerRing->setValue(fieldin); \ | ||||
87 | KTRY_FOCUS_GADGET(QDoubleSpinBox, fullFieldOuterRing); \ | ||||
88 | fullFieldOuterRing->setValue(fieldout); \ | ||||
89 | KTRY_FOCUS_COMBO_SET(focusDetectionCombo, detection); \ | ||||
90 | KTRY_FOCUS_COMBO_SET(focusAlgorithmCombo, algorithm); } while (false) | ||||
91 | | ||||
92 | class TestEkosFocus : public QObject | ||||
93 | { | ||||
94 | Q_OBJECT | ||||
95 | public: | ||||
96 | explicit TestEkosFocus(QObject *parent = nullptr); | ||||
97 | | ||||
98 | private slots: | ||||
99 | void initTestCase(); | ||||
100 | void cleanupTestCase(); | ||||
101 | | ||||
102 | void init(); | ||||
103 | void cleanup(); | ||||
104 | | ||||
105 | void testStarDetection_data(); | ||||
106 | void testStarDetection(); | ||||
107 | }; | ||||
108 | | ||||
109 | #endif | ||||
110 | #endif // TESTEKOSFOCUS_H |