Changeset View
Changeset View
Standalone View
Standalone View
Tests/kstars_ui/test_ekos_focus.cpp
- 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 | #include "kstars_ui_tests.h" | ||||
12 | #include "test_ekos.h" | ||||
13 | #include "test_ekos_simulator.h" | ||||
14 | #include "test_ekos_focus.h" | ||||
15 | #include "ekos/manager.h" | ||||
16 | #include "kstars.h" | ||||
17 | | ||||
18 | #if defined(HAVE_INDI) | ||||
19 | | ||||
20 | TestEkosFocus::TestEkosFocus(QObject *parent) : QObject(parent) | ||||
21 | { | ||||
22 | | ||||
23 | } | ||||
24 | | ||||
25 | void TestEkosFocus::initTestCase() | ||||
26 | { | ||||
27 | KVERIFY_EKOS_IS_HIDDEN(); | ||||
28 | KTRY_OPEN_EKOS(); | ||||
29 | KVERIFY_EKOS_IS_OPENED(); | ||||
30 | KTRY_EKOS_START_SIMULATORS(); | ||||
31 | | ||||
32 | // HACK: Reset clock to initial conditions | ||||
33 | KStars::Instance()->data()->clock()->setUTC(KStarsDateTime(KStarsUiTests::m_InitialConditions.dateTime)); | ||||
34 | } | ||||
35 | | ||||
36 | void TestEkosFocus::cleanupTestCase() | ||||
37 | { | ||||
38 | KTRY_EKOS_STOP_SIMULATORS(); | ||||
39 | KTRY_CLOSE_EKOS(); | ||||
40 | KVERIFY_EKOS_IS_HIDDEN(); | ||||
41 | } | ||||
42 | | ||||
43 | void TestEkosFocus::init() | ||||
44 | { | ||||
45 | | ||||
46 | } | ||||
47 | | ||||
48 | void TestEkosFocus::cleanup() | ||||
49 | { | ||||
50 | | ||||
51 | } | ||||
52 | | ||||
53 | void TestEkosFocus::testStarDetection_data() | ||||
54 | { | ||||
55 | #if QT_VERSION < 0x050900 | ||||
56 | QSKIP("Skipping fixture-based test on old QT version."); | ||||
57 | #else | ||||
58 | QTest::addColumn<QString>("NAME"); | ||||
59 | QTest::addColumn<QString>("RA"); | ||||
60 | QTest::addColumn<QString>("DEC"); | ||||
61 | | ||||
62 | // Altitude computation taken from SchedulerJob::findAltitude | ||||
63 | GeoLocation * const geo = KStarsData::Instance()->geo(); | ||||
64 | KStarsDateTime const now(KStarsData::Instance()->lt()); | ||||
65 | KSNumbers const numbers(now.djd()); | ||||
66 | CachingDms const LST = geo->GSTtoLST(geo->LTtoUT(now).gst()); | ||||
67 | | ||||
68 | std::list<char const *> Objects = { "Polaris", "Mizar", "M 51", "M 13", "M 47", "Pherkab", "Dubhe", "Vega", "NGC 2238", "M 81" }; | ||||
69 | size_t count = 0; | ||||
70 | | ||||
71 | foreach (char const *name, Objects) | ||||
72 | { | ||||
73 | SkyObject const * const so = KStars::Instance()->data()->objectNamed(name); | ||||
74 | if (so != nullptr) | ||||
75 | { | ||||
76 | SkyObject o(*so); | ||||
77 | o.updateCoordsNow(&numbers); | ||||
78 | o.EquatorialToHorizontal(&LST, geo->lat()); | ||||
79 | if (10.0 < o.alt().Degrees()) | ||||
80 | { | ||||
81 | QTest::addRow("%s", name) | ||||
82 | << name | ||||
83 | << o.ra().toHMSString() | ||||
84 | << o.dec().toDMSString(); | ||||
85 | count++; | ||||
86 | } | ||||
87 | else QWARN(QString("Fixture '%1' altitude is '%2' degrees, discarding.").arg(name).arg(so->alt().Degrees()).toStdString().c_str()); | ||||
88 | } | ||||
89 | } | ||||
90 | | ||||
91 | if (!count) | ||||
92 | QSKIP("No usable fixture objects, bypassing test."); | ||||
93 | #endif | ||||
94 | } | ||||
95 | | ||||
96 | void TestEkosFocus::testStarDetection() | ||||
97 | { | ||||
98 | #if QT_VERSION < 0x050900 | ||||
99 | QSKIP("Skipping fixture-based test on old QT version."); | ||||
100 | #else | ||||
101 | Ekos::Manager * const ekos = Ekos::Manager::Instance(); | ||||
102 | | ||||
103 | QFETCH(QString, NAME); | ||||
104 | QFETCH(QString, RA); | ||||
105 | QFETCH(QString, DEC); | ||||
106 | qDebug("Test focusing on '%s' RA '%s' DEC '%s'", | ||||
107 | NAME.toStdString().c_str(), | ||||
108 | RA.toStdString().c_str(), | ||||
109 | DEC.toStdString().c_str()); | ||||
110 | | ||||
111 | // Just sync to RA/DEC to make the mount teleport to the object | ||||
112 | QWARN("During this test, the mount is not tracking - we leave it as is for the feature in the CCD simulator to trigger a failure."); | ||||
113 | QTRY_VERIFY_WITH_TIMEOUT(ekos->mountModule() != nullptr, 5000); | ||||
114 | QVERIFY(ekos->mountModule()->sync(RA, DEC)); | ||||
115 | | ||||
116 | // Wait for Focus to come up, switch to Focus tab | ||||
117 | QTRY_VERIFY_WITH_TIMEOUT(ekos->focusModule() != nullptr, 5000); | ||||
118 | KTRY_EKOS_GADGET(QTabWidget, toolsWidget); | ||||
119 | toolsWidget->setCurrentWidget(ekos->focusModule()); | ||||
120 | QTRY_COMPARE_WITH_TIMEOUT(toolsWidget->currentWidget(), ekos->focusModule(), 1000); | ||||
121 | | ||||
122 | QWARN("The Focus capture button toggles after Ekos is started, leave a bit of time for it to settle."); | ||||
123 | QTest::qWait(500); | ||||
124 | | ||||
125 | KTRY_FOCUS_GADGET(QLineEdit, starsOut); | ||||
126 | | ||||
127 | // Run the focus procedure for SEP | ||||
128 | KTRY_FOCUS_CONFIGURE("SEP", "Iterative", 0.0, 100.0); | ||||
129 | KTRY_FOCUS_CAPTURE(1, 1); | ||||
130 | QWARN("No way to know when star detection procedure is fininshed."); | ||||
131 | QTest::qWait(1000); | ||||
132 | QTRY_VERIFY_WITH_TIMEOUT(starsOut->text().toInt() >= 1, 5000); | ||||
133 | | ||||
134 | // Run the focus procedure for Centroid | ||||
135 | KTRY_FOCUS_CONFIGURE("Centroid", "Iterative", 0.0, 100.0); | ||||
136 | KTRY_FOCUS_CAPTURE(1, 1); | ||||
137 | QWARN("No way to know when star detection procedure is fininshed."); | ||||
138 | QTest::qWait(1000); | ||||
139 | QTRY_VERIFY_WITH_TIMEOUT(starsOut->text().toInt() >= 1, 5000); | ||||
140 | | ||||
141 | // Run the focus procedure for Threshold | ||||
142 | KTRY_FOCUS_CONFIGURE("Threshold", "Iterative", 0.0, 100.0); | ||||
143 | KTRY_FOCUS_CAPTURE(1, 1); | ||||
144 | QWARN("No way to know when procedure is fininshed."); | ||||
145 | QTest::qWait(1000); | ||||
146 | QTRY_VERIFY_WITH_TIMEOUT(starsOut->text().toInt() >= 1, 5000); | ||||
147 | | ||||
148 | // Run the focus procedure for Gradient | ||||
149 | KTRY_FOCUS_CONFIGURE("Gradient", "Iterative", 0.0, 100.0); | ||||
150 | KTRY_FOCUS_CAPTURE(1, 1); | ||||
151 | QWARN("No way to know when procedure is fininshed."); | ||||
152 | QTest::qWait(1000); | ||||
153 | QTRY_VERIFY_WITH_TIMEOUT(starsOut->text().toInt() >= 1, 5000); | ||||
154 | | ||||
155 | // Run the focus procedure again to cover more code | ||||
156 | // Filtering annulus is independent of the detection method | ||||
157 | // Run the HFR average over three frames with SEP to avoid | ||||
158 | for (double inner = 0.0; inner < 100.0; inner += 23.0) | ||||
159 | { | ||||
160 | for (double outer = 100.0; inner < outer; outer -= 22.0) | ||||
161 | { | ||||
162 | KTRY_FOCUS_CONFIGURE("SEP", "Iterative", inner, outer); | ||||
163 | KTRY_FOCUS_CAPTURE(0.5, 5); | ||||
164 | QTest::qWait(1000); | ||||
165 | } | ||||
166 | } | ||||
167 | | ||||
168 | // Test threshold | ||||
169 | for (double threshold = 80.0; threshold < 200.0; threshold += 13.3) | ||||
170 | { | ||||
171 | KTRY_FOCUS_GADGET(QDoubleSpinBox, thresholdSpin); | ||||
172 | thresholdSpin->setValue(threshold); | ||||
173 | KTRY_FOCUS_CONFIGURE("Threshold", "Iterative", 0, 100.0); | ||||
174 | KTRY_FOCUS_CAPTURE(0.5, 1); | ||||
175 | QTest::qWait(1000); | ||||
176 | } | ||||
177 | #endif | ||||
178 | } | ||||
179 | | ||||
180 | #endif |