API
 
Loading...
Searching...
No Matches
tcsInterface_test.cpp
Go to the documentation of this file.
1/** \file tcsInterface_test.cpp
2 * \brief Catch2 tests for the tcsInterface app.
3 * \author Jared R. Males (jaredmales@gmail.com)
4 *
5 * \ingroup tcsInterface_files
6 */
7
8#include "../../../tests/testXWC.hpp"
9#include "../../../tests/testMacrosINDI.hpp"
10
11#include "../tcsInterface.hpp"
12
13using namespace MagAOX::app;
14
15namespace libXWCTest
16{
17
18/** \defgroup tcsInterface_unit_test tcsInterface Unit Tests
19 * \brief Unit tests for the tcsInterface application.
20 *
21 * \ingroup application_unit_test
22 */
23
24/// Namespace for `tcsInterface` unit tests.
25/** \ingroup tcsInterface_unit_test
26 */
27namespace tcsInterfaceTest
28{
29
30/// \cond DOXYGEN_SUPPRESS_TEST_HARNESS
31class tcsInterface_test : public tcsInterface
32{
33
34 public:
35 tcsInterface_test( const std::string device )
36 {
37 m_configName = device;
38
40 XWCTEST_SETUP_INDI_NEW_PROP( acqFromGuider );
42 XWCTEST_SETUP_INDI_NEW_PROP( offlTTenable );
43 XWCTEST_SETUP_INDI_NEW_PROP( offlTTdump );
44 XWCTEST_SETUP_INDI_NEW_PROP( offlTTavgInt );
45 XWCTEST_SETUP_INDI_NEW_PROP( offlTTgain );
46 XWCTEST_SETUP_INDI_NEW_PROP( offlTTthresh );
47 XWCTEST_SETUP_INDI_NEW_PROP( offlFenable );
48 XWCTEST_SETUP_INDI_NEW_PROP( offlFdump );
49 XWCTEST_SETUP_INDI_NEW_PROP( offlFavgInt );
50 XWCTEST_SETUP_INDI_NEW_PROP( offlFgain );
51 XWCTEST_SETUP_INDI_NEW_PROP( offlFthresh );
52 // XWCTEST_SETUP_INDI_ARB_PROP(m_indiP_teldata, tcsi, zd);
53 }
54};
55/// \endcond
56
57/// Verify the tcsInterface callback validators accept only the expected properties.
58/**
59 * \ingroup tcsInterface_unit_test
60 */
61SCENARIO( "INDI Callbacks", "[tcsInterface]" )
62{
63 // clang-format off
64 #ifdef TCSINTERFACE_TEST_DOXYGEN_REF
65 tcsInterface::newCallBack_m_indiP_pyrNudge( pcf::IndiProperty() );
66 tcsInterface::newCallBack_m_indiP_acqFromGuider( pcf::IndiProperty() );
67 tcsInterface::newCallBack_m_indiP_labMode( pcf::IndiProperty() );
68 tcsInterface::parse_xms( *(double *)nullptr, *(double *)nullptr, *(double *)nullptr, "" );
69 #endif
70 // clang-format on
71
85
86 // XWCTEST_INDI_SET_CALLBACK( tcsInterface, m_indiP_teldata, tcsi, zd);
87}
88
89/// Verify `tcsInterface::parse_xms()` accepts valid time strings and rejects malformed values.
90/**
91 * \ingroup tcsInterface_unit_test
92 */
93SCENARIO( "Parsing times in x:m:s format", "[tcsInterface]" )
94{
95 GIVEN( "A valid x:m:s string" )
96 {
97 int rv;
98
99 WHEN( "Positive, double digit integers" )
100 {
101 tcsInterface_test tit( "tcsi" );
102
103 std::string tstr = "12:20:50";
104
105 double x;
106 double m;
107 double s;
108
109 rv = tit.parse_xms( x, m, s, tstr );
110
111 REQUIRE( rv == 0 );
112 REQUIRE_THAT( x, Catch::Matchers::WithinAbs( 12, 1e-10 ) );
113 REQUIRE_THAT( m, Catch::Matchers::WithinAbs( 20, 1e-10 ) );
114 REQUIRE_THAT( s, Catch::Matchers::WithinAbs( 50, 1e-10 ) );
115 }
116
117 WHEN( "Negative, double digit integers" )
118 {
119 tcsInterface_test tit( "tcsi" );
120
121 std::string tstr = "-22:30:48";
122
123 double x;
124 double m;
125 double s;
126
127 rv = tit.parse_xms( x, m, s, tstr );
128
129 REQUIRE( rv == 0 );
130 REQUIRE_THAT( x, Catch::Matchers::WithinAbs( -22, 1e-10 ) );
131 REQUIRE_THAT( m, Catch::Matchers::WithinAbs( -30, 1e-10 ) );
132 REQUIRE_THAT( s, Catch::Matchers::WithinAbs( -48, 1e-10 ) );
133 }
134
135 WHEN( "Positive, double digit, decimal seconds" )
136 {
137 tcsInterface_test tit( "tcsi" );
138
139 std::string tstr = "12:20:50.267849";
140
141 double x;
142 double m;
143 double s;
144
145 rv = tit.parse_xms( x, m, s, tstr );
146
147 REQUIRE( rv == 0 );
148 REQUIRE_THAT( x, Catch::Matchers::WithinAbs( 12, 1e-10 ) );
149 REQUIRE_THAT( m, Catch::Matchers::WithinAbs( 20, 1e-10 ) );
150 REQUIRE_THAT( s, Catch::Matchers::WithinAbs( 50.267849, 1e-10 ) );
151 }
152
153 WHEN( "Negative, double digit integers" )
154 {
155 tcsInterface_test tit( "tcsi" );
156
157 std::string tstr = "-22:30:48.8771819";
158
159 double x;
160 double m;
161 double s;
162
163 rv = tit.parse_xms( x, m, s, tstr );
164
165 REQUIRE( rv == 0 );
166 REQUIRE_THAT( x, Catch::Matchers::WithinAbs( -22, 1e-10 ) );
167 REQUIRE_THAT( m, Catch::Matchers::WithinAbs( -30, 1e-10 ) );
168 REQUIRE_THAT( s, Catch::Matchers::WithinAbs( -48.8771819, 1e-10 ) );
169 }
170 }
171
172 GIVEN( "Invalid x:m:s strings" )
173 {
174 int rv;
175
176 WHEN( "empty" )
177 {
178 tcsInterface_test tit( "tcsi" );
179
180 std::string tstr = "";
181
182 double x;
183 double m;
184 double s;
185
186 rv = tit.parse_xms( x, m, s, tstr );
187
188 REQUIRE( rv == -1 );
189 }
190
191 WHEN( "no :" )
192 {
193 tcsInterface_test tit( "tcsi" );
194
195 std::string tstr = "12-20-50";
196
197 double x;
198 double m;
199 double s;
200
201 rv = tit.parse_xms( x, m, s, tstr );
202
203 REQUIRE( rv == -1 );
204 }
205
206 WHEN( "only one :" )
207 {
208 tcsInterface_test tit( "tcsi" );
209
210 std::string tstr = "12:20-50";
211
212 double x;
213 double m;
214 double s;
215
216 rv = tit.parse_xms( x, m, s, tstr );
217
218 REQUIRE( rv == -1 );
219 }
220
221 WHEN( "two :, but one at beginning" )
222 {
223 tcsInterface_test tit( "tcsi" );
224
225 std::string tstr = ":12:20";
226
227 double x;
228 double m;
229 double s;
230
231 rv = tit.parse_xms( x, m, s, tstr );
232
233 REQUIRE( rv == -1 );
234 }
235
236 WHEN( "two :, but no m" )
237 {
238 tcsInterface_test tit( "tcsi" );
239
240 std::string tstr = "12::20";
241
242 double x;
243 double m;
244 double s;
245
246 rv = tit.parse_xms( x, m, s, tstr );
247
248 REQUIRE( rv == -1 );
249 }
250
251 WHEN( "two :, but one at end" )
252 {
253 tcsInterface_test tit( "tcsi" );
254
255 std::string tstr = "12:20:";
256
257 double x;
258 double m;
259 double s;
260
261 rv = tit.parse_xms( x, m, s, tstr );
262
263 REQUIRE( rv == -1 );
264 }
265
266 WHEN( "invalid x" )
267 {
268 tcsInterface_test tit( "tcsi" );
269
270 std::string tstr = "x:20:80";
271
272 double x;
273 double m;
274 double s;
275
276 rv = tit.parse_xms( x, m, s, tstr );
277
278 REQUIRE( rv == -1 );
279 }
280
281 WHEN( "invalid -x" )
282 {
283 tcsInterface_test tit( "tcsi" );
284
285 std::string tstr = "-x:20:80";
286
287 double x;
288 double m;
289 double s;
290
291 rv = tit.parse_xms( x, m, s, tstr );
292
293 REQUIRE( rv == -1 );
294 }
295
296 WHEN( "invalid m" )
297 {
298 tcsInterface_test tit( "tcsi" );
299
300 std::string tstr = "20:m:80";
301
302 double x;
303 double m;
304 double s;
305
306 rv = tit.parse_xms( x, m, s, tstr );
307
308 REQUIRE( rv == -1 );
309 }
310
311 WHEN( "invalid -m" )
312 {
313 tcsInterface_test tit( "tcsi" );
314
315 std::string tstr = "-12:m:80";
316
317 double x;
318 double m;
319 double s;
320
321 rv = tit.parse_xms( x, m, s, tstr );
322
323 REQUIRE( rv == -1 );
324 }
325
326 WHEN( "invalid s" )
327 {
328 tcsInterface_test tit( "tcsi" );
329
330 std::string tstr = "20:23:s.ssy";
331
332 double x;
333 double m;
334 double s;
335
336 rv = tit.parse_xms( x, m, s, tstr );
337
338 REQUIRE( rv == -1 );
339 }
340
341 WHEN( "invalid -s" )
342 {
343 tcsInterface_test tit( "tcsi" );
344
345 std::string tstr = "-12:23:s.sye";
346
347 double x;
348 double m;
349 double s;
350
351 rv = tit.parse_xms( x, m, s, tstr );
352
353 REQUIRE( rv == -1 );
354 }
355 }
356}
357
358} // namespace tcsInterfaceTest
359
360} // namespace libXWCTest
The MagAO-X Clay Telescope TCS Interface.
int parse_xms(double &x, double &m, double &s, const std::string &xmsstr)
SCENARIO("INDI Callbacks", "[tcsInterface]")
Verify the tcsInterface callback validators accept only the expected properties.
#define XWCTEST_INDI_NEW_CALLBACK(testclass, propname)
Catch-2 tests for whether a NEW callback properly validates the input property properly.
Namespace for all libXWC tests.
#define XWCTEST_SETUP_INDI_NEW_PROP(propname)